VideoRoom switch video sources

2,036 views
Skip to first unread message

Gabriel Munteanu

unread,
Jan 11, 2017, 7:05:23 AM1/11/17
to meetecho-janus
Hi,

I'm interested in using Janus in one of my projects and right now I'm stuck at switching video sources.
Let me explain: I'm using videoroom plugin where I have one publisher and multiple watchers. During a video session I want a publisher to be able to switch from camera to screen sharing.
While testing I saw that if I change the video source(another camera) all watchers have to refresh the page and it works. If I change to screen sharing (hangup and create new offer) the watcher will see nothing after page refresh.
If I start with screen sharing and after that I switch to camera it is OK.
How can I make this transitions work all the time?

As far as I know, screen sharing doesn't work with audio. It is true?

Lorenzo Miniero

unread,
Jan 11, 2017, 9:15:52 AM1/11/17
to meetecho-janus
There's no need to refresh the page for that to work. You do need separate publishers for regular video and screen sharing, but on the viewer side, you either just close the previous video and subscribe to the new feed when the change happens, or you use the "switch" command to change the publisher you're subscribed to.

L.

Igor Khomenko

unread,
Jan 11, 2017, 10:10:12 AM1/11/17
to meetecho-janus
Hi there, 

I have the same task - to switch video source in real time

I found this WebRTC code sample
https://webrtc.github.io/samples/src/content/devices/input-output/

what they do is call 'getUserMedia' again with new video source when need to change camera:
https://github.com/webrtc/samples/blob/gh-pages/src/content/devices/input-output/js/main.js#L91

With Janus Javascript SDK we do not have a direct access to 'getUserMedia', so what we should do here? detach and attach again video room plugin? 

Lorenzo Miniero

unread,
Jan 11, 2017, 10:13:18 AM1/11/17
to meetecho-janus
janus.js is just an example, if you need more try modifying it to suit your needs. It already allows you to pass an externally captured MediaStream to a createOffer/createAnswer for instance: in that case, you created the MediaStream, so you can do with it whatever you want. Notice that if it requires a renegotiation, it will not work right now.

L.

Igor Khomenko

unread,
Jan 11, 2017, 11:38:18 AM1/11/17
to meetecho-janus
Thanks Lorenzo, 
in my case, I need to change the video input later, when a user is already on a video call, 
so a renegotiation is needed as I understand 

Igor Khomenko

unread,
Jan 11, 2017, 11:39:12 AM1/11/17
to meetecho-janus
because I need to replace a stream

https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream

The RTCPeerConnection.addStream() method adds a MediaStream as a local source of audio or video. If the negotiation already happened, a new one will be needed for the remote peer to be able to use it.

Igor Khomenko

unread,
Jan 16, 2017, 8:54:38 AM1/16/17
to meetecho-janus
Just played a bit more with Janus documentation and found the following steps to switch camera:

1) call handle.hangup() JS method which closes the PeerConnection
2) then request new stream with getUserMedia
3) pass this new stream to handle.createOffer()

Lorenzo - does it sound right?

I'm going to try it 

Lorenzo Miniero

unread,
Jan 16, 2017, 11:38:39 AM1/16/17
to meetecho-janus
Yep, that's basically an unpublish/publish in the VideoRoom.

L.
Reply all
Reply to author
Forward
0 new messages