From 7899611f228a11602807ce08189c581522a72065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 6 May 2021 09:20:02 +0200 Subject: [PATCH] Drop (old) Edge support The new Edge is based in Chromium and the Chrome shim is used. --- Gruntfile.js | 26 ------ README.md | 2 - index.d.ts | 7 +- package.json | 2 - src/js/adapter_factory.js | 21 ----- src/js/edge/edge_shim.js | 89 ------------------- src/js/edge/filtericeservers.js | 51 ----------- src/js/edge/getdisplaymedia.js | 24 ------ src/js/edge/getusermedia.js | 31 ------- src/js/utils.js | 5 -- test/e2e/connection.js | 9 -- test/e2e/simulcast.js | 3 +- test/karma.conf.js | 6 +- test/unit/adapter_factory.js | 2 +- test/unit/detectBrowser.js | 11 --- test/unit/edge.js | 146 -------------------------------- 16 files changed, 5 insertions(+), 430 deletions(-) delete mode 100644 src/js/edge/edge_shim.js delete mode 100644 src/js/edge/filtericeservers.js delete mode 100644 src/js/edge/getdisplaymedia.js delete mode 100644 src/js/edge/getusermedia.js delete mode 100644 test/unit/edge.js diff --git a/Gruntfile.js b/Gruntfile.js index d3ff4164a..bb9e6419b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -33,32 +33,6 @@ module.exports = function(grunt) { adapterAndNoGlobalObject: { src: ['./dist/adapter_core5.js'], dest: './out/adapter_no_global.js' - }, - // Use this if you do not want Microsoft Edge shim to be included. - adapterNoEdge: { - src: ['./dist/adapter_core5.js'], - dest: './out/adapter_no_edge.js', - options: { - // These files will be skipped. - ignore: [ - './dist/edge/edge_shim.js' - ], - browserifyOptions: { - // Exposes the shim in a global object to the browser. - standalone: 'adapter' - } - } - }, - // Use this if you do not want Microsoft Edge shim to be included and - // do not want adapter to expose anything to the global scope. - adapterNoEdgeAndNoGlobalObject: { - src: ['./dist/adapter_core5.js'], - dest: './out/adapter_no_edge_no_global.js', - options: { - ignore: [ - './dist/edge/edge_shim.js' - ] - } } }, eslint: { diff --git a/README.md b/README.md index 1f2e1448c..367d9954d 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,6 @@ You will find `adapter.js` in `bower_components/webrtc-adapter/`. ##### NPM In node_modules/webrtc-adapter/out/ folder you will find 4 files: * `adapter.js` - includes all the shims and is visible in the browser under the global `adapter` object (window.adapter). -* `adapter_no_edge.js` - same as above but does not include the Microsoft Edge (ORTC) shim. -* `adapter_no_edge_no_global.js` - same as above but is not exposed/visible in the browser (you cannot call/interact with the shims in the browser). * `adapter_no_global.js` - same as `adapter.js` but is not exposed/visible in the browser (you cannot call/interact with the shims in the browser). Include the file that suits your need in your project. diff --git a/index.d.ts b/index.d.ts index 9d5961ff8..22e2f0420 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,11 +25,6 @@ declare module "webrtc-adapter" { fixNegotiationNeeded(window: Window): void; } - interface IEdgeShim { - shimPeerConnection(window: Window): void; - shimReplaceTrack(window: Window): void; - } - interface IFirefoxShim { shimOnTrack(window: Window): void; shimPeerConnection(window: Window): void; @@ -53,7 +48,7 @@ declare module "webrtc-adapter" { export interface IAdapter { browserDetails: IBrowserDetails; commonShim: ICommonShim; - browserShim: IChromeShim | IEdgeShim | IFirefoxShim | ISafariShim | undefined; + browserShim: IChromeShim | IFirefoxShim | ISafariShim | undefined; extractVersion(uastring: string, expr: string, pos: number): number; disableLog(disable: boolean): void; disableWarnings(disable: boolean): void; diff --git a/package.json b/package.json index 326c60d5e..752d8a854 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "e2e-tests": "grunt && grunt downloadBrowser && karma start test/karma.conf.js" }, "dependencies": { - "rtcpeerconnection-shim": "^1.2.15", "sdp": "^2.12.0" }, "engines": { @@ -49,7 +48,6 @@ "karma-browserify": "^5.2.0", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^2.2.0", - "karma-edge-launcher": "^0.4.1", "karma-firefox-launcher": "^1.3.0", "karma-mocha": "^1.3.0", "karma-mocha-reporter": "^2.2.3", diff --git a/src/js/adapter_factory.js b/src/js/adapter_factory.js index 92e247711..20ccf4007 100644 --- a/src/js/adapter_factory.js +++ b/src/js/adapter_factory.js @@ -9,7 +9,6 @@ import * as utils from './utils'; // Browser shims. import * as chromeShim from './chrome/chrome_shim'; -import * as edgeShim from './edge/edge_shim'; import * as firefoxShim from './firefox/firefox_shim'; import * as safariShim from './safari/safari_shim'; import * as commonShim from './common_shim'; @@ -18,7 +17,6 @@ import * as commonShim from './common_shim'; export function adapterFactory({window} = {}, options = { shimChrome: true, shimFirefox: true, - shimEdge: true, shimSafari: true, }) { // Utils. @@ -95,25 +93,6 @@ export function adapterFactory({window} = {}, options = { commonShim.shimRTCIceCandidate(window, browserDetails); commonShim.shimConnectionState(window, browserDetails); - commonShim.shimMaxMessageSize(window, browserDetails); - commonShim.shimSendThrowTypeError(window, browserDetails); - break; - case 'edge': - if (!edgeShim || !edgeShim.shimPeerConnection || !options.shimEdge) { - logging('MS edge shim is not included in this adapter release.'); - return adapter; - } - logging('adapter.js shimming edge.'); - // Export to the adapter global object visible in the browser. - adapter.browserShim = edgeShim; - - edgeShim.shimGetUserMedia(window, browserDetails); - edgeShim.shimGetDisplayMedia(window, browserDetails); - edgeShim.shimPeerConnection(window, browserDetails); - edgeShim.shimReplaceTrack(window, browserDetails); - - // the edge shim implements the full RTCIceCandidate object. - commonShim.shimMaxMessageSize(window, browserDetails); commonShim.shimSendThrowTypeError(window, browserDetails); break; diff --git a/src/js/edge/edge_shim.js b/src/js/edge/edge_shim.js deleted file mode 100644 index edff170c1..000000000 --- a/src/js/edge/edge_shim.js +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. - */ -/* eslint-env node */ -'use strict'; - -import * as utils from '../utils'; -import {filterIceServers} from './filtericeservers'; -import shimRTCPeerConnection from 'rtcpeerconnection-shim'; - -export {shimGetUserMedia} from './getusermedia'; -export {shimGetDisplayMedia} from './getdisplaymedia'; - -export function shimPeerConnection(window, browserDetails) { - if (window.RTCIceGatherer) { - if (!window.RTCIceCandidate) { - window.RTCIceCandidate = function RTCIceCandidate(args) { - return args; - }; - } - if (!window.RTCSessionDescription) { - window.RTCSessionDescription = function RTCSessionDescription(args) { - return args; - }; - } - // this adds an additional event listener to MediaStrackTrack that signals - // when a tracks enabled property was changed. Workaround for a bug in - // addStream, see below. No longer required in 15025+ - if (browserDetails.version < 15025) { - const origMSTEnabled = Object.getOwnPropertyDescriptor( - window.MediaStreamTrack.prototype, 'enabled'); - Object.defineProperty(window.MediaStreamTrack.prototype, 'enabled', { - set(value) { - origMSTEnabled.set.call(this, value); - const ev = new Event('enabled'); - ev.enabled = value; - this.dispatchEvent(ev); - } - }); - } - } - - // ORTC defines the DTMF sender a bit different. - // https://github.com/w3c/ortc/issues/714 - if (window.RTCRtpSender && !('dtmf' in window.RTCRtpSender.prototype)) { - Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', { - get() { - if (this._dtmf === undefined) { - if (this.track.kind === 'audio') { - this._dtmf = new window.RTCDtmfSender(this); - } else if (this.track.kind === 'video') { - this._dtmf = null; - } - } - return this._dtmf; - } - }); - } - // Edge currently only implements the RTCDtmfSender, not the - // RTCDTMFSender alias. See http://draft.ortc.org/#rtcdtmfsender2* - if (window.RTCDtmfSender && !window.RTCDTMFSender) { - window.RTCDTMFSender = window.RTCDtmfSender; - } - - const RTCPeerConnectionShim = shimRTCPeerConnection(window, - browserDetails.version); - window.RTCPeerConnection = function RTCPeerConnection(config) { - if (config && config.iceServers) { - config.iceServers = filterIceServers(config.iceServers, - browserDetails.version); - utils.log('ICE servers after filtering:', config.iceServers); - } - return new RTCPeerConnectionShim(config); - }; - window.RTCPeerConnection.prototype = RTCPeerConnectionShim.prototype; -} - -export function shimReplaceTrack(window) { - // ORTC has replaceTrack -- https://github.com/w3c/ortc/issues/614 - if (window.RTCRtpSender && - !('replaceTrack' in window.RTCRtpSender.prototype)) { - window.RTCRtpSender.prototype.replaceTrack = - window.RTCRtpSender.prototype.setTrack; - } -} diff --git a/src/js/edge/filtericeservers.js b/src/js/edge/filtericeservers.js deleted file mode 100644 index 027654647..000000000 --- a/src/js/edge/filtericeservers.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. - */ -/* eslint-env node */ -'use strict'; - -import * as utils from '../utils'; -// Edge does not like -// 1) stun: filtered after 14393 unless ?transport=udp is present -// 2) turn: that does not have all of turn:host:port?transport=udp -// 3) turn: with ipv6 addresses -// 4) turn: occurring muliple times -export function filterIceServers(iceServers, edgeVersion) { - let hasTurn = false; - iceServers = JSON.parse(JSON.stringify(iceServers)); - return iceServers.filter(server => { - if (server && (server.urls || server.url)) { - let urls = server.urls || server.url; - if (server.url && !server.urls) { - utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls'); - } - const isString = typeof urls === 'string'; - if (isString) { - urls = [urls]; - } - urls = urls.filter(url => { - // filter STUN unconditionally. - if (url.indexOf('stun:') === 0) { - return false; - } - - const validTurn = url.startsWith('turn') && - !url.startsWith('turn:[') && - url.includes('transport=udp'); - if (validTurn && !hasTurn) { - hasTurn = true; - return true; - } - return validTurn && !hasTurn; - }); - - delete server.url; - server.urls = isString ? urls[0] : urls; - return !!urls.length; - } - }); -} diff --git a/src/js/edge/getdisplaymedia.js b/src/js/edge/getdisplaymedia.js deleted file mode 100644 index 67984b1c1..000000000 --- a/src/js/edge/getdisplaymedia.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. - */ - /* eslint-env node */ -'use strict'; - -export function shimGetDisplayMedia(window) { - if (!('getDisplayMedia' in window.navigator)) { - return; - } - if (!(window.navigator.mediaDevices)) { - return; - } - if (window.navigator.mediaDevices && - 'getDisplayMedia' in window.navigator.mediaDevices) { - return; - } - window.navigator.mediaDevices.getDisplayMedia = - window.navigator.getDisplayMedia.bind(window.navigator); -} diff --git a/src/js/edge/getusermedia.js b/src/js/edge/getusermedia.js deleted file mode 100644 index c44833356..000000000 --- a/src/js/edge/getusermedia.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. - */ - /* eslint-env node */ -'use strict'; - -export function shimGetUserMedia(window) { - const navigator = window && window.navigator; - - const shimError_ = function(e) { - return { - name: {PermissionDeniedError: 'NotAllowedError'}[e.name] || e.name, - message: e.message, - constraint: e.constraint, - toString() { - return this.name; - } - }; - }; - - // getUserMedia error shim. - const origGetUserMedia = navigator.mediaDevices.getUserMedia. - bind(navigator.mediaDevices); - navigator.mediaDevices.getUserMedia = function(c) { - return origGetUserMedia(c).catch(e => Promise.reject(shimError_(e))); - }; -} diff --git a/src/js/utils.js b/src/js/utils.js index 4dbbb280f..bcafbfbf2 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -174,11 +174,6 @@ export function detectBrowser(window) { result.browser = 'chrome'; result.version = extractVersion(navigator.userAgent, /Chrom(e|ium)\/(\d+)\./, 2); - } else if (navigator.mediaDevices && - navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) { // Edge. - result.browser = 'edge'; - result.version = extractVersion(navigator.userAgent, - /Edge\/(\d+).(\d+)$/, 2); } else if (window.RTCPeerConnection && navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) { // Safari. result.browser = 'safari'; diff --git a/test/e2e/connection.js b/test/e2e/connection.js index 637c59229..82c93ebf0 100644 --- a/test/e2e/connection.js +++ b/test/e2e/connection.js @@ -212,9 +212,6 @@ describe('establishes a connection', () => { }); it('with no explicit end-of-candidates', function(done) { - if (window.adapter.browserDetails.browser === 'edge') { - this.timeout(10000); - } pc1.oniceconnectionstatechange = function() { if (pc1.iceConnectionState === 'connected' || pc1.iceConnectionState === 'completed') { @@ -245,12 +242,6 @@ describe('establishes a connection', () => { }); describe('with datachannel', function() { - beforeEach(function() { - if (window.adapter.browserDetails.browser === 'edge') { - this.skip(); - } - }); - it('establishes a connection', (done) => { pc1.oniceconnectionstatechange = function() { if (pc1.iceConnectionState === 'connected' || diff --git a/test/e2e/simulcast.js b/test/e2e/simulcast.js index 4b40c744a..f6b1e9e9e 100644 --- a/test/e2e/simulcast.js +++ b/test/e2e/simulcast.js @@ -19,8 +19,7 @@ describe('simulcast', () => { }); it('using transceivers APIs', function() { - if (window.adapter.browserDetails.browser === 'edge' || - window.adapter.browserDetails.browser === 'safari') { + if (window.adapter.browserDetails.browser === 'safari') { this.skip(); } const constraints = {video: true}; diff --git a/test/karma.conf.js b/test/karma.conf.js index 839bc2481..a1e2e4277 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -12,9 +12,7 @@ const os = require('os'); let browsers; if (process.env.BROWSER) { - if (process.env.BROWSER === 'MicrosoftEdge') { - browsers = ['Edge']; - } else if (process.env.BROWSER === 'safari') { + if (process.env.BROWSER === 'safari') { browsers = ['Safari']; } else if (process.env.BROWSER === 'Electron') { browsers = ['electron']; @@ -24,7 +22,7 @@ if (process.env.BROWSER) { } else if (os.platform() === 'darwin') { browsers = ['chrome', 'firefox', 'Safari']; } else if (os.platform() === 'win32') { - browsers = ['chrome', 'firefox', 'Edge']; + browsers = ['chrome', 'firefox']; } else { browsers = ['chrome', 'firefox']; } diff --git a/test/unit/adapter_factory.js b/test/unit/adapter_factory.js index eb2a8967c..cacb91a28 100644 --- a/test/unit/adapter_factory.js +++ b/test/unit/adapter_factory.js @@ -27,7 +27,7 @@ describe('adapter factory', () => { afterEach(() => { utils.detectBrowser.restore(); }); - ['Chrome', 'Firefox', 'Safari', 'Edge'].forEach(browser => { + ['Chrome', 'Firefox', 'Safari'].forEach(browser => { it(browser + ' when disabled', () => { sinon.stub(utils, 'detectBrowser').returns({ browser: browser.toLowerCase() diff --git a/test/unit/detectBrowser.js b/test/unit/detectBrowser.js index 877f256f9..a256b336f 100644 --- a/test/unit/detectBrowser.js +++ b/test/unit/detectBrowser.js @@ -41,17 +41,6 @@ describe('detectBrowser', () => { expect(browserDetails.version).to.equal(45); }); - it('detects Edge if navigator.mediaDevices exists', () => { - navigator.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' + - 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 ' + - 'Safari/537.36 Edge/13.10547'; - navigator.mediaDevices = function() {}; - - const browserDetails = detectBrowser(window); - expect(browserDetails.browser).to.equal('edge'); - expect(browserDetails.version).to.equal(10547); - }); - it('detects Safari if window.RTCPeerConnection exists', () => { navigator.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) ' + 'AppleWebKit/604.1.6 (KHTML, like Gecko) Version/10.2 Safari/604.1.6'; diff --git a/test/unit/edge.js b/test/unit/edge.js deleted file mode 100644 index d29052c62..000000000 --- a/test/unit/edge.js +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. - */ -/* eslint-env node */ -const chai = require('chai'); -const expect = chai.expect; -const sinon = require('sinon'); -const sinonChai = require('sinon-chai'); -chai.use(sinonChai); - -describe('Edge shim', () => { - const shim = require('../../dist/edge/edge_shim'); - let window; - - const ua15025 = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' + - 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 ' + - 'Safari/537.36 Edge/15.15025'; - - beforeEach(() => { - window = { - navigator: { - userAgent: ua15025, - mediaDevices: {}, - getDisplayMedia: sinon.stub, - }, - }; - shim.shimPeerConnection(window, {}); - }); - - it('creates window.RTCPeerConnection', () => { - delete window.RTCPeerConnection; - shim.shimPeerConnection(window, {}); - expect(window.RTCPeerConnection).not.to.equal(undefined); - }); - - it('overrides window.RTCPeerConnection if it exists', () => { - window.RTCPeerConnection = true; - shim.shimPeerConnection(window, {}); - expect(window.RTCPeerConnection).not.to.equal(true); - }); - - describe('filtering of STUN and TURN servers', () => { - const edgeVersion = 15025; - const {filterIceServers} = require('../../dist/edge/filtericeservers'); - - it('converts legacy url member to urls', () => { - const result = filterIceServers([ - {url: 'turn:stun.l.google.com:19302?transport=udp'} - ], edgeVersion); - expect(result).to.deep.equal([ - {urls: 'turn:stun.l.google.com:19302?transport=udp'} - ]); - }); - - it('filters STUN before r14393', () => { - const result = filterIceServers([ - {urls: 'stun:stun.l.google.com'} - ], 14392); - expect(result).to.deep.equal([]); - }); - - it('does filter STUN without protocol after r14393', () => { - const result = filterIceServers([ - {urls: 'stun:stun.l.google.com'} - ], edgeVersion); - expect(result).to.deep.equal([]); - }); - - it('does filter STUN with protocol even after r14393', () => { - const result = filterIceServers([ - {urls: 'stun:stun.l.google.com:19302?transport=udp'} - ], edgeVersion); - expect(result).to.deep.equal([]); - }); - - it('filters incomplete TURN urls', () => { - const result = filterIceServers([ - {urls: 'turn:stun.l.google.com'}, - {urls: 'turn:stun.l.google.com:19302'} - ], edgeVersion); - expect(result).to.deep.equal([]); - }); - - it('filters TURN TCP', () => { - const result = filterIceServers([ - {urls: 'turn:stun.l.google.com:19302?transport=tcp'} - ], edgeVersion); - expect(result).to.deep.equal([]); - }); - - describe('removes all but the first server of a type', () => { - it('in separate entries', () => { - const result = filterIceServers([ - {urls: 'stun:stun.l.google.com'}, - {urls: 'turn:stun.l.google.com:19301?transport=udp'}, - {urls: 'turn:stun.l.google.com:19302?transport=udp'} - ], edgeVersion); - expect(result).to.deep.equal([ - {urls: 'turn:stun.l.google.com:19301?transport=udp'} - ]); - }); - - it('in urls entries', () => { - const result = filterIceServers([ - {urls: [ - 'turn:stun.l.google.com:19301?transport=udp', - 'turn:stun.l.google.com:19302?transport=udp' - ]} - ], edgeVersion); - expect(result).to.deep.equal([ - {urls: ['turn:stun.l.google.com:19301?transport=udp']} - ]); - }); - }); - }); - - describe('getDisplayMedia shim', () => { - it('does nothing if navigator.getDisplayMedia does not exist', () => { - delete window.navigator.getDisplayMedia; - shim.shimGetDisplayMedia(window); - expect(window.navigator.mediaDevices.getDisplayMedia).to.equal(undefined); - }); - - it('does not if navigator.mediaDevices does not exist', () => { - delete window.navigator.mediaDevices; - shim.shimGetDisplayMedia(window); - expect(window.navigator.mediaDevices).to.equal(undefined); - }); - - it('does not overwrite an existing ' + - 'navigator.mediaDevices.getDisplayMedia', () => { - window.navigator.mediaDevices.getDisplayMedia = 'foo'; - shim.shimGetDisplayMedia(window); - expect(window.navigator.mediaDevices.getDisplayMedia).to.equal('foo'); - }); - - it('shims navigator.mediaDevices.getDisplayMedia', () => { - shim.shimGetDisplayMedia(window); - expect(window.navigator.mediaDevices.getDisplayMedia).to.be.a('function'); - }); - }); -});