@@ -41,6 +41,7 @@ class PeerConnectionObserver implements PeerConnection.Observer, EventChannel.St
41
41
private PeerConnection .RTCConfiguration configuration ;
42
42
final Map <String , MediaStream > remoteStreams = new HashMap <>();
43
43
final Map <String , MediaStreamTrack > remoteTracks = new HashMap <>();
44
+ final Map <String , RtpTransceiver > transceivers = new HashMap <>();
44
45
private final StateProvider stateProvider ;
45
46
private final EventChannel eventChannel ;
46
47
private EventChannel .EventSink eventSink ;
@@ -151,13 +152,16 @@ void dataChannelSend(int dataChannelId, ByteBuffer byteBuffer, Boolean isBinary)
151
152
}
152
153
153
154
RtpTransceiver getRtpTransceiverById (String id ) {
154
- List <RtpTransceiver > transceivers = peerConnection .getTransceivers ();
155
- for (RtpTransceiver transceiver : transceivers ) {
156
- if (id .equals (transceiver .getMid ())){
157
- return transceiver ;
158
- }
159
- }
160
- return null ;
155
+ RtpTransceiver transceiver = transceivers .get (id );
156
+ if (null == transceiver ) {
157
+ List <RtpTransceiver > transceivers = peerConnection .getTransceivers ();
158
+ for (RtpTransceiver t : transceivers ) {
159
+ if (id .equals (t .getMid ())){
160
+ transceiver = t ;
161
+ }
162
+ }
163
+ }
164
+ return transceiver ;
161
165
}
162
166
163
167
RtpSender getRtpSenderById (String id ) {
@@ -432,7 +436,11 @@ public void onAddTrack(RtpReceiver receiver, MediaStream[] mediaStreams) {
432
436
List <RtpTransceiver > transceivers = peerConnection .getTransceivers ();
433
437
for ( RtpTransceiver transceiver : transceivers ) {
434
438
if (transceiver .getReceiver () != null && receiver .id ().equals (transceiver .getReceiver ().id ())) {
435
- params .putMap ("transceiver" , transceiverToMap (transceiver ));
439
+ String transceiverId = transceiver .getMid ();
440
+ if (null == transceiverId ) {
441
+ transceiverId = stateProvider .getNextStreamUUID ();
442
+ }
443
+ params .putMap ("transceiver" , transceiverToMap (transceiverId , transceiver ));
436
444
}
437
445
}
438
446
}
@@ -846,10 +854,14 @@ private Map<String, Object> rtpReceiverToMap(RtpReceiver receiver){
846
854
return info .toMap ();
847
855
}
848
856
849
- Map <String , Object > transceiverToMap (RtpTransceiver transceiver ){
857
+ Map <String , Object > transceiverToMap (String transceiverId , RtpTransceiver transceiver ){
850
858
ConstraintsMap info = new ConstraintsMap ();
851
- info .putString ("transceiverId" , transceiver .getMid ());
852
- info .putString ("mid" , transceiver .getMid ());
859
+ info .putString ("transceiverId" , transceiverId );
860
+ if (transceiver .getMid () == null ) {
861
+ info .putString ("mid" , "" );
862
+ } else {
863
+ info .putString ("mid" , transceiver .getMid ());
864
+ }
853
865
info .putString ("direction" , transceiverDirectionString (transceiver .getDirection ()));
854
866
info .putMap ("sender" , rtpSenderToMap (transceiver .getSender ()));
855
867
info .putMap ("receiver" , rtpReceiverToMap (transceiver .getReceiver ()));
@@ -888,7 +900,12 @@ public void addTransceiver(MediaStreamTrack track, Map<String, Object> transceiv
888
900
} else {
889
901
transceiver = peerConnection .addTransceiver (track );
890
902
}
891
- result .success (transceiverToMap (transceiver ));
903
+ String transceiverId = transceiver .getMid ();
904
+ if (null == transceiverId ) {
905
+ transceiverId = stateProvider .getNextStreamUUID ();
906
+ }
907
+ transceivers .put (transceiverId , transceiver );
908
+ result .success (transceiverToMap (transceiverId , transceiver ));
892
909
}
893
910
894
911
public void addTransceiverOfType (String mediaType , Map <String , Object > transceiverInit , Result result ) {
@@ -898,7 +915,12 @@ public void addTransceiverOfType(String mediaType, Map<String, Object> transceiv
898
915
} else {
899
916
transceiver = peerConnection .addTransceiver (stringToMediaType (mediaType ));
900
917
}
901
- result .success (transceiverToMap (transceiver ));
918
+ String transceiverId = transceiver .getMid ();
919
+ if (null == transceiverId ) {
920
+ transceiverId = stateProvider .getNextStreamUUID ();
921
+ }
922
+ transceivers .put (transceiverId , transceiver );
923
+ result .success (transceiverToMap (transceiverId , transceiver ));
902
924
}
903
925
904
926
public void rtpTransceiverSetDirection (String direction , String transceiverId , Result result ) {
@@ -990,8 +1012,12 @@ public void getReceivers(Result result) {
990
1012
public void getTransceivers (Result result ) {
991
1013
List <RtpTransceiver > transceivers = peerConnection .getTransceivers ();
992
1014
ConstraintsArray transceiversParams = new ConstraintsArray ();
993
- for (RtpTransceiver receiver : transceivers ){
994
- transceiversParams .pushMap (new ConstraintsMap (transceiverToMap (receiver )));
1015
+ for (RtpTransceiver transceiver : transceivers ){
1016
+ String transceiverId = transceiver .getMid ();
1017
+ if (null == transceiverId ) {
1018
+ transceiverId = stateProvider .getNextStreamUUID ();
1019
+ }
1020
+ transceiversParams .pushMap (new ConstraintsMap (transceiverToMap (transceiverId , transceiver )));
995
1021
}
996
1022
ConstraintsMap params = new ConstraintsMap ();
997
1023
params .putArray ("transceivers" , transceiversParams .toArrayList ());
0 commit comments