8000 mid, transceiverId nullable · minorlab/flutter-webrtc@633d72e · GitHub
[go: up one dir, main page]

Skip to content

Commit 633d72e

Browse files
committed
mid, transceiverId nullable
1 parent 364753d commit 633d72e

File tree

3 files changed

+36
-81
lines changed

3 files changed

+36
-81
lines changed

lib/src/interface/rtc_rtp_transceiver.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ abstract class RTCRtpTransceiver {
2626

2727
TransceiverDirection? get currentDirection;
2828

29-
String get mid;
29+
String? get mid;
3030

3131
RTCRtpSender get sender;
3232

3333
RTCRtpReceiver get receiver;
3434

3535
bool get stoped;
3636

37-
String get transceiverId;
37+
String? get transceiverId;
3838

3939
Future<void> setDirection(TransceiverDirection direction);
4040

lib/src/native/rtc_rtp_transceiver_impl.dart

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,27 @@ List<RTCRtpEncoding> listToRtpEncodings(List<Map<String, dynamic>> list) {
1818
}
1919

2020
class RTCRtpTransceiverInitNative extends RTCRtpTransceiverInit {
21-
RTCRtpTransceiverInitNative(TransceiverDirection direction,
22-
List<MediaStream> streams, List<RTCRtpEncoding> sendEncodings)
23-
: super(
24-
direction: direction,
25-
streams: streams,
26-
sendEncodings: sendEncodings);
21+
RTCRtpTransceiverInitNative(TransceiverDirection direction, List<MediaStream> streams, List<RTCRtpEncoding> sendEncodings)
22+
: super(direction: direction, streams: streams, sendEncodings: sendEncodings);
2723

2824
factory RTCRtpTransceiverInitNative.fromMap(Map<dynamic, dynamic> map) {
29-
return RTCRtpTransceiverInitNative(
30-
typeStringToRtpTransceiverDirection[map['direction']]!,
31-
(map['streams'] as List<dynamic>)
32-
.map((e) => MediaStreamNative.fromMap(map))
33-
.toList(),
34-
listToRtpEncodings(map['sendEncodings']));
25+
return RTCRtpTransceiverInitNative(typeStringToRtpTransceiverDirection[map['direction']]!,
26+
(map['streams'] as List<dynamic>).map((e) => MediaStreamNative.fromMap(map)).toList(), listToRtpEncodings(map['sendEncodings']));
3527
}
3628

3729
Map<String, dynamic> toMap() {
3830
return {
3931
'direction': typeRtpTransceiverDirectionToString[direction],
4032
if (streams != null) 'streamIds': streams!.map((e) => e.id).toList(),
41-
if (sendEncodings != null)
42-
'sendEncodings': sendEncodings!.map((e) => e.toMap()).toList(),
33+
if (sendEncodings != null) 'sendEncodings': sendEncodings!.map((e) => e.toMap()).toList(),
4334
};
4435
}
4536

4637
static Map<String, dynamic> initToMap(RTCRtpTransceiverInit init) {
4738
return {
4839
'direction': typeRtpTransceiverDirectionToString[init.direction],
49-
if (init.streams != null)
50-
'streamIds': init.streams!.map((e) => e.id).toList(),
51-
if (init.sendEncodings != null)
52-
'sendEncodings': init.sendEncodings!.map((e) => e.toMap()).toList(),
40+
if (init.streams != null) 'streamIds': init.streams!.map((e) => e.id).toList(),
41+
if (init.sendEncodings != null) 'sendEncodings': init.sendEncodings!.map((e) => e.toMap()).toList(),
5342
};
5443
}
5544
}
@@ -64,34 +53,27 @@ class RTCRtpTransceiverNative extends RTCRtpTransceiver {
6453
this._peerConnectionId,
6554
);
6655

67-
factory RTCRtpTransceiverNative.fromMap(Map<dynamic, dynamic> map,
68-
{required String peerConnectionId}) {
56+
factory RTCRtpTransceiverNative.fromMap(Map<dynamic, dynamic> map, {required String peerConnectionId}) {
6957
var transceiver = RTCRtpTransceiverNative(
7058
map['transceiverId'],
7159
typeStringToRtpTransceiverDirection[map['direction']]!,
7260
map['mid'],
73-
RTCRtpSenderNative.fromMap(map['sender'],
74-
peerConnectionId: peerConnectionId),
75-
RTCRtpReceiverNative.fromMap(map['receiver'],
76-
peerConnectionId: peerConnectionId),
61+
RTCRtpSenderNative.fromMap(map['sender'], peerConnectionId: peerConnectionId),
62+
RTCRtpReceiverNative.fromMap(map['receiver'], peerConnectionId: peerConnectionId),
7763
peerConnectionId);
7864
return transceiver;
7965
}
8066

81-
static List<RTCRtpTransceiverNative> fromMaps(List<dynamic> map,
82-
{required String peerConnectionId}) {
83-
return map
84-
.map((e) => RTCRtpTransceiverNative.fromMap(e,
85-
peerConnectionId: peerConnectionId))
86-
.toList();
67+
static List<RTCRtpTransceiverNative> fromMaps(List<dynamic> map, {required String peerConnectionId}) {
68+
return map.map((e) => RTCRtpTransceiverNative.fromMap(e, peerConnectionId: peerConnectionId)).toList();
8769
}
8870

8971
final MethodChannel _channel = WebRTC.methodChannel();
9072
String _peerConnectionId;
91-
String _id;
73+
String? _id;
9274
bool _stop = false;
9375
TransceiverDirection _direction;
94-
String _mid;
76+
String? _mid;
9577
RTCRtpSender _sender;
9678
RTCRtpReceiver _receiver;
9779

@@ -103,7 +85,7 @@ class RTCRtpTransceiverNative extends RTCRtpTransceiver {
10385
TransceiverDirection get currentDirection => _direction;
10486

10587
@override
106-
String get mid => _mid;
88+
String? get mid => _mid;
10789

10890
@override
10991
RTCRtpSender get sender => _sender;
@@ -115,17 +97,13 @@ class RTCRtpTransceiverNative extends RTCRtpTransceiver {
11597
bool get stoped => _stop;
11698

11799
@override
118-
String get transceiverId => _id;
100+
String? get transceiverId => _id;
119101

120102
@override
121103
Future<void> setDirection(TransceiverDirection direction) async {
122104
try {
123-
await _channel
124-
.invokeMethod('rtpTransceiverSetDirection', <String, dynamic>{
125-
'peerConnectionId': _peerConnectionId,
126-
'transceiverId': _id,
127-
'direction': typeRtpTransceiverDirectionToString[direction]
128-
});
105+
await _channel.invokeMethod('rtpTransceiverSetDirection',
106+
<String, dynamic>{'peerConnectionId': _peerConnectionId, 'transceiverId': _id, 'direction': typeRtpTransceiverDirectionToString[direction]});
129107
} on PlatformException catch (e) {
130108
throw 'Unable to RTCRtpTransceiver::setDirection: ${e.message}';
131109
}
@@ -134,11 +112,8 @@ class RTCRtpTransceiverNative extends RTCRtpTransceiver {
134112
@override
135113
Future<TransceiverDirection> getCurrentDirection() async {
136114
try {
137-
final response = await WebRTC.invokeMethod(
138-
'rtpTransceiverGetCurrentDirection', <String, dynamic>{
139-
'peerConnectionId': _peerConnectionId,
140-
'transceiverId': _id
141-
});
115+
final response =
116+
await WebRTC.invokeMethod('rtpTransceiverGetCurrentDirection', <String, dynamic>{'peerConnectionId': _peerConnectionId, 'transceiverId': _id});
142117

143118
_direction = typeStringToRtpTransceiverDirection[response['result']]!;
144119
return _direction;
@@ -150,10 +125,7 @@ class RTCRtpTransceiverNative extends RTCRtpTransceiver {
150125
@override
151126
Future<void> stop() async {
152127
try {
153-
await _channel.invokeMethod('rtpTransceiverStop', <String, dynamic>{
154-
'peerConnectionId': _peerConnectionId,
155-
'transceiverId': _id
156-
});
128+
await _channel.invokeMethod('rtpTransceiverStop', <String, dynamic>{'peerConnectionId': _peerConnectionId, 'transceiverId': _id});
157129

158130
_stop = true;
159131
} on PlatformException catch (e) {

lib/src/web/rtc_rtp_transceiver_impl.dart

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ List<RTCRtpEncoding> listToRtpEncodings(List<Map<String, dynamic>> list) {
1818
}
1919

2020
class RTCRtpTransceiverInitWeb extends RTCRtpTransceiverInit {
21-
RTCRtpTransceiverInitWeb(TransceiverDirection direction,
22-
List<MediaStream> streams, List<RTCRtpEncoding> sendEncodings)
23-
: super(
24-
direction: direction,
25-
streams: streams,
26-
sendEncodings: sendEncodings);
21+
RTCRtpTransceiverInitWeb(TransceiverDirection direction, List<MediaStream> streams, List<RTCRtpEncoding> sendEncodings)
22+
: super(direction: direction, streams: streams, sendEncodings: sendEncodings);
2723

2824
factory RTCRtpTransceiverInitWeb.fromMap(Map<dynamic, dynamic> map) {
2925
if (map['direction'] == null) {
@@ -33,72 +29,59 @@ class RTCRtpTransceiverInitWeb extends RTCRtpTransceiverInit {
3329
throw Exception('You must provide the streams');
3430
}
3531

36-
return RTCRtpTransceiverInitWeb(
37-
typeStringToRtpTransceiverDirection[map['direction']]!,
38-
(map['streams'] as List<MediaStream>).map((e) => e).toList(),
32+
return RTCRtpTransceiverInitWeb(typeStringToRtpTransceiverDirection[map['direction']]!, (map['streams'] as List<MediaStream>).map((e) => e).toList(),
3933
listToRtpEncodings(map['sendEncodings']));
4034
}
4135

4236
Map<String, dynamic> toMap() {
4337
return {
4438
'direction': typeRtpTransceiverDirectionToString[direction],
4539
if (streams != null) 'streamIds': streams!.map((e) => e.id).toList(),
46-
if (sendEncodings != null)
47-
'sendEncodings': sendEncodings!.map((e) => e.toMap()).toList(),
40+
if (sendEncodings != null) 'sendEncodings': sendEncodings!.map((e) => e.toMap()).toList(),
4841
};
4942
}
5043

5144
static Map<String, dynamic> initToMap(RTCRtpTransceiverInit init) {
5245
return {
5346
'direction': typeRtpTransceiverDirectionToString[init.direction],
54-
'streams': init.streams != null
55-
? init.streams!.map((e) => (e as MediaStreamWeb).jsStream).toList()
56-
: [],
57-
'sendEncodings': init.sendEncodings != null
58-
? init.sendEncodings!.map((e) => e.toMap()).toList()
59-
: [],
47+
'streams': init.streams != null ? init.streams!.map((e) => (e as MediaStreamWeb).jsStream).toList() : [],
48+
'sendEncodings': init.sendEncodings != null ? init.sendEncodings!.map((e) => e.toMap()).toList() : [],
6049
};
6150
}
6251
}
6352

6453
class RTCRtpTransceiverWeb extends RTCRtpTransceiver {
6554
RTCRtpTransceiverWeb(this._jsTransceiver, _peerConnectionId);
6655

67-
factory RTCRtpTransceiverWeb.fromJsObject(Object jsTransceiver,
68-
{String? peerConnectionId}) {
56+
factory RTCRtpTransceiverWeb.fromJsObject(Object jsTransceiver, {String? peerConnectionId}) {
6957
var transceiver = RTCRtpTransceiverWeb(jsTransceiver, peerConnectionId);
7058
return transceiver;
7159
}
7260

7361
Object _jsTransceiver;
7462

7563
@override
76-
TransceiverDirection? get currentDirection =>
77-
typeStringToRtpTransceiverDirection[
78-
jsutil.getProperty(_jsTransceiver, 'direction')];
64+
TransceiverDirection? get currentDirection => typeStringToRtpTransceiverDirection[jsutil.getProperty(_jsTransceiver, 'direction')];
7965

8066
@override
81-
String get mid => jsutil.getProperty(_jsTransceiver, 'mid');
67+
String? get mid => jsutil.getProperty(_jsTransceiver, 'mid');
8268

8369
@override
84-
RTCRtpSender get sender => RTCRtpSenderWeb.fromJsSender(
85-
jsutil.getProperty(_jsTransceiver, 'sender'));
70+
RTCRtpSender get sender => RTCRtpSenderWeb.fromJsSender(jsutil.getProperty(_jsTransceiver, 'sender'));
8671

8772
@override
88-
RTCRtpReceiver get receiver =>
89-
RTCRtpReceiverWeb(jsutil.getProperty(_jsTransceiver, 'receiver'));
73+
RTCRtpReceiver get receiver => RTCRtpReceiverWeb(jsutil.getProperty(_jsTransceiver, 'receiver'));
9074

9175
@override
9276
bool get stoped => jsutil.getProperty(_jsTransceiver, 'stopped');
9377

9478
@override
95-
String get transceiverId => mid;
79+
String? get transceiverId => mid;
9680

9781
@override
9882
Future<void> setDirection(TransceiverDirection direction) async {
9983
try {
100-
jsutil.setProperty(_jsTransceiver, 'direction',
101-
typeRtpTransceiverDirectionToString[direction]);
84+
jsutil.setProperty(_jsTransceiver, 'direction', typeRtpTransceiverDirectionToString[direction]);
10285
} on PlatformException catch (e) {
10386
throw 'Unable to RTCRtpTransceiver::setDirection: ${e.message}';
10487
}

0 commit comments

Comments
 (0)
0