From 6e196692bc2e40d878a522df7c8df5a0ae05f768 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Tue, 9 Apr 2024 08:17:08 +0800 Subject: [PATCH 1/2] fix data channel init error. --- lib/src/rtc_peerconnection_impl.dart | 36 ++++++++++++++++++---------- web/main.dart | 12 +++++++--- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/src/rtc_peerconnection_impl.dart b/lib/src/rtc_peerconnection_impl.dart index 17e6f04..d57a661 100644 --- a/lib/src/rtc_peerconnection_impl.dart +++ b/lib/src/rtc_peerconnection_impl.dart @@ -8,9 +8,7 @@ import 'package:dart_webrtc/dart_webrtc.dart'; import 'package:js/js_util.dart'; import 'package:platform_detect/platform_detect.dart'; import 'package:web/web.dart' as web; -import 'package:webrtc_interface/webrtc_interface.dart'; -import 'media_stream_impl.dart'; import 'media_stream_track_impl.dart'; import 'rtc_data_channel_impl.dart'; import 'rtc_dtmf_sender_impl.dart'; @@ -18,6 +16,10 @@ import 'rtc_rtp_receiver_impl.dart'; import 'rtc_rtp_sender_impl.dart'; import 'rtc_rtp_transceiver_impl.dart'; +extension on web.RTCDataChannelInit { + external set binaryType(String value); +} + /* * PeerConnection */ @@ -395,21 +397,29 @@ class RTCPeerConnectionWeb extends RTCPeerConnection { @override Future createDataChannel( String label, RTCDataChannelInit dataChannelDict) { - final map = dataChannelDict.toMap(); + var dcInit = web.RTCDataChannelInit( + id: dataChannelDict.id, + ordered: dataChannelDict.ordered, + protocol: dataChannelDict.protocol, + negotiated: dataChannelDict.negotiated, + ); + if (dataChannelDict.binaryType == 'binary') { - map['binaryType'] = 'arraybuffer'; // Avoid Blob in data channel + dcInit.binaryType = 'arraybuffer'; // Avoid Blob in data channel + } + + if (dataChannelDict.maxRetransmits > 0) { + dcInit.maxRetransmits = dataChannelDict.maxRetransmits; + } + + if (dataChannelDict.maxRetransmitTime > 0) { + dcInit.maxPacketLifeTime = dataChannelDict.maxRetransmitTime; } final jsDc = _jsPc.createDataChannel( - label, - web.RTCDataChannelInit( - id: map['id'], - ordered: map['ordered'], - maxPacketLifeTime: map['maxPacketLifeTime'], - maxRetransmits: map['maxRetransmits'], - protocol: map['protocol'], - negotiated: map['negotiated'], - )); + label, + dcInit, + ); return Future.value(RTCDataChannelWeb(jsDc)); } diff --git a/web/main.dart b/web/main.dart index 4bbed71..dd071fb 100644 --- a/web/main.dart +++ b/web/main.dart @@ -76,7 +76,7 @@ void loopBackTest() async { algorithm: Algorithm.kAesGcm, keyProvider: keyProvider); if (keyProviderOptions.discardFrameWhenCryptorNotReady) { - Timer(Duration(seconds: 2), () { + Timer(Duration(seconds: 1), () { fc.setEnabled(true); }); } else { @@ -84,7 +84,9 @@ void loopBackTest() async { } await fc.setKeyIndex(0); - await fc.updateCodec('vp8'); + if (event.track.kind == 'video') { + await fc.updateCodec('vp8'); + } pc2FrameCryptors.add(fc); }; pc2.onConnectionState = (state) { @@ -138,7 +140,9 @@ void loopBackTest() async { keyProvider: keyProvider); await fc.setEnabled(true); await fc.setKeyIndex(0); - await fc.updateCodec('vp8'); + if (track.kind == 'video') { + await fc.updateCodec('vp8'); + } pc1FrameCryptors.add(fc); }); /* @@ -163,6 +167,8 @@ void loopBackTest() async { } }); */ + var dc = await pc1.createDataChannel( + 'label', RTCDataChannelInit()..binaryType = 'binary'); var offer = await pc1.createOffer(); await pc2.addTransceiver( From dd7c8ba491f1351c44a5d39820b2a19004215719 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Tue, 9 Apr 2024 08:18:26 +0800 Subject: [PATCH 2/2] bump version. --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 525d560..3d517ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog -------------------------------------------- +[1.3.2] - 2024-04-09 + +* Fix error when constructing RTCDataChannelInit. + [1.3.1] - 2024-04-08 * Add keyRingSize/discardFrameWhenCryptorNotReady to KeyProviderOptions. diff --git a/pubspec.yaml b/pubspec.yaml index 1f37dd0..aa8a061 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dart_webrtc description: Use the dart/js library to re-wrap the webrtc js interface of the browser, to adapted common browsers. -version: 1.3.1 +version: 1.3.2 homepage: https://github.com/flutter-webrtc/dart-webrtc environment: