Correct way of implementing video mute/unmute in videoroom

1,236 views
Skip to first unread message

Maximilian Stock

unread,
Mar 10, 2021, 12:47:34 PM3/10/21
to meetecho-janus
Hello,

For our video platform, we are using Janus 0.10.9 as SFU with the videoroom plugin and the official Janus.js package. In a videoroom, a user wants to mute and unmute its own video stream, falling back to a placeholder in case of being muted. We are using data channels as a way of signaling these events to all participants.

Question 1
Muting/unmuting video is currently implemented via "createOffer", as seen in this example gist. Is this the intended way of handling video mute/unmute, so that a potential webcam indicator turns off/on correctly?

Question 2
In our current videochat application, the "onremotestream" callback is called multiple times when someone joins an existing videoroom session. In fact, the number of times the callback is called depends on whether:
  • I am a publisher and another user comes in and subscribes to my feed
  • I join an existing videoroom with one publisher and subscribe to his feed
In the first case, "onremotestream" is called four times. In the latter case, its called five times.

Can you give me any pointers as to why "onremotestream" is called several times (I read about once per audio/video track, but that should be two times)?
Also, are there any obvious explanations for different numbers of callback invocations?


Thank you very much for your help

Kind regards,
Maximilian


Alessandro Toppi

unread,
Mar 12, 2021, 10:38:33 AM3/12/21
to meetecho-janus
#1 you are muting/unmuting through renegotiation. That is a valid approach, maybe the only one if you want to turn off the camera usage indicator.
#2 onremotestream might be called multiple times for different reasons. It is expected that it is called for every "ontrack" event (that is any m-line of the remote peer), but there could be other scenarios. I encourage you to set a breakpoint in the code and inspect the stacks to understand the reason the callback has been invoked by janus.js

Maximilian Stock

unread,
Mar 12, 2021, 2:22:20 PM3/12/21
to meetecho-janus
Thank you very much for your response, Alessandro.

Regarding #2: I'm seeing two calls to "pc.ontrack" (for video and audio) and then a call to "track.onunmute" (again for video and audio, although we always join with audio muted). Just wondering, does this seem correct to you or is our application code responsible for the onunmute-calls?

Alessandro Toppi

unread,
Mar 12, 2021, 4:19:56 PM3/12/21
to meetecho-janus
The unmute event is about the incoming audio/video.

Maximilian Stock

unread,
Mar 12, 2021, 5:17:06 PM3/12/21
to meetecho-janus
Superb, thank you very much for clarifying!

Ramon Blanquer

unread,
Apr 6, 2021, 11:01:39 AM4/6/21
to meetecho-janus
Hey Maximilian! I hit the same design problem you mentioned.

I was wondering how do you the intercept when a person goes video-muted? Maybe by manually querying the video tracks of the received stream?

onremotestream: (stream: MediaStream) => {
    console.log(stream.getVideoTracks().length === 0);
}

I'm curious about how did you solve it :)

Thank you.
Ramon.

Maximilian Stock

unread,
Apr 6, 2021, 1:56:07 PM4/6/21
to meetecho-janus
Hey Ramon,

do you mean how we notice that a videotrack is being muted/unmuted? 
You can use the data channel of the videoroom plugin to send commands (eg. structured JSON payloads) to all subscribers, to notify them of the respective change.

Additionally, a publisher triggers a renegotiation to remove its video track (as discussed above). Each subscriber then received a onRemoteStream
call, which just updates their local media stream, which is ignored, as the subscriber's state says that particular publisher is muted.

Kind regards
Maximilian

Ramon Blanquer

unread,
Apr 13, 2021, 3:58:59 PM4/13/21
to meetecho-janus
Thanks for sharing Maximilian! That makes sense. Good leverage of the tool.
Reply all
Reply to author
Forward
0 new messages