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

Commit fe6a2b9

Browse files
committed
Don't set remote description when a setLocalDescription is not resolved.
When the impolite side receives offer after `setLocalDescription`, before it's resolved, it sets both local description and remote description. Its signaling state changes from stable to have-local-offer, to stable, to have-remote-offer. It doesn't comply with the behavior of impolite side described in perfect negotiation, which is ignoring the remote description. Test: P2P case WebRTC collision should be resolved.
1 parent a83fa5c commit fe6a2b9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/sdk/p2p/peerconnection-channel.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class P2PPeerConnectionChannel extends EventDispatcher {
9696
this._sendDataPromises = new Map(); // Key is data sequence number, value is an object has |resolve| and |reject|.
9797
this._addedTrackIds = []; // Tracks that have been added after receiving remote SDP but before connection is established. Draining these messages when ICE connection state is connected.
9898
this._isPolitePeer = localId < remoteId;
99+
this._settingLocalSdp = false;
100+
this._settingRemoteSdp = false;
99101
this._disposed = false;
100102
this._createPeerConnection();
101103
this._sendSignalingMessage(SignalingType.UA, sysInfo);
@@ -416,10 +418,13 @@ class P2PPeerConnectionChannel extends EventDispatcher {
416418
_onOffer(sdp) {
417419
Logger.debug('About to set remote description. Signaling state: ' +
418420
this._pc.signalingState);
419-
if (this._pc.signalingState !== 'stable') {
421+
if (this._pc.signalingState !== 'stable' || this._settingLocalSdp) {
420422
if (this._isPolitePeer) {
421423
Logger.debug('Rollback.');
422-
this._pc.setLocalDescription();
424+
this._settingLocalSdp = true;
425+
this._pc.setLocalDescription().then(() => {
426+
this._settingLocalSdp = false;
427+
});
423428
} else {
424429
Logger.debug('Collision detected. Ignore this offer.');
425430
return;
@@ -434,7 +439,9 @@ class P2PPeerConnectionChannel extends EventDispatcher {
434439
sdp.sdp = this._setCodecOrder(sdp.sdp);
435440
}
436441
const sessionDescription = new RTCSessionDescription(sdp);
442+
this._settingRemoteSdp = true;
437443
this._pc.setRemoteDescription(sessionDescription).then(() => {
444+
this._settingRemoteSdp = false;
438445
this._createAndSendAnswer();
439446
}, (error) => {
440447
Logger.debug('Set remote description failed. Message: ' + error.message);
@@ -447,9 +454,11 @@ class P2PPeerConnectionChannel extends EventDispatcher {
447454
this._pc.signalingState);
448455
sdp.sdp = this._setRtpSenderOptions(sdp.sdp, this._config);
449456
const sessionDescription = new RTCSessionDescription(sdp);
457+
this._settingRemoteSdp = true;
450458
this._pc.setRemoteDescription(new RTCSessionDescription(
451459
sessionDescription)).then(() => {
452460
Logger.debug('Set remote descripiton successfully.');
461+
this._settingRemoteSdp = false;
453462
this._drainPendingMessages();
454463
}, (error) => {
455464
Logger.debug('Set remote description failed. Message: ' + error.message);
@@ -548,7 +557,8 @@ class P2PPeerConnectionChannel extends EventDispatcher {
548557
}
549558

550559
_onNegotiationneeded() {
551-
if (this._pc.signalingState === 'stable') {
560+
if (this._pc.signalingState === 'stable' && !this._pc._settingLocalSdp &&
561+
!this._settingRemoteSdp) {
552562
this._doNegotiate();
553563
} else {
554564
this._isNegotiationNeeded = true;
@@ -851,7 +861,9 @@ class P2PPeerConnectionChannel extends EventDispatcher {
851861
desc.sdp = this._setRtpReceiverOptions(desc.sdp);
852862
localDesc = desc;
853863
if (this._pc.signalingState === 'stable') {
864+
this._settingLocalSdp = true;
854865
return this._pc.setLocalDescription(desc).then(() => {
866+
this._settingLocalSdp = false;
855867
return this._sendSdp(localDesc);
856868
});
857869
}
@@ -871,7 +883,10 @@ class P2PPeerConnectionChannel extends EventDispatcher {
871883
desc.sdp = this._setRtpReceiverOptions(desc.sdp);
872884
localDesc=desc;
873885
this._logCurrentAndPendingLocalDescription();
874-
return this._pc.setLocalDescription(desc);
886+
this._settingLocalSdp = true;
887+
return this._pc.setLocalDescription(desc).then(()=>{
888+
this._settingLocalSdp = false;
889+
});
875890
}).then(()=>{
876891
return this._sendSdp(localDesc);
877892
}).catch((e) => {

0 commit comments

Comments
 (0)