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

Commit d7ab0bd

Browse files
authored
Setting local description is considered as negotiating. (#486)
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 943e6b4 commit d7ab0bd

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;
@@ -849,7 +859,9 @@ class P2PPeerConnectionChannel extends EventDispatcher {
849859
this._pc.createOffer().then((desc) => {
850860
desc.sdp = this._setRtpReceiverOptions(desc.sdp);
851861
if (this._pc.signalingState === 'stable') {
862+
this._settingLocalSdp = true;
852863
return this._pc.setLocalDescription(desc).then(() => {
864+
this._settingLocalSdp = false;
853865
return this._sendSdp(this._pc.localDescription);
854866
});
855867
}
@@ -867,7 +879,10 @@ class P2PPeerConnectionChannel extends EventDispatcher {
867879
this._pc.createAnswer().then((desc) => {
868880
desc.sdp = this._setRtpReceiverOptions(desc.sdp);
869881
this._logCurrentAndPendingLocalDescription();
870-
return this._pc.setLocalDescription(desc);
882+
this._settingLocalSdp = true;
883+
return this._pc.setLocalDescription(desc).then(()=>{
884+
this._settingLocalSdp = false;
885+
});
871886
}).then(()=>{
872887
return this._sendSdp(this._pc.localDescription);
873888
}).catch((e) => {

0 commit comments

Comments
 (0)