Skip to content

Commit

Permalink
ios,android: fix sLD / sRD rollback
Browse files Browse the repository at this point in the history
Fixes: #1223
  • Loading branch information
saghul committed Nov 22, 2022
1 parent a58dcfb commit 0247841
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
22 changes: 16 additions & 6 deletions android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -995,11 +995,16 @@ public void onCreateSuccess(SessionDescription sdp) {

@Override
public void onSetSuccess() {
SessionDescription newSdp = peerConnection.getLocalDescription();
WritableMap newSdpMap = Arguments.createMap();
WritableMap params = Arguments.createMap();
newSdpMap.putString("type", newSdp.type.canonicalForm());
newSdpMap.putString("sdp", newSdp.description);

SessionDescription newSdp = peerConnection.getLocalDescription();
// Can happen when doing a rollback.
if (newSdp != null) {
newSdpMap.putString("type", newSdp.type.canonicalForm());
newSdpMap.putString("sdp", newSdp.description);
}

params.putMap("sdpInfo", newSdpMap);
params.putArray("transceiversInfo", getTransceiversInfo(pcId));
promise.resolve(params);
Expand Down Expand Up @@ -1058,11 +1063,16 @@ public void onCreateSuccess(final SessionDescription sdp) {

@Override
public void onSetSuccess() {
SessionDescription newSdp = peerConnection.getRemoteDescription();
WritableMap newSdpMap = Arguments.createMap();
WritableMap params = Arguments.createMap();
newSdpMap.putString("type", newSdp.type.canonicalForm());
newSdpMap.putString("sdp", newSdp.description);

SessionDescription newSdp = peerConnection.getRemoteDescription();
// Be defensive for the rollback cases.
if (newSdp != null) {
newSdpMap.putString("type", newSdp.type.canonicalForm());
newSdpMap.putString("sdp", newSdp.description);
}

params.putArray("transceiversInfo", getTransceiversInfo(id));
params.putMap("sdpInfo", newSdpMap);

Expand Down
31 changes: 19 additions & 12 deletions ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,17 @@ @implementation WebRTCModule (RTCPeerConnection)
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
} else {
RTCPeerConnection *strongPc = weakPc;
id newSdp = @{

@"sdpInfo": @{@"type": [RTCSessionDescription stringForType:strongPc.localDescription.type],
@"sdp": strongPc.localDescription.sdp
},
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
RTCSessionDescription *localDesc = strongPc.localDescription;
if (localDesc) {
sdpInfo[@"type"] = [RTCSessionDescription stringForType:localDesc.type];
sdpInfo[@"sdp"] = localDesc.sdp;
}
id data = @{
@"sdpInfo": sdpInfo,
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID]
};
resolve(newSdp);
resolve(data);
}
};

Expand Down Expand Up @@ -262,15 +265,19 @@ @implementation WebRTCModule (RTCPeerConnection)
[newTransceivers addObject:newTransceiver];
}
}

id newSdp = @{
@"sdpInfo": @{
@"type": [RTCSessionDescription stringForType:peerConnection.remoteDescription.type],
@"sdp": peerConnection.remoteDescription.sdp},

NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
RTCSessionDescription *remoteDesc = peerConnection.remoteDescription;
if (remoteDesc) {
sdpInfo[@"type"] = [RTCSessionDescription stringForType:remoteDesc.type];
sdpInfo[@"sdp"] = remoteDesc.sdp;
}
id data = @{
@"sdpInfo": sdpInfo,
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID],
@"newTransceivers": newTransceivers
};
callback(@[@(YES), newSdp]);
callback(@[@(YES), data]);
}
}];
}
Expand Down
23 changes: 19 additions & 4 deletions src/RTCPeerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
transceiversInfo
} = await WebRTCModule.peerConnectionSetLocalDescription(this._pcId, desc);

this.localDescription = new RTCSessionDescription(sdpInfo);
if (sdpInfo.type && sdpInfo.sdp) {
this.localDescription = new RTCSessionDescription(sdpInfo);
} else {
this.localDescription = null;
}

this._updateTransceivers(transceiversInfo);

log.debug(`${this._pcId} setLocalDescription OK`);
Expand Down Expand Up @@ -186,9 +191,19 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
if (successful) {
log.debug(`${this._pcId} setRemoteDescription OK`);

this.remoteDescription = new RTCSessionDescription(data.sdpInfo);
const {
sdpInfo,
newTransceivers,
transceiversInfo
} = data;

data.newTransceivers?.forEach( t => {
if (sdpInfo.type && sdpInfo.sdp) {
this.remoteDescription = new RTCSessionDescription(sdpInfo);
} else {
this.remoteDescription = null;
}

newTransceivers?.forEach( t => {
const { transceiverOrder, transceiver } = t;
const newSender = new RTCRtpSender(transceiver.sender);
const newReceiver = new RTCRtpReceiver(transceiver.receiver);
Expand All @@ -201,7 +216,7 @@ export default class RTCPeerConnection extends defineCustomEventTarget(...PEER_C
this._insertTransceiverSorted(transceiverOrder, newTransceiver);
});

this._updateTransceivers(data.transceiversInfo);
this._updateTransceivers(transceiversInfo);

resolve();
} else {
Expand Down

0 comments on commit 0247841

Please sign in to comment.