Hi Everyone,
I’m able to publish successfully but battling with this error when i join a live video stream. I saw this question was asked before but didn’t see what the solution is.
“Missing mandatory element (feed)”
Running this version:
Janus version: 1202 (1.2.2)
//Join session
var janusViewer = null;
var videoRoomViewer = null;
var localStream = null; // Global variable for th
var roomId = {{ room_id }};
function subscribeToFeed(feedId) {
console.log("Subscribing to feed:", feedId);
var subscribe = {
"request": "join",
"room": roomId, // The ID of the video room you're joining
"ptype": "subscriber", // Indicating this handle is for subscribing
"feed": feedId // The publisher's feed ID you want to subscribe to
};
videoRoomViewer.send({"message": subscribe, success: function(result) {
console.log("Subscription request was successful", result);
}, error: function(error) {
console.log("Subscription request failed", error);
}});
}
function startViewer() {
Janus.init({
debug: "all",
callback: function() {
janusViewer = new Janus({
server: "ws://localhost:8188/",
success: function() {
janusViewer.attach({
plugin: "janus.plugin.videoroom",
success: function(pluginHandle) {
videoRoomViewer = pluginHandle;
console.log("Attached to Video Room as a subscriber", videoRoomViewer);
var joinRequest = {
"request": "join",
"room": roomId
"ptype": "subscriber"
};
videoRoomViewer.send({"message": joinRequest});
},
onremotestream: function(stream) {
console.log("Received a remote stream", stream);
Janus.attachMediaStream(document.getElementById('viewerVideo'), stream);
},
onmessage: function(msg, jsep) {
console.log("Received a message from Janus:", jsep);
if (jsep) {
videoRoomViewer.createAnswer({
jsep: jsep,
media: { audioSend: false, videoSend: false },
success: function(jsep) {
var joinRequest = {
"request": "join",
"room": roomId,
"ptype": "subscriber",
};
videoRoomViewer.send({ "message": joinRequest})
},
error: function(error) {
console.error("WebRTC error:", error);
}
});
}
if (msg.videoroom === "event" && msg.publishers) {
console.log("Got a list of available publishers/feeds:", msg.publishers);
msg.publishers.forEach(function(publisher) {
console.log("Publisher:", publisher);
// Ensure publisher.id is valid and not undefined before attempting to subscribe
if (publisher.id) {
subscribeToFeed(publisher.id); // Subscribe when publishers are received
}
});
} else {
console.log("Non-publisher event received", msg);
}
},
});
},
error: function(error) {
console.error("Error initializing viewer Janus session", error);
},
destroyed: function() {
console.log("Viewer Janus session destroyed");
}
});
}
});
}
// Call startViewer
startViewer();
Are there adjustments i need to make? Thank you all.
A huge thank you to Lorenzo and team for building this great server.