8000 Web: `addTransceiver` bug fix (#675) · bratyslav/flutter-webrtc@0a165c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a165c6

Browse files
authored
Web: addTransceiver bug fix (flutter-webrtc#675)
* Use `track` instead of `kind` when both `track` and `kind` are set (flutter-webrtc#4) * `getSettings` for Web (flutter-webrtc#3) * Fix: init would never be `RTCRtpTransceiverInitWeb` * Clean up
1 parent bb20331 commit 0a165c6

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

lib/src/interface/rtc_rtp_parameters.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ class RTCRtpEncoding {
6060
this.ssrc,
6161
});
6262

63-
factory RTCRtpEncoding.fromMap(Map<dynamic, dynamic> map) {
64-
return RTCRtpEncoding(
63+
factory RTCRtpEncoding.fromMap(Map<dynamic, dynamic> map) => RTCRtpEncoding(
6564
rid: map['rid'],
6665
active: map['active'],
6766
maxBitrate: map['maxBitrate'],
6867
maxFramerate: map['maxFramerate'],
6968
minBitrate: map['minBitrate'],
7069
numTemporalLayers: map['numTemporalLayers'],
7170
scaleResolutionDownBy: map['scaleResolutionDownBy'],
72-
ssrc: map['ssrc']);
73-
}
71+
ssrc: map['ssrc'],
72+
);
7473

7574
/// If non-null, this represents the RID that identifies this encoding layer.
7675
/// RIDs are used to identify layers in simulcast.
@@ -102,18 +101,17 @@ class RTCRtpEncoding {
102101
/// Can't be changed between getParameters/setParameters.
103102
int? ssrc;
104103

105-
Map<String, dynamic> toMap() {
106-
return {
107-
if (rid != null) 'rid': rid,
108-
'active': active,
109-
if (maxBitrate != null) 'maxBitrate': maxBitrate,
110-
if (maxFramerate != null) 'maxFramerate': maxFramerate,
111-
if (minBitrate != null) 'minBitrate': minBitrate,
112-
'numTemporalLayers': numTemporalLayers,
113-
'scaleResolutionDownBy': scaleResolutionDownBy,
114-
if (ssrc != null) 'ssrc': ssrc,
115-
};
116-
}
104+
Map<String, dynamic> toMap() => {
105+
'active': active,
106+
if (rid != null) 'rid': rid,
107+
if (maxBitrate != null) 'maxBitrate': maxBitrate,
108+
if (maxFramerate != null) 'maxFramerate': maxFramerate,
109+
if (minBitrate != null) 'minBitrate': minBitrate,
110+
if (numTemporalLayers != null) 'numTemporalLayers': numTemporalLayers,
111+
if (scaleResolutionDownBy != null)
112+
'scaleResolutionDownBy': scaleResolutionDownBy,
113+
if (ssrc != null) 'ssrc': ssrc,
114+
};
117115
}
118116

119117
class RTCHeaderExtension {

lib/src/web/rtc_peerconnection_impl.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,15 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
386386
final jsTrack = track is MediaStreamTrackWeb ? track.jsTrack : null;
387387
final kindString = kind != null ? typeRTCRtpMediaTypetoString[kind] : null;
388388
final trackOrKind = jsTrack ?? kindString;
389-
final jsOptions = jsutil.jsify(
390-
init is RTCRtpTransceiverInitWeb ? init.toJSMap() : {},
391-
);
389+
assert(trackOrKind != null, 'track or kind must not be null');
392390

393391
final transceiver = jsutil.callMethod(
394392
_jsPc,
395393
'addTransceiver',
396-
[trackOrKind, jsOptions],
394+
[
395+
trackOrKind,
396+
if (init != null) init.toJsObject(),
397+
],
397398
);
398399

399400
return RTCRtpTransceiverWeb.fromJsObject(

lib/src/web/rtc_rtp_transceiver_impl.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ List<RTCRtpEncoding> listToRtpEncodings(List<Map<String, dynamic>> list) {
1717
return list.map((e) => RTCRtpEncoding.fromMap(e)).toList();
1818
}
1919

20+
@Deprecated('RTCRtpTransceiverInitWeb isn\'t referenced from anywhere.')
2021
class RTCRtpTransceiverInitWeb extends RTCRtpTransceiverInit {
2122
RTCRtpTransceiverInitWeb(TransceiverDirection direction,
2223
List<MediaStream> streams, List<RTCRtpEncoding> sendEncodings)
@@ -45,15 +46,17 @@ class RTCRtpTransceiverInitWeb extends RTCRtpTransceiverInit {
4546
if (sendEncodings != null)
4647
'sendEncodings': sendEncodings!.map((e) => e.toMap()).toList(),
4748
};
49+
}
4850

49-
Map<String, dynamic> toJSMap() => {
51+
extension RTCRtpTransceiverInitWebExt on RTCRtpTransceiverInit {
52+
dynamic toJsObject() => jsutil.jsify({
5053
'direction': typeRtpTransceiverDirectionToString[direction],
5154
if (streams != null)
5255
'streams':
5356
streams!.map((e) => (e as MediaStreamWeb).jsStream).toList(),
5457
if (sendEncodings != null)
5558
'sendEncodings': sendEncodings!.map((e) => e.toMap()).toList(),
56-
};
59+
});
5760
}
5861

5962
class RTCRtpTransceiverWeb extends RTCRtpTransceiver {

0 commit comments

Comments
 (0)
0