From 308c5167fbf109bacfd6d148df7186fd7002b288 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Fri, 1 Oct 2021 16:15:54 +0900 Subject: [PATCH 1/4] move internal events & remove unused events --- lib/livekit_client.dart | 4 +-- lib/src/events.dart | 65 ------------------------------------ lib/src/internal/events.dart | 37 ++++++++++++++++++++ lib/src/rtc_engine.dart | 1 + 4 files changed, 40 insertions(+), 67 deletions(-) create mode 100644 lib/src/internal/events.dart diff --git a/lib/livekit_client.dart b/lib/livekit_client.dart index 3f51f7bd5..995ef18e4 100644 --- a/lib/livekit_client.dart +++ b/lib/livekit_client.dart @@ -1,8 +1,8 @@ /// Flutter Client SDK to LiveKit. library livekit_client; -export 'src/exceptions.dart'; export 'src/events.dart'; +export 'src/exceptions.dart'; export 'src/livekit.dart'; export 'src/managers/event.dart'; export 'src/options.dart'; @@ -21,5 +21,5 @@ export 'src/track/remote_track_publication.dart'; export 'src/track/track.dart'; export 'src/track/track_publication.dart'; export 'src/track/video_track.dart'; -export 'src/types.dart' show RTCConfiguration, RTCIceServer, RTCIceTransportPolicy, Reliability; +export 'src/types.dart'; export 'src/widget/video_track_renderer.dart'; diff --git a/lib/src/events.dart b/lib/src/events.dart index fb0cb3d1e..d24377095 100644 --- a/lib/src/events.dart +++ b/lib/src/events.dart @@ -68,10 +68,6 @@ class ActiveSpeakersChangedEvent with RoomEvent { }); } -class AudioPlaybackChangedEvent with RoomEvent { - const AudioPlaybackChangedEvent(); -} - /// When a new [Track] is published to [Room] *after* the current participant has /// joined. It will not fire for tracks that are already published. /// Emitted by [Room] and [RemoteParticipant]. @@ -217,13 +213,6 @@ class EngineReconnectedEvent with EngineEvent { const EngineReconnectedEvent(); } -// class EngineParticipantUpdateEvent with EngineEvent { -// final List participants; -// const EngineParticipantUpdateEvent({ -// required this.participants, -// }); -// } - class EngineTrackAddedEvent with EngineEvent { final rtc.MediaStreamTrack track; final rtc.MediaStream stream; @@ -253,60 +242,6 @@ class EngineRemoteMuteChangedEvent with EngineEvent { }); } -// added -abstract class EngineIceStateUpdatedEvent with EngineEvent { - final rtc.RTCIceConnectionState iceState; - final bool isPrimary; - const EngineIceStateUpdatedEvent({ - required this.iceState, - required this.isPrimary, - }); -} - -class EngineSubscriberIceStateUpdatedEvent extends EngineIceStateUpdatedEvent { - const EngineSubscriberIceStateUpdatedEvent({ - required rtc.RTCIceConnectionState state, - required bool isPrimary, - }) : super( - iceState: state, - isPrimary: isPrimary, - ); -} - -class EnginePublisherIceStateUpdatedEvent extends EngineIceStateUpdatedEvent { - const EnginePublisherIceStateUpdatedEvent({ - required rtc.RTCIceConnectionState state, - required bool isPrimary, - }) : super( - iceState: state, - isPrimary: isPrimary, - ); -} - -// -// Track events -// - -class TrackMessageEvent with TrackEvent { - const TrackMessageEvent(); -} - -class TrackUpdateSettingsEvent with TrackEvent { - const TrackUpdateSettingsEvent(); -} - -class TrackUpdateSubscriptionEvent with TrackEvent { - const TrackUpdateSubscriptionEvent(); -} - -class TrackAudioPlaybackStartedEvent with TrackEvent { - const TrackAudioPlaybackStartedEvent(); -} - -class TrackAudioPlaybackFailedEvent with TrackEvent { - const TrackAudioPlaybackFailedEvent(); -} - // // Signal events // diff --git a/lib/src/internal/events.dart b/lib/src/internal/events.dart new file mode 100644 index 000000000..c7b51b2c2 --- /dev/null +++ b/lib/src/internal/events.dart @@ -0,0 +1,37 @@ +// added +import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc; +import 'package:meta/meta.dart'; + +import '../events.dart'; + +@internal +abstract class EngineIceStateUpdatedEvent with EngineEvent { + final rtc.RTCIceConnectionState iceState; + final bool isPrimary; + const EngineIceStateUpdatedEvent({ + required this.iceState, + required this.isPrimary, + }); +} + +@internal +class EngineSubscriberIceStateUpdatedEvent extends EngineIceStateUpdatedEvent { + const EngineSubscriberIceStateUpdatedEvent({ + required rtc.RTCIceConnectionState state, + required bool isPrimary, + }) : super( + iceState: state, + isPrimary: isPrimary, + ); +} + +@internal +class EnginePublisherIceStateUpdatedEvent extends EngineIceStateUpdatedEvent { + const EnginePublisherIceStateUpdatedEvent({ + required rtc.RTCIceConnectionState state, + required bool isPrimary, + }) : super( + iceState: state, + isPrimary: isPrimary, + ); +} diff --git a/lib/src/rtc_engine.dart b/lib/src/rtc_engine.dart index 882935ca9..164f77ef9 100644 --- a/lib/src/rtc_engine.dart +++ b/lib/src/rtc_engine.dart @@ -9,6 +9,7 @@ import 'constants.dart'; import 'events.dart'; import 'exceptions.dart'; import 'extensions.dart'; +import 'internal/events.dart'; import 'logger.dart'; import 'managers/delay.dart'; import 'managers/event.dart'; From cb273238e9c0c4aaa057cb64e445daa06f8a786a Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Fri, 1 Oct 2021 16:46:27 +0900 Subject: [PATCH 2/4] `TrackUnpublishedEvent` for local tracks --- lib/src/events.dart | 4 ++-- lib/src/participant/local_participant.dart | 12 ++++++++---- lib/src/participant/remote_participant.dart | 6 +----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/src/events.dart b/lib/src/events.dart index d24377095..f365e6460 100644 --- a/lib/src/events.dart +++ b/lib/src/events.dart @@ -83,8 +83,8 @@ class TrackPublishedEvent with RoomEvent, ParticipantEvent { /// The participant has unpublished one of their [Track]. /// Emitted by [Room] and [RemoteParticipant]. class TrackUnpublishedEvent with RoomEvent, ParticipantEvent { - final RemoteParticipant participant; - final RemoteTrackPublication publication; + final Participant participant; + final TrackPublication publication; const TrackUnpublishedEvent({ required this.participant, required this.publication, diff --git a/lib/src/participant/local_participant.dart b/lib/src/participant/local_participant.dart index 0d096ba51..8ae60b1bc 100644 --- a/lib/src/participant/local_participant.dart +++ b/lib/src/participant/local_participant.dart @@ -151,14 +151,11 @@ class LocalParticipant extends Participant { /// Unpublish a track that's already published @override - Future unpublishTrack(String trackSid, {bool notify = false}) async { + Future unpublishTrack(String trackSid, {bool notify = true}) async { logger.finer('Unpublish track sid: $trackSid, notify: $notify'); final pub = trackPublications.remove(trackSid); if (pub is! LocalTrackPublication) return; - // final existing = tracks.values.where((element) => element.track == track); - // if (existing.isEmpty) return; - // final pub = existing.first; final track = pub.track; if (track != null) { await track.stop(); @@ -178,6 +175,13 @@ class LocalParticipant extends Participant { } } } + + if (notify) { + [events, roomEvents].emit(TrackUnpublishedEvent( + participant: this, + publication: pub, + )); + } } /// Publish a new data payload to the room. diff --git a/lib/src/participant/remote_participant.dart b/lib/src/participant/remote_participant.dart index 177a7eb7f..6036c1001 100644 --- a/lib/src/participant/remote_participant.dart +++ b/lib/src/participant/remote_participant.dart @@ -152,7 +152,7 @@ class RemoteParticipant extends Participant { } @override - Future unpublishTrack(String trackSid, {bool notify = false}) async { + Future unpublishTrack(String trackSid, {bool notify = true}) async { logger.finer('Unpublish track sid: $trackSid, notify: $notify'); final pub = trackPublications.remove(trackSid); if (pub is! RemoteTrackPublication) return; @@ -166,10 +166,6 @@ class RemoteParticipant extends Participant { track: track, publication: pub, )); - - // if (track is AudioTrack) { - // await AudioManager().decrementSubscriptionCounter(); - // } } if (notify) { From 47e9cd7da4824cc7ba75ee24cb78bd43c1e847bd Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Fri, 1 Oct 2021 16:47:50 +0900 Subject: [PATCH 3/4] update example since we have local track unpublish events --- example/lib/widgets/controls.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/example/lib/widgets/controls.dart b/example/lib/widgets/controls.dart index 3be30cab8..63f49758a 100644 --- a/example/lib/widgets/controls.dart +++ b/example/lib/widgets/controls.dart @@ -47,11 +47,7 @@ class _ControlsWidgetState extends State { void _unpublishAll() async { final result = await context.showUnPublishDialog(); - if (result == true) { - await participant.unpublishAllTracks(); - // Force to update UI for now - participant.notifyListeners(); - } + if (result == true) await participant.unpublishAllTracks(); } void _muteAudio() { From 3197922810cd5bfe230143af2fafdab4ee578202 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Fri, 1 Oct 2021 16:51:56 +0900 Subject: [PATCH 4/4] use flutter_webrtc 0.6.9 --- example/pubspec.lock | 10 ++++------ pubspec.lock | 10 ++++------ pubspec.yaml | 10 ++-------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index c04b21609..43fbf463d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -110,12 +110,10 @@ packages: flutter_webrtc: dependency: transitive description: - path: "." - ref: master - resolved-ref: "32d83d85fa2faebcd37a19534f8a84273b12cbce" - url: "https://github.com/flutter-webrtc/flutter-webrtc" - source: git - version: "0.6.8" + name: flutter_webrtc + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.9" google_fonts: dependency: "direct main" description: diff --git a/pubspec.lock b/pubspec.lock index d1a0e23b6..2b5752380 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -98,12 +98,10 @@ packages: flutter_webrtc: dependency: "direct main" description: - path: "." - ref: master - resolved-ref: "32d83d85fa2faebcd37a19534f8a84273b12cbce" - url: "https://github.com/flutter-webrtc/flutter-webrtc" - source: git - version: "0.6.8" + name: flutter_webrtc + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.9" http: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 689cccebe..e3064b950 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,14 +15,8 @@ dependencies: logging: ^1.0.2 uuid: ^3.0.4 synchronized: ^3.0.0 - protobuf: ^2.0.0 - - flutter_webrtc: - # This will use custom webrtc build from - # https://github.com/webrtc-sdk/Specs/releases - git: - url: https://github.com/flutter-webrtc/flutter-webrtc - ref: master + protobuf: ^2.0.0 + flutter_webrtc: ^0.6.9 dev_dependencies: flutter_test: