8000 fix: Fix currentDirection/direction implementation confusion. · XuTuKe/flutter-webrtc@750141b · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 750141b

Browse files
committed
fix: Fix currentDirection/direction implementation confusion.
1 parent d9899a3 commit 750141b

File tree

6 files changed

+80
-26
lines changed

6 files changed

+80
-26
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,12 @@ public void onMethodCall(MethodCall call, @NonNull Result notSafeResult) {
602602
rtpTransceiverSetDirection(peerConnectionId, direction, transceiverId, result);
603603
break;
604604
}
605+
case "rtpTransceiverGetDirection": {
606+
String peerConnectionId = call.argument("peerConnectionId");
607+
String transceiverId = call.argument("transceiverId");
608+
rtpTransceiverGetDirection(peerConnectionId, transceiverId, result);
609+
break;
610+
}
605611
case "rtpTransceiverGetCurrentDirection": {
606612
String peerConnectionId = call.argument("peerConnectionId");
607613
String transceiverId = call.argument("transceiverId");
@@ -1582,6 +1588,15 @@ public void rtpTransceiverSetDirection(String peerConnectionId, String direction
15821588
}
15831589
}
15841590

1591+
public void rtpTransceiverGetDirection(String peerConnectionId, String transceiverId, Result result) {
1592+
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
1593+
if (pco == null || pco.getPeerConnection() == null) {
1594+
resultError("rtpTransceiverSetDirection", "peerConnection is null", result);
1595+
} else {
1596+
pco.rtpTransceiverGetDirection(transceiverId, result);
1597+
}
1598+
}
1599+
15851600
public void rtpTransceiverGetCurrentDirection(String peerConnectionId, String transceiverId, Result result) {
15861601
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
15871602
if (pco == null || pco.getPeerConnection() == null) {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,17 +933,33 @@ public void rtpTransceiverSetDirection(String direction, String transceiverId, R
933933
result.success(null);
934934
}
935935

936-
public void rtpTransceiverGetCurrentDirection(String transceiverId, Result result) {
936+
public void rtpTransceiverGetDirection(String transceiverId, Result result) {
937937
RtpTransceiver transceiver = getRtpTransceiverById(transceiverId);
938938
if (transceiver == null) {
939-
resultError("rtpTransceiverGetCurrentDirection", "transceiver is null", result);
939+
resultError("rtpTransceiverGetDirection", "transceiver is null", result);
940940
return;
941941
}
942942
ConstraintsMap params = new ConstraintsMap();
943943
params.putString("result", transceiverDirectionString(transceiver.getDirection()));
944944
result.success(params.toMap());
945945
}
946946

947+
public void rtpTransceiverGetCurrentDirection(String transceiverId, Result result) {
948+
RtpTransceiver transceiver = getRtpTransceiverById(transceiverId);
949+
if (transceiver == null) {
950+
resultError("rtpTransceiverGetCurrentDirection", "transceiver is null", result);
951+
return;
952+
}
953+
RtpTransceiver.RtpTransceiverDirection direction = transceiver.getCurrentDirection();
954+
if(direction == null) {
955+
result.success(null);
956+
} else {
957+
ConstraintsMap params = new ConstraintsMap();
958+
params.putString("result", transceiverDirectionString(direction));
959+
result.success(params.toMap());
960+
}
961+
}
962+
947963
public void rtpTransceiverStop(String transceiverId, Result result) {
948964
RtpTransceiver transceiver = getRtpTransceiverById(transceiverId);
949965
if (transceiver == null) {

common/darwin/Classes/FlutterWebRTCPlugin.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult) result
733733
[transcevier setDirection:[self stringToTransceiverDirection:direction]];
734734
#endif
735735
result(nil);
736-
} else if ([@"rtpTransceiverGetCurrentDirection" isEqualToString:call.method]){
736+
} else if ([@"rtpTransceiverGetCurrentDirection" isEqualToString:call.method] || [@"rtpTransceiverGetDirection" isEqualToString:call.method]){
737737
NSDictionary* argsMap = call.arguments;
738738
NSString* peerConnectionId = argsMap[@"peerConnectionId"];
739739
NSString* transceiverId = argsMap[@"transceiverId"];
@@ -751,7 +751,17 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult) result
751751
details:nil]);
752752
return;
753753
}
754-
result(@{@"result": [self transceiverDirectionString:transcevier.direction]});
754+
755+
if([@"rtpTransceiverGetDirection" isEqualToString:call.method]){
756+
result(@{@"result": [self transceiverDirectionString:transcevier.direction]});
757+
} else if ([@"rtpTransceiverGetCurrentDirection" isEqualToString:call.method]) {
758+
RTCRtpTransceiverDirection *directionOut = nil;
759+
if ([transcevier currentDirection:directionOut]) {
760+
result(@{@"result": [self transceiverDirectionString:*directionOut]});
761+
} else {
762+
result(nil);
763+
}
764+
}
755765
} else if ([@"rtpTransceiverStop" isEqualToString:call.method]){
756766
NSDictionary* argsMap = call.arguments;
757767
NSString* peerConnectionId = argsMap[@"peerConnectionId"];

lib/src/interface/rtc_rtp_transceiver.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ class RTCRtpTransceiverInit {
2424
abstract class RTCRtpTransceiver {
2525
RTCRtpTransceiver();
2626

27-
TransceiverDirection? get currentDirection;
27+
Future<TransceiverDirection?> getCurrentDirection();
28+
29+
Future<void> setDirection(TransceiverDirection direction);
30+
31+
Future<TransceiverDirection> getDirection();
2832

2933
String get mid;
3034

@@ -36,9 +40,10 @@ abstract class RTCRtpTransceiver {
3640

3741
String get transceiverId;
3842

39-
Future<void> setDirection(TransceiverDirection direction);
40-
41-
Future<TransceiverDirection> getCurrentDirection();
42-
4343
Future<void> stop();
44+
45+
/// Deprecated methods.
46+
@Deprecated('Use the `await getCurrentDirection` instead')
47+
TransceiverDirection get currentDirection => throw UnimplementedError(
48+
'Need to be call asynchronously from native sdk, so the method is deprecated');
4449
}

lib/src/native/rtc_rtp_transceiver_impl.dart

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ class RTCRtpTransceiverNative extends RTCRtpTransceiver {
9999
_peerConnectionId = id;
100100
}
101101

102-
@override
103-
TransceiverDirection get currentDirection => _direction;
104-
105102
@override
106103
String get mid => _mid;
107104

@@ -132,18 +129,34 @@ class RTCRtpTransceiverNative extends RTCRtpTransceiver {
132129
}
133130

134131
@override
135-
Future<TransceiverDirection> getCurrentDirection() async {
132+
Future<TransceiverDirection?> getCurrentDirection() async {
136133
try {
137134
final response = await WebRTC.invokeMethod(
138135
'rtpTransceiverGetCurrentDirection', <String, dynamic>{
139136
'peerConnectionId': _peerConnectionId,
140137
'transceiverId': _id
141138
});
139+
return response != null
140+
? typeStringToRtpTransceiverDirection[response['result']]
141+
: null;
142+
} on PlatformException catch (e) {
143+
throw 'Unable to RTCRtpTransceiver::getCurrentDirection: ${e.message}';
144+
}
145+
}
146+
147+
@override
148+
Future<TransceiverDirection> getDirection() async {
149+
try {
150+
final response = await WebRTC.invokeMethod(
151+
'rtpTransceiverGetDirection', <String, dynamic>{
152+
'peerConnectionId': _peerConnectionId,
153+
'transceiverId': _id
154+
});
142155

143156
_direction = typeStringToRtpTransceiverDirection[response['result']]!;
144157
return _direction;
145158
} on PlatformException catch (e) {
146-
throw 'Unable to RTCRtpTransceiver::getCurrentDirection: ${e.message}';
159+
throw 'Unable to RTCRtpTransceiver::getDirection: ${e.message}';
147160
}
148161
}
149162

lib/src/web/rtc_rtp_transceiver_impl.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ class RTCRtpTransceiverWeb extends RTCRtpTransceiver {
6868
Object _jsTransceiver;
6969

7070
@override
71-
TransceiverDirection? get currentDirection =>
71+
Future<TransceiverDirection?> getCurrentDirection() async =>
7272
typeStringToRtpTransceiverDirection[
73-
jsutil.getProperty(_jsTransceiver, 'direction')];
73+
jsutil.getProperty(_jsTransceiver, 'currentDirection')];
74+
75+
@override
76+
Future<TransceiverDirection> getDirection() async =>
77+
typeStringToRtpTransceiverDirection[
78+
jsutil.getProperty(_jsTransceiver, 'direction')]!;
7479

7580
@override
7681
String get mid => jsutil.getProperty(_jsTransceiver, 'mid');
@@ -99,16 +104,6 @@ class RTCRtpTransceiverWeb extends RTCRtpTransceiver {
99104
}
100105
}
101106

102-
@override
103-
Future<TransceiverDirection> getCurrentDirection() async {
104-
try {
105-
var direction = jsutil.getProperty(_jsTransceiver, 'direction');
106-
return Future.value(typeStringToRtpTransceiverDirection[direction]);
107-
} on PlatformException catch (e) {
108-
throw 'Unable to RTCRtpTransceiver::getCurrentDirection: ${e.message}';
109-
}
110-
}
111-
112107
@override
113108
Future<void> stop() async {
114109
try {

0 commit comments

Comments
 (0)
0