3

I've been using SimpleWebRTC in my app for a while. It's very easy to setup and works well for simple apps. However, I need to be able to disable/enable video without affecting audio in my app, and this is where SimpleWebRTC falls short. Searching a few other StackOverflow questions revealed that this seems to be called 'renegotiation'.

Apparently up until relatively recently (last year or two?) browsers did not expose MediaStreamTracks (https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack), which made renegotiation impossible. Now this is apparently possible, but I don't see any wrapper library doing this. Actually, most of the popular WebRTC libraries don't seem to be maintained at all anymore.

Has anyone worked with stream renegotiation and can point me in the right direction, either to a library that implements it, a polyfill, or some guidance on how I can implement this via current WebRTC standards? I don't mind getting rid of a library in favor of barebones WebRTC, I'm just not sure what's the proper way of ending/starting connection consistently is, since implementations still seem finicky between browsers.

Alexander Tsepkov
  • 3,946
  • 3
  • 35
  • 59
  • Possible duplicate of [How to addTrack in MediaStream in WebRTC](http://stackoverflow.com/questions/35504214/how-to-addtrack-in-mediastream-in-webrtc) – jib Dec 28 '16 at 14:53
  • Also, have you tried just disabling the video? This causes video packets to stop being sent, at least in Firefox: https://jsfiddle.net/ec9ossmu/ (fiddle requires Firefox, because Chrome doesn't support stats to the spec quite yet). – jib Dec 28 '16 at 15:03
  • @jib thanks, as far as the fiddle, it has the same effect to Philipp's solution in Chrome, video is effectively paused but camera stays on, making the user suspicious. As for your first link, you're right, that is technically a duplicate, sorry I missed that. The state of Chrome has changed since the answer, it now partially supports tracks, in particular `addTrack` and `removeTrack` but not `replaceTrack`, which as Phillip pointed out is what I need. I can mark it as duplicate, but due to evolving support for WebRTC, I'd need to see if the answer still works and if there is now a cleaner way. – Alexander Tsepkov Dec 29 '16 at 01:18

1 Answers1

2

In particular for simplewebrtc there is https://simplewebrtc.com/notsosimple.html#mute It doesn't renegotiate but sets the MediaStreamTrack enabled attribute to false which sends black frames (low bandwidth). The downside is that if you mute the camera this way, the camera light will stay on.

Philipp Hancke
  • 15,855
  • 2
  • 23
  • 31
  • Yes, I'm already aware of this solution, I apologize I forgot to mention it. The problem with it is exactly as you describe, a user who sees the camera light when they intend to only transmit audio is likely to think my app is doing something sketchy. – Alexander Tsepkov Dec 28 '16 at 16:54
  • 1
    then the problem is that some browsers (Chrome) still don't implement RTPSender.replaceTrack which would allow this without renegotiation. If you want to implement renegotiation: good luck. – Philipp Hancke Dec 28 '16 at 20:51
  • I see, it definitely seems like Firefox is doing much better job than Chrome when it comes to WebRTC standards. Unfortunately, majority of our users would probably use Chrome. – Alexander Tsepkov Dec 29 '16 at 01:06