From 88b462432e88de3c7159edace3c7beb369598186 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Sat, 2 Apr 2022 15:09:02 +0900 Subject: [PATCH] Send DC info for syncState (#88) * dc private methods * impl * pub * id * fix test --- example/macos/Podfile.lock | 2 +- example/pubspec.lock | 6 +++--- lib/src/core/engine.dart | 27 +++++++++++++++++---------- lib/src/core/signal_client.dart | 2 ++ lib/src/extensions.dart | 7 +++++++ pubspec.lock | 8 ++++---- pubspec.yaml | 3 +-- test/mock/datachannel_mock.dart | 10 +++++++++- test/mock/peerconnection_mock.dart | 2 +- 9 files changed, 45 insertions(+), 22 deletions(-) diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index 163d334..d7bf729 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -51,4 +51,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c -COCOAPODS: 1.11.2 +COCOAPODS: 1.11.3 diff --git a/example/pubspec.lock b/example/pubspec.lock index 0009ef5..3a1c410 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -56,7 +56,7 @@ packages: name: dart_webrtc url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" device_info_plus: dependency: transitive description: @@ -176,7 +176,7 @@ packages: name: flutter_webrtc url: "https://pub.dartlang.org" source: hosted - version: "0.8.3" + version: "0.8.5" google_fonts: dependency: "direct main" description: @@ -510,7 +510,7 @@ packages: name: webrtc_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.3" win32: dependency: transitive description: diff --git a/lib/src/core/engine.dart b/lib/src/core/engine.dart index a36c89c..1553e0c 100644 --- a/lib/src/core/engine.dart +++ b/lib/src/core/engine.dart @@ -529,6 +529,7 @@ class Engine extends Disposable with EventsEmittable { answer: answer, subscription: subscription, publishTracks: publishTracks, + dataChannelInfo: dataChannelInfo(), ); } @@ -643,7 +644,16 @@ class Engine extends Disposable with EventsEmittable { ))); } -extension EngineInternalMethods on Engine { +extension EnginePrivateMethods on Engine { + // publisher data channel for the reliability + rtc.RTCDataChannel? _publisherDataChannel(Reliability reliability) => + reliability == Reliability.reliable ? _reliableDCPub : _lossyDCPub; + + // state of the publisher data channel + rtc.RTCDataChannelState _publisherDataChannelState(Reliability reliability) => + _publisherDataChannel(reliability)?.state ?? + rtc.RTCDataChannelState.RTCDataChannelClosed; + void _updateConnectionState(ConnectionState newValue) { if (_connectionState == newValue) return; @@ -664,13 +674,10 @@ extension EngineInternalMethods on Engine { } } -extension EnginePrivateMethods on Engine { - // publisher data channel for the reliability - rtc.RTCDataChannel? _publisherDataChannel(Reliability reliability) => - reliability == Reliability.reliable ? _reliableDCPub : _lossyDCPub; - - // state of the publisher data channel - rtc.RTCDataChannelState _publisherDataChannelState(Reliability reliability) => - _publisherDataChannel(reliability)?.state ?? - rtc.RTCDataChannelState.RTCDataChannelClosed; +extension EngineInternalMethods on Engine { + @internal + List dataChannelInfo() => [ + _reliableDCPub, + _lossyDCPub + ].whereNotNull().map((e) => e.toLKInfoType()).toList(); } diff --git a/lib/src/core/signal_client.dart b/lib/src/core/signal_client.dart index 55982c9..562c3c7 100644 --- a/lib/src/core/signal_client.dart +++ b/lib/src/core/signal_client.dart @@ -352,12 +352,14 @@ extension SignalClientRequests on SignalClient { required lk_rtc.SessionDescription? answer, required lk_rtc.UpdateSubscription subscription, required Iterable? publishTracks, + required Iterable? dataChannelInfo, }) => _sendRequest(lk_rtc.SignalRequest( syncState: lk_rtc.SyncState( answer: answer, subscription: subscription, publishTracks: publishTracks, + dataChannels: dataChannelInfo, ), )); diff --git a/lib/src/extensions.dart b/lib/src/extensions.dart index 2933c97..0c0f7e1 100644 --- a/lib/src/extensions.dart +++ b/lib/src/extensions.dart @@ -53,6 +53,13 @@ extension ReliabilityExt on Reliability { }[this]!; } +extension RTCDataChannelExt on rtc.RTCDataChannel { + lk_rtc.DataChannelInfo toLKInfoType() => lk_rtc.DataChannelInfo( + id: id, + label: label, + ); +} + extension RTCIceCandidateExt on rtc.RTCIceCandidate { static rtc.RTCIceCandidate fromJson(String jsonString) { final map = json.decode(jsonString) as Map; diff --git a/pubspec.lock b/pubspec.lock index 16d3641..5be13e5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -114,12 +114,12 @@ packages: source: hosted version: "2.2.1" dart_webrtc: - dependency: "direct main" + dependency: transitive description: name: dart_webrtc url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" device_info_plus: dependency: "direct main" description: @@ -218,7 +218,7 @@ packages: name: flutter_webrtc url: "https://pub.dartlang.org" source: hosted - version: "0.8.3" + version: "0.8.5" glob: dependency: transitive description: @@ -496,7 +496,7 @@ packages: name: webrtc_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.3" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 67a8590..7197b52 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,8 +22,7 @@ dependencies: uuid: ^3.0.4 synchronized: ^3.0.0 protobuf: ^2.0.1 - flutter_webrtc: ^0.8.3 - dart_webrtc: ^1.0.3 + flutter_webrtc: ^0.8.5 device_info_plus: ^3.2.1 dev_dependencies: diff --git a/test/mock/datachannel_mock.dart b/test/mock/datachannel_mock.dart index 04f346c..76e33fd 100644 --- a/test/mock/datachannel_mock.dart +++ b/test/mock/datachannel_mock.dart @@ -2,9 +2,10 @@ import 'package:flutter_webrtc/flutter_webrtc.dart'; class MockDataChannel extends RTCDataChannel { final String? _label; + final int _id; RTCDataChannelState? _state = RTCDataChannelState.RTCDataChannelOpen; - MockDataChannel(this._label); + MockDataChannel(this._id, this._label); @override String? get label => _label; @@ -20,4 +21,11 @@ class MockDataChannel extends RTCDataChannel { _state = RTCDataChannelState.RTCDataChannelClosing; _state = RTCDataChannelState.RTCDataChannelClosed; } + + @override + // TODO: implement bufferedAmount + int? get bufferedAmount => throw UnimplementedError(); + + @override + int? get id => _id; } diff --git a/test/mock/peerconnection_mock.dart b/test/mock/peerconnection_mock.dart index 0c64eaa..3d072bf 100644 --- a/test/mock/peerconnection_mock.dart +++ b/test/mock/peerconnection_mock.dart @@ -172,7 +172,7 @@ class MockPeerConnection extends RTCPeerConnection { @override Future createDataChannel( String label, RTCDataChannelInit dataChannelDict) async { - return MockDataChannel(label); + return MockDataChannel(dataChannelDict.id, label); } @override