diff --git a/gulpfile.js b/gulpfile.js index e30cfb842..09f65c987 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -137,6 +137,14 @@ gulp.task('build/webapis-notification.min.js', ['compile-esm'], function(cb) { return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.min.js', true, cb); }); +gulp.task('build/webapis-rtc-peer-connection.js', ['compile-esm'], function(cb) { + return generateScript('./lib/browser/webapis-rtc-peer-connection.ts', 'webapis-rtc-peer-connection.js', false, cb); +}); + +gulp.task('build/webapis-rtc-peer-connection.min.js', ['compile-esm'], function(cb) { + return generateScript('./lib/browser/webapis-rtc-peer-connection.ts', 'webapis-rtc-peer-connection.min.js', true, cb); +}); + gulp.task('build/webapis-shadydom.js', ['compile-esm'], function(cb) { return generateScript('./lib/browser/shadydom.ts', 'webapis-shadydom.js', false, cb); }); @@ -245,6 +253,8 @@ gulp.task('build', [ 'build/webapis-media-query.min.js', 'build/webapis-notification.js', 'build/webapis-notification.min.js', + 'build/webapis-rtc-peer-connection.js', + 'build/webapis-rtc-peer-connection.min.js', 'build/webapis-shadydom.js', 'build/webapis-shadydom.min.js', 'build/zone-patch-cordova.js', diff --git a/lib/browser/webapis-rtc-peer-connection.ts b/lib/browser/webapis-rtc-peer-connection.ts new file mode 100644 index 000000000..2551ae234 --- /dev/null +++ b/lib/browser/webapis-rtc-peer-connection.ts @@ -0,0 +1,26 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +Zone.__load_patch('RTCPeerConnection', (global: any, Zone: ZoneType, api: _ZonePrivate) => { + const RTCPeerConnection = global['RTCPeerConnection']; + if (!RTCPeerConnection) { + return; + } + + const addSymbol = api.symbol('addEventListener'); + const removeSymbol = api.symbol('removeEventListener'); + + RTCPeerConnection.prototype.addEventListener = RTCPeerConnection.prototype[addSymbol]; + RTCPeerConnection.prototype.removeEventListener = RTCPeerConnection.prototype[removeSymbol]; + + // RTCPeerConnection extends EventTarget, so we must clear the symbol + // to allow pathc RTCPeerConnection.prototype.addEventListener again + RTCPeerConnection.prototype[addSymbol] = null; + RTCPeerConnection.prototype[removeSymbol] = null; + + api.patchEventTarget(global, [RTCPeerConnection.prototype], {useGlobalCallback: false}); +});