Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIDEO-4958 Remove unused Chrome shims and plan-b shims. #1965

Draft
wants to merge 2 commits into
base: VIDEO-4958/remove-unused-shims
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/connect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { MediaStreamTrack } = require('./webrtc');
const { guessBrowser, guessBrowserVersion } = require('./webrtc/util');
const createCancelableRoomPromise = require('./cancelableroompromise');
const EncodingParametersImpl = require('./encodingparameters');
Expand Down
2 changes: 1 addition & 1 deletion lib/createlocaltracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { applyNoiseCancellation } from './media/track/noisecancellationimpl';

const { buildLogLevels } = require('./util');
const { getUserMedia, MediaStreamTrack } = require('./webrtc');
const { getUserMedia } = require('./webrtc');

const {
LocalAudioTrack,
Expand Down
1 change: 0 additions & 1 deletion lib/localparticipant.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { MediaStreamTrack } = require('./webrtc');
const { asLocalTrack, asLocalTrackPublication, trackClass } = require('./util');
const { typeErrors: E, trackPriority } = require('./util/constants');
const { validateLocalTrack } = require('./util/validate');
Expand Down
2 changes: 0 additions & 2 deletions lib/media/track/mediatrack.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const { isIOS } = require('../../util/browserdetection');
const { MediaStream } = require('../../webrtc');

const { waitForEvent, waitForSometime } = require('../../util');
const localMediaRestartDeferreds = require('../../util/localmediarestartdeferreds');
const Track = require('./');
Expand Down
7 changes: 3 additions & 4 deletions lib/signaling/v2/peerconnection.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const DefaultBackoff = require('../../util/backoff');

const {
RTCIceCandidate: DefaultRTCIceCandidate,
RTCPeerConnection: DefaultRTCPeerConnection,
RTCSessionDescription: DefaultRTCSessionDescription,
getStats: getStatistics
} = require('../../webrtc');

Expand Down Expand Up @@ -128,9 +127,9 @@ class PeerConnectionV2 extends StateMachine {
setSimulcast,
Backoff: DefaultBackoff,
IceConnectionMonitor: DefaultIceConnectionMonitor,
RTCIceCandidate: DefaultRTCIceCandidate,
RTCIceCandidate,
RTCPeerConnection: DefaultRTCPeerConnection,
RTCSessionDescription: DefaultRTCSessionDescription,
RTCSessionDescription,
Timeout: DefaultTimeout
}, options);

Expand Down
2 changes: 0 additions & 2 deletions lib/util/sdp/issue8329.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const { RTCSessionDescription } = require('../../webrtc');

const { createPtToCodecName, getMediaSections } = require('./');

/**
Expand Down
52 changes: 49 additions & 3 deletions lib/util/support.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* globals RTCRtpTransceiver */

'use strict';

const { guessBrowser, support: isWebRTCSupported } = require('../webrtc/util');
const { getSdpFormat } = require('../webrtc/util/sdp');
const { isAndroid, isMobile, isNonChromiumEdge, rebrandedChromeBrowser, mobileWebKitBrowser } = require('./browserdetection');

