Skip to content

Commit

Permalink
Merge pull request #31 from flutter-webrtc/fix/dc-init-error
Browse files Browse the repository at this point in the history
Fix/dc init error
  • Loading branch information
cloudwebrtc authored Apr 9, 2024
2 parents 8aa3647 + dd7c8ba commit a3edbd5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
36 changes: 23 additions & 13 deletions lib/src/rtc_peerconnection_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ 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';
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
*/
Expand Down Expand Up @@ -395,21 +397,29 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
@override
Future<RTCDataChannel> 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));
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
12 changes: 9 additions & 3 deletions web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ void loopBackTest() async {
algorithm: Algorithm.kAesGcm,
keyProvider: keyProvider);
if (keyProviderOptions.discardFrameWhenCryptorNotReady) {
Timer(Duration(seconds: 2), () {
Timer(Duration(seconds: 1), () {
fc.setEnabled(true);
});
} else {
await fc.setEnabled(true);
}

await fc.setKeyIndex(0);
await fc.updateCodec('vp8');
if (event.track.kind == 'video') {
await fc.updateCodec('vp8');
}
pc2FrameCryptors.add(fc);
};
pc2.onConnectionState = (state) {
Expand Down Expand Up @@ -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);
});
/*
Expand All @@ -163,6 +167,8 @@ void loopBackTest() async {
}
});
*/
var dc = await pc1.createDataChannel(
'label', RTCDataChannelInit()..binaryType = 'binary');
var offer = await pc1.createOffer();

await pc2.addTransceiver(
Expand Down

0 comments on commit a3edbd5

Please sign in to comment.