Skip to content

Commit

Permalink
feat: support LocalTrackSubscribedEvent. (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Aug 27, 2024
1 parent c3f5ff2 commit 0929ca9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions example/lib/pages/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class _RoomPageState extends State<RoomPage> {
'Attempting to reconnect ${event.attempt}/${event.maxAttemptsRetry}, '
'(${event.nextRetryDelaysInMs}ms delay until next attempt)');
})
..on<LocalTrackSubscribedEvent>((event) {
print('Local track subscribed: ${event.trackSid}');
})
..on<LocalTrackPublishedEvent>((_) => _sortParticipants())
..on<LocalTrackUnpublishedEvent>((_) => _sortParticipants())
..on<TrackSubscribedEvent>((_) => _sortParticipants())
Expand Down
5 changes: 5 additions & 0 deletions lib/src/core/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,11 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
await publisher!.addIceCandidate(event.candidate);
}
})
..on<SignalLocalTrackSubscribedEvent>((event) async {
events.emit(EngineLocalTrackSubscribedEvent(
trackSid: event.trackSid,
));
})
..on<SignalTokenUpdatedEvent>((event) {
logger.fine('Server refreshed the token');
token = event.token;
Expand Down
7 changes: 7 additions & 0 deletions lib/src/core/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
notifyListeners();
}
})
..on<EngineLocalTrackSubscribedEvent>(
(event) => events.emit(
LocalTrackSubscribedEvent(
trackSid: event.trackSid,
),
),
)
..on<EngineActiveSpeakersUpdateEvent>(
(event) => _onEngineActiveSpeakersUpdateEvent(event.speakers))
..on<EngineDataPacketReceivedEvent>(_onDataMessageEvent)
Expand Down
5 changes: 5 additions & 0 deletions lib/src/core/signal_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
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));
Expand Down
11 changes: 11 additions & 0 deletions lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions lib/src/internal/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0929ca9

Please sign in to comment.