const SUPPORTED_CHROME_BASED_BROWSERS = [
Expand All @@ -22,11 +23,56 @@ const SUPPORTED_IOS_BROWSERS = [
// Currently none. Add 'brave', 'edg', and 'edge' here once we start supporting them
const SUPPORTED_MOBILE_WEBKIT_BASED_BROWSERS = [];

// NOTE(mmalavalli): We cache Chrome's unified plan support in order
// to prevent instantiation of more than one RTCPeerConnection.
let isChromeUnifiedPlanSupported;

/**
* Check whether the current browser supports unified plan sdps.
* @param {boolean} [shouldCacheResultForChrome=true] - For unit tests only
*/
function isUnifiedPlanSupported(shouldCacheResultForChrome = true) {
const maybeCacheResultForChrome = shouldCacheResultForChrome
? result => { isChromeUnifiedPlanSupported = result; }
: () => { /* Do not cache result for Chrome */ };

let isSupported;

return ({
chrome: () => {
if (typeof isChromeUnifiedPlanSupported === 'boolean') {
return isChromeUnifiedPlanSupported;
}
if (typeof RTCPeerConnection === 'undefined' || !('addTransceiver' in RTCPeerConnection.prototype)) {
maybeCacheResultForChrome(isSupported = false);
return isSupported;
}
const peerConnection = new RTCPeerConnection();
try {
peerConnection.addTransceiver('audio');
maybeCacheResultForChrome(isSupported = true);
} catch (e) {
maybeCacheResultForChrome(isSupported = false);
}
peerConnection.close();
return isSupported;
},
firefox: () => {
return true;
},
safari: () => {
return typeof RTCRtpTransceiver !== 'undefined'
&& 'currentDirection' in RTCRtpTransceiver.prototype;
}
}[guessBrowser()] || (() => false))();
}

/**
* Check if the current browser is officially supported by twilio-video.js.
@param {boolean} [shouldCacheUnifiedPlanSupportForChrome=true] - For unit tests only
* @returns {boolean}
*/
function isSupported() {
function isSupported(shouldCacheUnifiedPlanSupportForChrome = true) {
const browser = guessBrowser();

// NOTE (csantos): Return right away if there is no browser detected
Expand All @@ -42,7 +88,7 @@ function isSupported() {

return !!browser
&& isWebRTCSupported()
&& getSdpFormat() === 'unified'
&& isUnifiedPlanSupported(shouldCacheUnifiedPlanSupportForChrome)
&& (!rebrandedChrome || SUPPORTED_CHROME_BASED_BROWSERS.includes(rebrandedChrome))
&& !isNonChromiumEdge(browser)
&& (!mobileWebKit || SUPPORTED_MOBILE_WEBKIT_BASED_BROWSERS.includes(mobileWebKit))
Expand Down
27 changes: 6 additions & 21 deletions lib/webrtc/getstats.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { flatMap, guessBrowser, guessBrowserVersion } = require('./util');
const { getSdpFormat } = require('./util/sdp');

const guess = guessBrowser();
const guessVersion = guessBrowserVersion();
Expand Down Expand Up @@ -277,14 +276,9 @@ function standardizeFirefoxActiveIceCandidatePairStats(stats) {
*/
function getTracks(peerConnection, kind, localOrRemote) {
const getSendersOrReceivers = localOrRemote === 'local' ? 'getSenders' : 'getReceivers';
if (peerConnection[getSendersOrReceivers]) {
return peerConnection[getSendersOrReceivers]()
.map(({ track }) => track)
.filter(track => track && track.kind === kind);
}
const getStreams = localOrRemote === 'local' ? 'getLocalStreams' : 'getRemoteStreams';
const getTracks = kind === 'audio' ? 'getAudioTracks' : 'getVideoTracks';
return flatMap(peerConnection[getStreams](), stream => stream[getTracks]());
return peerConnection[getSendersOrReceivers]()
.map(({ track }) => track)
.filter(track => track && track.kind === kind);
}

/**
Expand All @@ -298,20 +292,11 @@ function getTrackStats(peerConnection, track, options = {}) {
if (typeof options.testForChrome !== 'undefined' || isChrome) {
return chromeOrSafariGetTrackStats(peerConnection, track);
}
if (typeof options.testForFirefox !== 'undefined' || isFirefox) {
if (typeof options.testForFirefox !== 'undefined' || isFirefox) {
return firefoxGetTrackStats(peerConnection, track, options.isRemote);
}
if (typeof options.testForSafari !== 'undefined' || isSafari) {
if (typeof options.testForSafari !== 'undefined' || getSdpFormat() === 'unified') {
return chromeOrSafariGetTrackStats(peerConnection, track);
}
// NOTE(syerrapragada): getStats() is not supported on
// Safari versions where plan-b is the SDP format
// due to this bug: https://bugs.webkit.org/show_bug.cgi?id=192601
return Promise.reject(new Error([
'getStats() is not supported on this version of Safari',
'due to this bug: https://bugs.webkit.org/show_bug.cgi?id=192601'
].join(' ')));
if (typeof options.testForSafari !== 'undefined' || isSafari) {
return chromeOrSafariGetTrackStats(peerConnection, track);
}
return Promise.reject(new Error('RTCPeerConnection#getStats() not supported'));
}
Expand Down
16 changes: 0 additions & 16 deletions lib/webrtc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,9 @@ Object.defineProperties(WebRTC, {
enumerable: true,
value: require('./getusermedia')
},
MediaStream: {
enumerable: true,
value: require('./mediastream')
},
MediaStreamTrack: {
enumerable: true,
value: require('./mediastreamtrack')
},
RTCIceCandidate: {
enumerable: true,
value: require('./rtcicecandidate')
},
RTCPeerConnection: {
enumerable: true,
value: require('./rtcpeerconnection')
},
RTCSessionDescription: {
enumerable: true,
value: require('./rtcsessiondescription')
}
});

Expand Down
10 changes: 0 additions & 10 deletions lib/webrtc/mediastream.js

This file was deleted.

10 changes: 0 additions & 10 deletions lib/webrtc/mediastreamtrack.js

This file was deleted.

10 changes: 0 additions & 10 deletions lib/webrtc/rtcicecandidate.js

This file was deleted.

Loading