Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 1ccf904

Browse files
authored
Remove plan B support and remove some legacy API calls. (#493)
1 parent 7e50ab6 commit 1ccf904

File tree

3 files changed

+37
-66
lines changed

3 files changed

+37
-66
lines changed

src/sdk/base/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export function sysInfo() {
120120
}
121121
info.capabilities = {
122122
continualIceGathering: false,
123-
unifiedPlan: true,
124123
streamRemovable: info.runtime.name !== 'Firefox',
125124
ignoreDataChannelAcks: true,
126125
};

src/sdk/conference/channel.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,6 @@ export class ConferencePeerConnectionChannel extends EventDispatcher {
846846

847847
const pcConfiguration = this._config.rtcConfiguration || {};
848848
if (Utils.isChrome()) {
849-
pcConfiguration.sdpSemantics = 'unified-plan';
850849
pcConfiguration.bundlePolicy = 'max-bundle';
851850
}
852851
this._pc = new RTCPeerConnection(pcConfiguration);

src/sdk/p2p/peerconnection-channel.js

Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ class P2PPeerConnectionChannel extends EventDispatcher {
8585
this._publishedStreamTracks = new Map(); // Key is MediaStream's ID, value is an array of the ID of its MediaStreamTracks that haven't been removed.
8686
this._isNegotiationNeeded = false;
8787
this._remoteSideSupportsRemoveStream = true;
88-
this._remoteSideSupportsPlanB = true;
89-
this._remoteSideSupportsUnifiedPlan = true;
9088
this._remoteSideIgnoresDataChannelAcks = false;
9189
this._remoteIceCandidates = [];
9290
this._dataChannels = new Map(); // Key is data channel's label, value is a RTCDataChannel.
@@ -427,6 +425,10 @@ class P2PPeerConnectionChannel extends EventDispatcher {
427425
if (this._isPolitePeer) {
428426
Logger.debug('Rollback.');
429427
this._settingLocalSdp = true;
428+
// setLocalDescription(rollback) is not supported on Safari right now.
429+
// Test case "WebRTC collision should be resolved." is expected to fail.
430+
// See
431+
// https://wpt.fyi/results/webrtc/RTCPeerConnection-setLocalDescription-rollback.html?q=webrtc&run_id=5662062321598464&run_id=5756139520131072&run_id=5754637556645888&run_id=5764334049296384.
430432
this._pc.setLocalDescription().then(() => {
431433
this._settingLocalSdp = false;
432434
});
@@ -436,13 +438,6 @@ class P2PPeerConnectionChannel extends EventDispatcher {
436438
}
437439
}
438440
sdp.sdp = this._setRtpSenderOptions(sdp.sdp, this._config);
439-
// Firefox only has one codec in answer, which does not truly reflect its
440-
// decoding capability. So we set codec preference to remote offer, and let
441-
// Firefox choose its preferred codec.
442-
// Reference: https://bugzilla.mozilla.org/show_bug.cgi?id=814227.
443-
if (Utils.isFirefox()) {
444-
sdp.sdp = this._setCodecOrder(sdp.sdp);
445-
}
446441
const sessionDescription = new RTCSessionDescription(sdp);
447442
this._settingRemoteSdp = true;
448443
this._pc.setRemoteDescription(sessionDescription).then(() => {
@@ -654,41 +649,12 @@ class P2PPeerConnectionChannel extends EventDispatcher {
654649
stream.dispatchEvent(event);
655650
}
656651

657-
_isUnifiedPlan() {
658-
if (Utils.isFirefox()) {
659-
return true;
660-
}
661-
const pc = new RTCPeerConnection({
662-
sdpSemantics: 'unified-plan',
663-
});
664-
return (pc.getConfiguration() && pc.getConfiguration().sdpSemantics ===
665-
'plan-b');
666-
}
667-
668652
_createPeerConnection() {
669653
const pcConfiguration = this._config.rtcConfiguration || {};
670-
if (Utils.isChrome()) {
671-
pcConfiguration.sdpSemantics = 'unified-plan';
672-
}
673654
this._pc = new RTCPeerConnection(pcConfiguration);
674-
// Firefox 59 implemented addTransceiver. However, mid in SDP will differ from track's ID in this case. And transceiver's mid is null.
675-
if (typeof this._pc.addTransceiver === 'function' && Utils.isSafari()) {
676-
this._pc.addTransceiver('audio');
677-
this._pc.addTransceiver('video');
678-
}
679-
if (!this._isUnifiedPlan() && !Utils.isSafari()) {
680-
this._pc.onaddstream = (event) => {
681-
// TODO: Legacy API, should be removed when all UAs implemented WebRTC 1.0.
682-
this._onRemoteStreamAdded.apply(this, [event]);
683-
};
684-
this._pc.onremovestream = (event) => {
685-
this._onRemoteStreamRemoved.apply(this, [event]);
686-
};
687-
} else {
688-
this._pc.ontrack = (event) => {
689-
this._onRemoteTrackAdded.apply(this, [event]);
690-
};
691-
}
655+
this._pc.ontrack = (event) => {
656+
this._onRemoteTrackAdded.apply(this, [event]);
657+
};
692658
this._pc.onicecandidate = (event) => {
693659
this._onLocalIceCandidate.apply(this, [event]);
694660
};
@@ -729,15 +695,27 @@ class P2PPeerConnectionChannel extends EventDispatcher {
729695
this._publishingStreams.push(stream);
730696
}
731697
this._pendingStreams.length = 0;
732-
for (let j = 0; j < this._pendingUnpublishStreams.length; j++) {
733-
if (!this._pendingUnpublishStreams[j].mediaStream) {
698+
for (const stream of this._pendingUnpublishStreams) {
699+
if (!stream.stream) {
734700
continue;
735701
}
736-
this._pc.removeStream(this._pendingUnpublishStreams[j].mediaStream);
737-
this._unpublishPromises.get(
738-
this._pendingUnpublishStreams[j].mediaStream.id).resolve();
739-
this._publishedStreams.delete(this._pendingUnpublishStreams[j]);
740-
Logger.debug('Remove stream.');
702+
if (typeof this._pc.getSenders === 'function' &&
703+
typeof this._pc.removeTrack === 'function') {
704+
for (const sender of this._pc.getSenders()) {
705+
for (const track of stream.stream.getTracks()) {
706+
if (sender.track == track) {
707+
this._pc.removeTrack(sender);
708+
}
709+
}
710+
}
711+
} else {
712+
Logger.debug(
713+
'getSender or removeTrack is not supported, fallback to ' +
714+
'removeStream.');
715+
this._pc.removeStream(stream.stream);
716+
}
717+
this._unpublishPromises.get(stream.stream.id).resolve();
718+
this._publishedStreams.delete(stream);
741719
}
742720
this._pendingUnpublishStreams.length = 0;
743721
}
@@ -770,7 +748,7 @@ class P2PPeerConnectionChannel extends EventDispatcher {
770748
}
771749
}
772750
this._pendingMessages.length = 0;
773-
} else if (this._pc && !dc) {
751+
} else if (this._pc && this._pc.connectionState !== 'closed' && !dc) {
774752
this._createDataChannel(DataChannelLabel.MESSAGE);
775753
}
776754
}
@@ -804,12 +782,8 @@ class P2PPeerConnectionChannel extends EventDispatcher {
804782
if (ua.sdk && ua.sdk && ua.sdk.type === 'JavaScript' && ua.runtime &&
805783
ua.runtime.name === 'Firefox') {
806784
this._remoteSideSupportsRemoveStream = false;
807-
this._remoteSideSupportsPlanB = false;
808-
this._remoteSideSupportsUnifiedPlan = true;
809785
} else { // Remote side is iOS/Android/C++ which uses Google's WebRTC stack.
810786
this._remoteSideSupportsRemoveStream = true;
811-
this._remoteSideSupportsPlanB = true;
812-
this._remoteSideSupportsUnifiedPlan = false;
813787
}
814788
if (ua.capabilities) {
815789
this._remoteSideIgnoresDataChannelAcks =
@@ -863,7 +837,8 @@ class P2PPeerConnectionChannel extends EventDispatcher {
863837
this._isNegotiationNeeded = false;
864838
this._pc.createOffer().then((desc) => {
865839
desc.sdp = this._setRtpReceiverOptions(desc.sdp);
866-
if (this._pc.signalingState === 'stable') {
840+
if (this._pc.signalingState === 'stable' && !this._settingLocalSdp &&
841+
!this._settingRemoteSdp) {
867842
this._settingLocalSdp = true;
868843
return this._pc.setLocalDescription(desc).then(() => {
869844
this._settingLocalSdp = false;
@@ -1076,17 +1051,15 @@ class P2PPeerConnectionChannel extends EventDispatcher {
10761051
const streamEvent = new StreamModule.StreamEvent('streamadded', {
10771052
stream: info.stream,
10781053
});
1079-
if (this._isUnifiedPlan()) {
1080-
for (const track of info.mediaStream.getTracks()) {
1081-
track.addEventListener('ended', (event) => {
1082-
const mediaStreams = this._getStreamByTrack(event.target);
1083-
for (const mediaStream of mediaStreams) {
1084-
if (this._areAllTracksEnded(mediaStream)) {
1085-
this._onRemoteStreamRemoved({stream: mediaStream});
1086-
}
1054+
for (const track of info.mediaStream.getTracks()) {
1055+
track.addEventListener('ended', (event) => {
1056+
const mediaStreams = this._getStreamByTrack(event.target);
1057+
for (const mediaStream of mediaStreams) {
1058+
if (this._areAllTracksEnded(mediaStream)) {
1059+
this._onRemoteStreamRemoved({stream: mediaStream});
10871060
}
1088-
});
1089-
}
1061+
}
1062+
});
10901063
}
10911064
this._sendSignalingMessage(SignalingType.TRACKS_ADDED, info.trackIds);
10921065
this._remoteStreamInfo.get(info.mediaStream.id).mediaStream = null;

0 commit comments

Comments
 (0)