angular / zone.js

Implements Zones for JavaScript
https://github.com/angular/angular/tree/master/packages/zone.js/
MIT License
3.25k stars 408 forks source link

getUserMedia and RTCPeerConnection #948

Closed benbro closed 5 years ago

benbro commented 7 years ago

getUserMedia and RTCPeerConnection behave differently on Chrome, Firefox, Edge and Safari when using zone.js. On Chrome callbacks are run inside the zone while on other browsers they run outside the zone.

I've added the webrtc/samples PeerConnection example to a simple Angular 5 app.

Test the following app in Firefox 56 and compare it with Chrome 62.

App: https://angular-gitter-mgsmnr.stackblitz.io

Editor: https://stackblitz.com/edit/angular-gitter-mgsmnr

JiaLiPassion commented 7 years ago

@benbro , I will test it, thanks.

aullman commented 6 years ago

I have also found that events don't work on RTCPeerConnections in Safari at all when you include zone.js. With zone.js included on the page if I execute:

let pc = new RTCPeerConnection();
pc.addEventListener('icecandidate', function(){alert('candidate');});
pc.dispatchEvent(new Event('icecandidate'));

Then I don't get the alert at all, the event does not dispatch. But if I don't include zone.js then it works as expected. This results in WebRTC apps not working at all when using Zone.js because we can't get any of the ice candidate events.

aullman commented 6 years ago

Oops, sorry, just found this has already been fixed with https://github.com/angular/zone.js/issues/883

I just had to add this to my polyfills.ts file.

import 'zone.js/dist/webapis-rtc-peer-connection';
JiaLiPassion commented 6 years ago

@benbro , @aullman , just like @aullman said, to use getUserMedia and rtcpeerconnection, please include following files into polyfill.ts

// rtc peer connection patch
import 'zone.js/dist/webapis-rtc-peer-connection';
// getUserMedia patch
import 'zone.js/dist/zone-patch-user-media.js';

if there is still problem , please let me know.

benbro commented 6 years ago

@JiaLiPassion thanks. Is this specifically for Safari or for Edge and Firefox too?

benbro commented 6 years ago

Edge uses ORTC which uses newer API. Chrome is adding support over time. RTCIceGatherer RTCIceTransport RTCDtlsTransport RTCRtpSender RTCRtpReceiver

JiaLiPassion commented 6 years ago

@benbro , I am not familiar with the RTC differences between all those browsers, as your very first comments, some browser work, some not, is that correct?

And I will check those new API later.

benbro commented 6 years ago

RTCRtpSender RTCRtpSender and RTCRtpReceiver RTCIceGatherer RTCIceTransport RTCDtlsTransport

hermanfransen commented 6 years ago

I forked @benbro app and upgraded zone.js 0.8.18 -> 0.8.20 and polyfills.ts added patches:

// rtc peer connection patch
import 'zone.js/dist/webapis-rtc-peer-connection';
// getUserMedia patch
import 'zone.js/dist/zone-patch-user-media';

Then pc.component.html added playsinline to support Safari (see issue #1019):

<video #localVideo playsinline autoplay muted></video>
<video #remoteVideo playsinline autoplay></video>

App: https://webrtc-angular-test.stackblitz.io/

Editor: https://stackblitz.com/edit/webrtc-angular-test

But even with the patches the 'Call' button stays disabled on Firefox (I used Firefox 58.0.2 (64-bits) on MacOS 10.12.6)

JiaLiPassion commented 6 years ago

@hermanfransen , thank you for the stackblitz demo, I will check it.

tamiorzel commented 6 years ago

what about IE?

hermanfransen commented 6 years ago

@JiaLiPassion , you are welcome. It's the same as the repo I send you in #1019 by the way.

hermanfransen commented 6 years ago

@tamiorzel , WebRTC is not supported by IE. See this for more information.

marcelrouw commented 6 years ago

@hermanfransen There few WeRTC plugins for IE like Temasys. So it's possible to use WeRTC in IE. There are still some (mainly big) companies that rather use IE with a plugin instead of a modern browser with a native implementation of WeRTC.

JiaLiPassion commented 5 years ago

close this for duplicate issue in angular repo.