feross / simple-peer

📡 Simple WebRTC video, voice, and data channels
MIT License
7.37k stars 972 forks source link

shim support #26

Closed yocontra closed 9 years ago

yocontra commented 9 years ago

There are some shims (for example: https://code.google.com/p/webrtc4all/) that allow you to do webrtc all the way back to IE6. Crazy.

The API is supposed to be the same as the spec but it looks a little different from a first glance. Not going to be easy to drop it right in. I was curious if you had any ideas for how this should work with simple-peer

Stuff I can think of off the top of my head:

LMK your thoughts :+1:

feross commented 9 years ago

It looks like this shim requires an installation, since they're shipping an .exe file. When installed, they expose a w4aPeerConnection global in their supported browsers. Pretty cool trick.

It looks like they might be using ORTC (the next version of WebRTC, with an incompatible API). I'm not interested in supporting ORTC in simple-peer until at least one browser actually starts shipping with it. Microsoft's next browser will only support ORTC and not WebRTC, so that would be a good time to add support.

There supposedly are ORTC -> WebRTC shims available. If you use one of those, then you should get an API that'll work with simple-peer. Then just set it on the window and simple-peer will find it. Or you can pass it into simple-peer explicitly, as described here in the readme:

var peer = new SimplePeer({
  wrtc: {
    RTCPeerConnection: {},
    RTCSessionDescription {},
    RTCIceCandidate: {} // fill these in with the actual implementations
  }
}

Alternatively, just use the Temasys plugin (https://temasys.atlassian.net/wiki/display/TWPP/WebRTC+Plugins) which exposes the current WebRTC API instead of ORTC.

yocontra commented 9 years ago

@feross Hadn't seen this temasys stuff - super cool! I'll check it out and report back if all works well :+1:

yocontra commented 9 years ago

@feross Have you used it before? Got any example code up somewhere?

feross commented 9 years ago

Perhaps @serrynaimo can help with the sample code?

serrynaimo commented 9 years ago

@contra you can just import http://cdn.temasys.com.sg/adapterjs/0.10.x/adapter.min.js before simple peer. It'll then work with the plugin in IE/Safari. simple-peers getBrowserRTC function will recognise the RTCPeerConnection to be present and should just work.

Make sure you put all WebRTC related code into

AdapterJS.onwebrtcready = function(isUsingPlugin) {
    // The WebRTC API is ready.
    // isUsingPlugin: true is the WebRTC plugin is being used, false otherwise
    getUserMedia(constraints, successCb, failCb);
};

Will give it a try myself soon.

yocontra commented 9 years ago

@serrynaimo Found a few issues with using it with simple-peer but I've opened them on the AdapterJS repo

yocontra commented 9 years ago

After a lot of struggling I got Temasys working for the most part, but when a Temasys client enters a call with a Chrome client (both using simple-peer) simple-peer on chrome destroys the peer during negotiation with this debug message

[3a52134] destroy (error: signal() called with invalid signal data)

but it seems like the temasys client is sending valid data.

Still investigating what is going on, will update when I figure it out

serrynaimo commented 9 years ago

Thanks for all the hard work! Please continue to share your findings, I'll loop in the team to see if they have advice.

yocontra commented 9 years ago

I got it! Working video call between chrome and safari, data channels work as well. I had to change some stuff in simple-peer, the whole problem was that the object provided by the shim is not JSON serializable, so you just need to have simple-peer pick the right properties off of it. I'll send a PR in a minute.

feross commented 9 years ago

@serrynaimo Can you fix this bug in the Temasys plugin and make the sdp objects serializable with JSON.stringify? That sounds like a compatibility bug.

yocontra commented 9 years ago

@feross That seems like the most logical thing to do, but I think that code is actually in their native extension and I have no idea where to track that code down + it would have to be fixed across 3 repos. The simplest fix for me was to just do it in simple-peer to get this working ASAP, I think long-term it would be better to have temasys do it on their end. I'll open a ticket in the right places and link them back here

yocontra commented 9 years ago

Looks like somebody beat me to it:

Feel free to close the PR if you feel like it's worth waiting for TemaSys to fix it or if it isn't a priority

feross commented 9 years ago

@contra No, I'll merge your PR but will revert once Temasys fixes it. Would like to keep as many hacks as possible out of the codebase.