From 0929ca9cb5b0d91d7445cd41b4ac88f935304133 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 27 Aug 2024 08:34:38 +0800 Subject: [PATCH] feat: support LocalTrackSubscribedEvent. (#578) --- example/lib/pages/room.dart | 3 +++ lib/src/core/engine.dart | 5 +++++ lib/src/core/room.dart | 7 +++++++ lib/src/core/signal_client.dart | 5 +++++ lib/src/events.dart | 11 +++++++++++ lib/src/internal/events.dart | 17 +++++++++++++++++ 6 files changed, 48 insertions(+) diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index cfaeda79..e9c6ee6d 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -99,6 +99,9 @@ class _RoomPageState extends State { 'Attempting to reconnect ${event.attempt}/${event.maxAttemptsRetry}, ' '(${event.nextRetryDelaysInMs}ms delay until next attempt)'); }) + ..on((event) { + print('Local track subscribed: ${event.trackSid}'); + }) ..on((_) => _sortParticipants()) ..on((_) => _sortParticipants()) ..on((_) => _sortParticipants()) diff --git a/lib/src/core/engine.dart b/lib/src/core/engine.dart index 8ad91fd0..d46acc0f 100644 --- a/lib/src/core/engine.dart +++ b/lib/src/core/engine.dart @@ -1015,6 +1015,11 @@ class Engine extends Disposable with EventsEmittable { await publisher!.addIceCandidate(event.candidate); } }) + ..on((event) async { + events.emit(EngineLocalTrackSubscribedEvent( + trackSid: event.trackSid, + )); + }) ..on((event) { logger.fine('Server refreshed the token'); token = event.token; diff --git a/lib/src/core/room.dart b/lib/src/core/room.dart index 801bfe3c..181b87aa 100644 --- a/lib/src/core/room.dart +++ b/lib/src/core/room.dart @@ -526,6 +526,13 @@ class Room extends DisposableChangeNotifier with EventsEmittable { notifyListeners(); } }) + ..on( + (event) => events.emit( + LocalTrackSubscribedEvent( + trackSid: event.trackSid, + ), + ), + ) ..on( (event) => _onEngineActiveSpeakersUpdateEvent(event.speakers)) ..on(_onDataMessageEvent) diff --git a/lib/src/core/signal_client.dart b/lib/src/core/signal_client.dart index fdcb81a8..e13801bc 100644 --- a/lib/src/core/signal_client.dart +++ b/lib/src/core/signal_client.dart @@ -281,6 +281,11 @@ class SignalClient extends Disposable with EventsEmittable { trackSid: msg.trackUnpublished.trackSid, )); break; + case lk_rtc.SignalResponse_Message.trackSubscribed: + events.emit(SignalLocalTrackSubscribedEvent( + trackSid: msg.trackSubscribed.trackSid, + )); + break; case lk_rtc.SignalResponse_Message.speakersChanged: events.emit( SignalSpeakersChangedEvent(speakers: msg.speakersChanged.speakers)); diff --git a/lib/src/events.dart b/lib/src/events.dart index 8b2f7975..001d67a6 100644 --- a/lib/src/events.dart +++ b/lib/src/events.dart @@ -228,6 +228,17 @@ class LocalTrackPublishedEvent with RoomEvent, ParticipantEvent { '(participant: ${participant}, publication: ${publication})'; } +class LocalTrackSubscribedEvent with RoomEvent, ParticipantEvent { + final String trackSid; + const LocalTrackSubscribedEvent({ + required this.trackSid, + }); + + @override + String toString() => '${runtimeType}' + '(trakSid: ${trackSid}})'; +} + /// The local participant has unpublished one of their [Track]. /// Emitted by [Room] and [LocalParticipant]. class LocalTrackUnpublishedEvent with RoomEvent, ParticipantEvent { diff --git a/lib/src/internal/events.dart b/lib/src/internal/events.dart index b6fc4c92..e9fca89a 100644 --- a/lib/src/internal/events.dart +++ b/lib/src/internal/events.dart @@ -169,6 +169,14 @@ class EngineDisconnectedEvent with InternalEvent, EngineEvent { }); } +@internal +class EngineLocalTrackSubscribedEvent with InternalEvent, EngineEvent { + final String trackSid; + const EngineLocalTrackSubscribedEvent({ + required this.trackSid, + }); +} + @internal class EngineFullRestartingEvent with InternalEvent, EngineEvent { const EngineFullRestartingEvent(); @@ -297,6 +305,15 @@ class SignalTrackUnpublishedEvent with SignalEvent, InternalEvent { }); } +@internal +class SignalLocalTrackSubscribedEvent with SignalEvent, InternalEvent { + final String trackSid; + + const SignalLocalTrackSubscribedEvent({ + required this.trackSid, + }); +} + @internal class SignalRoomUpdateEvent with SignalEvent, InternalEvent { final lk_models.Room room;