8000 Fixed a crash caused by using GetTransceivers under non-unified-plan,… · next-coder/flutter-webrtc@eb14879 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb14879

Browse files
committed
Fixed a crash caused by using GetTransceivers under non-unified-plan,close flutter-webrtc#389.
1 parent 999bb42 commit eb14879

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

android/src/main/java/com/cloudwebrtc/webrtc/MethodCallHandlerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,11 @@ private RTCConfiguration parseRTCConfiguration(ConstraintsMap map) {
916916

917917
public String peerConnectionInit(ConstraintsMap configuration, ConstraintsMap constraints) {
918918
String peerConnectionId = getNextStreamUUID();
919-
PeerConnectionObserver observer = new PeerConnectionObserver(this, messenger, peerConnectionId);
919+
RTCConfiguration conf = parseRTCConfiguration(configuration);
920+
PeerConnectionObserver observer = new PeerConnectionObserver(conf,this, messenger, peerConnectionId);
920921
PeerConnection peerConnection
921922
= mFactory.createPeerConnection(
922-
parseRTCConfiguration(configuration),
923+
conf,
923924
parseMediaConstraints(constraints),
924925
observer);
925926
observer.setPeerConnection(peerConnection);

android/src/main/java/com/cloudwebrtc/webrtc/PeerConnectionObserver.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ class PeerConnectionObserver implements PeerConnection.Observer, EventChannel.St
3838
private BinaryMessenger messenger;
3939
private final String id;
4040
private PeerConnection peerConnection;
41+
private PeerConnection.RTCConfiguration configuration;
4142
final Map<String, MediaStream> remoteStreams = new HashMap<>();
4243
final Map<String, MediaStreamTrack> remoteTracks = new HashMap<>();
4344
private final StateProvider stateProvider;
4445
private final EventChannel eventChannel;
4546
private EventChannel.EventSink eventSink;
4647

47-
PeerConnectionObserver(StateProvider stateProvider, BinaryMessenger messenger, String id) {
48+
PeerConnectionObserver(PeerConnection.RTCConfiguration configuration, StateProvider stateProvider, BinaryMessenger messenger, String id) {
49+
this.configuration = configuration;
4850
this.stateProvider = stateProvider;
4951
this.messenger = messenger;
5052
this.id = id;
@@ -430,11 +432,13 @@ public void onAddTrack(RtpReceiver receiver, MediaStream[] mediaStreams) {
430432
params.putMap("track", mediaTrackToMap(receiver.track()));
431433
params.putMap("receiver", rtpReceiverToMap(receiver));
432434

433-
List<RtpTransceiver> transceivers = peerConnection.getTransceivers();
434-
for( RtpTransceiver transceiver : transceivers ) {
435-
if(transceiver.getReceiver() != null && receiver.id().equals(transceiver.getReceiver().id())) {
436-
params.putMap("transceiver", transceiverToMap(transceiver));
437-
}
435+
if(this.configuration.sdpSemantics == PeerConnection.SdpSemantics.UNIFIED_PLAN) {
436+
List<RtpTransceiver> transceivers = peerConnection.getTransceivers();
437+
for( RtpTransceiver transceiver : transceivers ) {
438+
if(transceiver.getReceiver() != null && receiver.id().equals(transceiver.getReceiver().id())) {
439+
params.putMap("transceiver", transceiverToMap(transceiver));
440+
}
441+
}
438442
}
439443
sendEvent(params);
440444
}

common/darwin/Classes/FlutterRTCPeerConnection.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,14 @@ - (void)peerConnection:(RTCPeerConnection *)peerConnection
537537
@"streams": streams,
538538
}];
539539

540-
for(RTCRtpTransceiver *transceiver in peerConnection.transceivers) {
541-
if(transceiver.receiver != nil && [transceiver.receiver.receiverId isEqualToString:rtpReceiver.receiverId]) {
542-
[event setValue:[self transceiverToMap:transceiver] forKey:@"transceiver"];
540+
if(peerConnection.configuration.sdpSemantics == RTCSdpSemanticsUnifiedPlan) {
541+
for(RTCRtpTransceiver *transceiver in peerConnection.transceivers) {
542+
if(transceiver.receiver != nil && [transceiver.receiver.receiverId isEqualToString:rtpReceiver.receiverId]) {
543+
[event setValue:[self transceiverToMap:transceiver] forKey:@"transceiver"];
544+
}
543545
}
544546
}
547+
545548
eventSink(event);
546549
}
547550
}

0 commit comments

Comments
 (0)
0