Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/src/publication/local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class LocalTrackPublication<T extends LocalTrack> extends TrackPublication<T> {
required this.participant,
required lk_models.TrackInfo info,
required T track,
}) : super(info: info) {
updateTrack(track);
}) : super(info: info, track: track) {
// register dispose func
onDispose(() async {
// this object is responsible for disposing track
Expand Down
4 changes: 1 addition & 3 deletions lib/src/publication/remote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RemoteTrackPublication<T extends RemoteTrack>
required this.participant,
required lk_models.TrackInfo info,
T? track,
}) : super(info: info) {
}) : super(info: info, track: track) {
logger.fine('RemoteTrackPublication.init track: $track, info: $info');

// register dispose func
Expand All @@ -121,8 +121,6 @@ class RemoteTrackPublication<T extends RemoteTrack>
cancelFunc: (func) => _cancelPendingTrackSettingsUpdateRequest = func,
wait: const Duration(milliseconds: 1500),
);

updateTrack(track);
}

@internal
Expand Down
23 changes: 13 additions & 10 deletions lib/src/publication/track_publication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ abstract class TrackPublication<T extends Track> extends Disposable {

TrackPublication({
required lk_models.TrackInfo info,
required T? track,
}) : sid = info.sid,
name = info.name,
kind = info.type.toLKType(),
source = info.source.toLKType(),
_simulcasted = info.simulcast,
_metadataMuted = info.muted,
_mimeType = info.mimeType {
_mimeType = info.mimeType,
_track = track {
if (track != null) _attachTrackListener(track);
updateFromInfo(info);
}

Expand Down Expand Up @@ -110,19 +113,19 @@ abstract class TrackPublication<T extends Track> extends Disposable {
// dispose previous track (if exists)
await _track?.dispose();
_track = newValue;

if (newValue != null) {
// listen for Track's muted events
final listener = newValue.createListener()
..on<InternalTrackMuteUpdatedEvent>(
(event) => _onTrackMuteUpdatedEvent(event));
// dispose listener when the track is disposed
newValue.onDispose(() => listener.dispose());
}
if (newValue != null) _attachTrackListener(newValue);

return true;
}

void _attachTrackListener(T track) {
// listen for Track's muted events
final listener = track.createListener()
..on<InternalTrackMuteUpdatedEvent>((event) => _onTrackMuteUpdatedEvent(event));
// dispose listener when the track is disposed
track.onDispose(() => listener.dispose());
}

void _onTrackMuteUpdatedEvent(InternalTrackMuteUpdatedEvent event) {
// send signal to server (if mute initiated by local user)
if (event.shouldSendSignal) {
Expand Down
Loading