Skip to content

Commit

Permalink
Send DC info for syncState (livekit#88)
Browse files Browse the repository at this point in the history
* dc private methods

* impl

* pub

* id

* fix test
  • Loading branch information
hiroshihorie authored Apr 2, 2022
1 parent e733317 commit 88b4624
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 22 deletions.
2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
27 changes: 17 additions & 10 deletions lib/src/core/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
answer: answer,
subscription: subscription,
publishTracks: publishTracks,
dataChannelInfo: dataChannelInfo(),
);
}

Expand Down Expand Up @@ -643,7 +644,16 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
)));
}

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;

Expand All @@ -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<lk_rtc.DataChannelInfo> dataChannelInfo() => [
_reliableDCPub,
_lossyDCPub
].whereNotNull().map((e) => e.toLKInfoType()).toList();
}
2 changes: 2 additions & 0 deletions lib/src/core/signal_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,14 @@ extension SignalClientRequests on SignalClient {
required lk_rtc.SessionDescription? answer,
required lk_rtc.UpdateSubscription subscription,
required Iterable<lk_rtc.TrackPublishedResponse>? publishTracks,
required Iterable<lk_rtc.DataChannelInfo>? dataChannelInfo,
}) =>
_sendRequest(lk_rtc.SignalRequest(
syncState: lk_rtc.SyncState(
answer: answer,
subscription: subscription,
publishTracks: publishTracks,
dataChannels: dataChannelInfo,
),
));

Expand Down
7 changes: 7 additions & 0 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic>;
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion test/mock/datachannel_mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion test/mock/peerconnection_mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class MockPeerConnection extends RTCPeerConnection {
@override
Future<RTCDataChannel> createDataChannel(
String label, RTCDataChannelInit dataChannelDict) async {
return MockDataChannel(label);
return MockDataChannel(dataChannelDict.id, label);
}

@override
Expand Down

0 comments on commit 88b4624

Please sign in to comment.