@@ -1,7 +1,3 @@
|
||||
import '../logger.dart';
|
||||
import '../events.dart';
|
||||
import '../extensions.dart';
|
||||
import '../internal/events.dart';
|
||||
import '../participant/local_participant.dart';
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../track/local.dart';
|
||||
@@ -24,34 +20,6 @@ class LocalTrackPublication<T extends LocalTrack> extends TrackPublication<T> {
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> updateTrack(T? newValue) async {
|
||||
final didUpdate = await super.updateTrack(newValue);
|
||||
|
||||
if (newValue != null) {
|
||||
// attach listener to track
|
||||
final listener = newValue.createListener()
|
||||
// listen for track muted events
|
||||
..on<TrackMuteUpdatedEvent>((event) {
|
||||
// send signal to server
|
||||
logger.fine('${this} sending mute signal ${sid}, ${event.muted}');
|
||||
participant.room.engine.signalClient.sendMuteTrack(sid, event.muted);
|
||||
// emit events
|
||||
final newEvent = event.muted
|
||||
? TrackMutedEvent(participant: participant, track: this)
|
||||
: TrackUnmutedEvent(participant: participant, track: this);
|
||||
[participant.events, participant.room.events].emit(newEvent);
|
||||
});
|
||||
// dispose listener when the track is disposed
|
||||
newValue.onDispose(() => listener.dispose());
|
||||
}
|
||||
|
||||
return didUpdate;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get muted => track?.muted ?? super.muted;
|
||||
|
||||
/// Mute the track associated with this publication
|
||||
Future<void> mute() async => await track?.mute();
|
||||
|
||||
|
||||
@@ -93,7 +93,6 @@ class RemoteTrackPublication<T extends RemoteTrack>
|
||||
@override
|
||||
void updateFromInfo(lk_models.TrackInfo info) {
|
||||
super.updateFromInfo(info);
|
||||
updateMuted(info.muted);
|
||||
track?.updateMuted(info.muted);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import '../events.dart';
|
||||
import '../internal/events.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../extensions.dart';
|
||||
import '../logger.dart';
|
||||
import '../participant/participant.dart';
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../support/disposable.dart';
|
||||
@@ -26,9 +29,7 @@ abstract class TrackPublication<T extends Track> extends Disposable {
|
||||
/// The [Participant] this publication belongs to.
|
||||
abstract final Participant participant;
|
||||
|
||||
// metadata-muted
|
||||
bool _muted = false;
|
||||
bool get muted => _muted;
|
||||
bool get muted => track?.muted ?? false;
|
||||
|
||||
bool simulcasted = false;
|
||||
TrackDimension? dimension;
|
||||
@@ -64,9 +65,6 @@ abstract class TrackPublication<T extends Track> extends Disposable {
|
||||
bool operator ==(Object other) =>
|
||||
other is TrackPublication && sid == other.sid;
|
||||
|
||||
@internal
|
||||
void updateMuted(bool muted) => _muted = muted;
|
||||
|
||||
// Update track to new value, dispose previous if exists.
|
||||
// Returns true if value has changed.
|
||||
// Intended for internal use only.
|
||||
@@ -76,6 +74,30 @@ 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());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void _onTrackMuteUpdatedEvent(InternalTrackMuteUpdatedEvent event) {
|
||||
// send signal to server (if mute initiated by local user)
|
||||
if (event.shouldSendSignal) {
|
||||
logger.fine(
|
||||
'${this} Sending mute signal... sid:${sid}, muted:${event.muted}');
|
||||
participant.room.engine.signalClient.sendMuteTrack(sid, event.muted);
|
||||
}
|
||||
// emit events
|
||||
final newEvent = event.muted
|
||||
? TrackMutedEvent(participant: participant, track: this)
|
||||
: TrackUnmutedEvent(participant: participant, track: this);
|
||||
[participant.events, participant.room.events].emit(newEvent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user