Unable to join stream-Missing mandatory element (feed)

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.

Make sure feedId is valid and not something like null or undefined. Sounds more like a client side issue to me.

Thanks for the fast response Lorenzo. You are right, it seems the issue is on the client side.

My understanding of the subscriber’s process flow is this:
Join a room(RoomId) > subscribe to a feed(FeedId) > consume the streamed content

If there’s a specific section on the documentation that addresses this? Please point me to that. i don’t mind reading it to understand this.

Thanks for the impactful talks you give. Awesome work.

That’s the flow, but as I mentioned, you should check what value you’re putting in the request by the time you send it. The error you’re getting means Janus didn’t find anything when looking for the feed property, which means your code is not setting it (possibly because you do set it, but the variable is empty).

Thanks Lorenzo, i managed to get the feedID issue sorted by making some changes on the client side.

1 Like

Hi @lorenzo @jasonm

I am also getting the same issue, Could you assist how you resolve this issue. The use case is an invisible user would be monitor the room without any further actions.

Janus server: wss://janus.conf.meetecho.com/ws

function joinRoom() {
            var register = {
                request: "join",
                room: 1234,  // The room ID you want to join
                ptype: "subscriber"
            };
            console.log("Sending join request:", register);

            videoRoomPlugin.send({
                message: register,
                success: (data) => {
                console.log("Joined room as subscriber:", data);
                // Handle successful subscription (e.g., listen to media stream)
                },
                error: (error) => {
                console.error("Subscription failed:", error);
                },
            });

        }```

It will help me to proceed further. Thanks in Advance.

![Screenshot from 2024-06-17 19-52-09|690x453](upload://koydmzzyzNjjkKmmJtVUy6b2zNV.png)