Skip to content
Advertisement

Unable to change camera / stream for WebRTC call

Source: https://github.com/anoek/webrtc-group-chat-example/blob/master/client.html

I’m trying to modify this Webrtc example to add the ability of changing camera (Cross-browser support).

Normal usage works perfectly, after changing camera, failed in renegotiation.

1) Get a list of devices via navigator.mediaDevices.enumerateDevices()

2) Change local_media_stream after getting new stream

JavaScript

3) Trigger renegotiation function (Copied from line 132 of Source code)

JavaScript

I believe that my approaches are wrong, but I’ve tried many different ways found on google to edit the codes for renegotiation, however I’m not familiar to WebRTC and Socket.io, still can’t make the thing works.

After changing the camera, the video shown on other participant just became a static image from video last frame.

Can anybody please help to point my mistake? Thanks in advance.

Advertisement

Answer

Previously I done it in the following way (an order is important).

Let’s say you list all our available devices:

JavaScript

And now you want to switch:

1) Stop current tracks

JavaScript

2) Obtain new stream

JavaScript

3) Replace tracks:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement