After upgrading from release 8.5.0 to 9.x I don't seem to be able to receive video in an Electron app.
The peer.on('stream') handler is not invoked. Without diving further into it, I suspect it might be related to an on-addStream event not being fired.
Everything works before this commit: https://github.com/feross/simple-peer/commit/747ed8f111344c28a51a0e7f653d3ed024b999fe
Steps to reproduce:
Use the code in the readme (https://github.com/feross/simple-peer#videovoice) but pass in a stream from electron by using navigator.mediaDevices.getUserMedia.
Happens with both Electron v. 1.7.12 and v. 1.8.6.
In the past simple-peer supported RTCPeerConnection.addStream() method, which is an old API that is not in specification.
Starting with 9.1 only spec-compliant method is used, namely RTCPeerConnection.addTrack(), that works in any modern browser.
Apparently Electron uses Chromium version that is too old and doesn't support this API.
There are couple of options here:
I see, thanks for the detailed explanation.
I can confirm that the first option of using Electron 2 works (tested with 2.0.0-beta.8).
And thanks for a great library. It's truly a pleasure to be using a project that is so actively maintained.
Good, I'm closing this now, since it is unlikely that simple-peer will start supporting old APIs again.
Feel free to post other issues or questions if you find any.
Sorry, I was a bit quick before. Turns out NPM hadn't updated the package as expected since I previously pointed at a specific github commit.
So, apparently it does not work in Electron 2 either. Electron 2 uses Chromium 61. And I believe that Electron 1.8.6 uses Chromium 59.
It would seem that RTCPeerConnection.addTrack() has been in chrome since 56: https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack
Can you make following test in Electron environment?:
p = new RTCPeerConnection
typeof p.addTrack
It should return function. If it returns undefined instead, you may need to report the issue to Electron developers and try WebRTC adapter.
undefined indeed. Thanks again.
@thbaja Please update us if you hear anything from the Electron maintainers about what's going on. This is quite odd, IMO.
MDN is wrong, native addTrack only came to Chrome in M64, not M56. adapter provides a shim so including it once before simple-peer might work
Thanks for the clarification @fippo.
I can confirm that it's as easy as you describe. You only have to require the adapter before using simple-peer.
I had a small issue with a limitation in the shim though, which might be worth for other users to be aware of.
'The adapter.js addTrack polyfill only supports a single ' +
' stream which is associated with the specified track.',
'NotSupportedError');
Is your track associated with your stream? ie) Is it one of the tracks in stream.getTracks()?
Try this:
peer.addTrack(stream.getTracks()[0], stream)
Thanks for that critical info, @fippo! 鉂わ笍
@RationalCoding, thanks I'm good 馃憤
Just wanted to mention it since other people might go down the same path and use simple-peer for Electron projects and stumble upon the same things.
M66 upgrade is in progress for a while now, hopefully soon: https://github.com/electron/electron/pull/12477
Most helpful comment
MDN is wrong, native addTrack only came to Chrome in M64, not M56. adapter provides a shim so including it once before simple-peer might work