Fix: RemoteTrack's initial mute state (#59)

This commit is contained in:
Hiroshi Horie
2021-12-17 12:26:33 +07:00
committed by GitHub
parent fa063ac352
commit f458f052a5
2 changed files with 46 additions and 26 deletions
@@ -49,6 +49,9 @@ class RemoteTrackPublication<T extends RemoteTrack>
/// relevant event. /// relevant event.
StreamState get streamState => _streamState; StreamState get streamState => _streamState;
// latest TrackInfo
bool _metadataMuted = false;
@internal @internal
Future<void> updateStreamState(StreamState streamState) async { Future<void> updateStreamState(StreamState streamState) async {
// return if no change // return if no change
@@ -73,6 +76,8 @@ class RemoteTrackPublication<T extends RemoteTrack>
required lk_models.TrackInfo info, required lk_models.TrackInfo info,
T? track, T? track,
}) : super(info: info) { }) : super(info: info) {
logger.fine('RemoteTrackPublication.init track: $track, info: $info');
// register dispose func // register dispose func
onDispose(() async { onDispose(() async {
_cancelVisibilityDebounceFunc?.call(); _cancelVisibilityDebounceFunc?.call();
@@ -92,8 +97,11 @@ class RemoteTrackPublication<T extends RemoteTrack>
@internal @internal
@override @override
void updateFromInfo(lk_models.TrackInfo info) { void updateFromInfo(lk_models.TrackInfo info) {
logger.fine(
'RemoteTrackPublication.updateFromInfo sid: ${info.sid} muted: ${info.muted}');
super.updateFromInfo(info); super.updateFromInfo(info);
track?.updateMuted(info.muted); track?.updateMuted(info.muted);
_metadataMuted = info.muted;
} }
// called any time visibility info updates // called any time visibility info updates
@@ -169,29 +177,35 @@ class RemoteTrackPublication<T extends RemoteTrack>
@internal @internal
@override @override
Future<bool> updateTrack(covariant T? newValue) async { Future<bool> updateTrack(covariant T? newValue) async {
logger.fine('RemoteTrackPublication.updateTrack track: $newValue');
final didUpdate = await super.updateTrack(newValue); final didUpdate = await super.updateTrack(newValue);
// Only listen for visibility updates if video optimization is on
// and the attached track is a video track
final roomOptions = participant.room.roomOptions ?? const RoomOptions(); final roomOptions = participant.room.roomOptions ?? const RoomOptions();
//
if (didUpdate && if (didUpdate && newValue != null) {
newValue != null && // if new Track has been set to this RemoteTrackPublication,
roomOptions.optimizeVideo && // update the Track's muted state from the latest info.
newValue.kind == lk_models.TrackType.VIDEO) { newValue.updateMuted(
// _metadataMuted,
// Attach visibility event listener (if video track) shouldNotify: false, // don't emit event since this is initial state
// );
final listener = newValue.createListener();
listener.on<TrackVisibilityUpdatedEvent>( // Only listen for visibility updates if video optimization is on
_onVideoRendererVisibilityUpdateEvent); // and the attached track is a video track
// if (roomOptions.optimizeVideo &&
newValue.onDispose(() async { newValue.kind == lk_models.TrackType.VIDEO) {
await listener.dispose(); // Attach visibility event listener
// consider all views are disposed when track is null final listener = newValue.createListener();
_visibilities.clear(); listener.on<TrackVisibilityUpdatedEvent>(
if (!isDisposed) _visibilityDidUpdate?.call(null); _onVideoRendererVisibilityUpdateEvent);
});
newValue.onDispose(() async {
await listener.dispose();
// consider all views are disposed when track is null
_visibilities.clear();
if (!isDisposed) _visibilityDidUpdate?.call(null);
});
}
} }
return didUpdate; return didUpdate;
+12 -6
View File
@@ -139,14 +139,20 @@ abstract class Track extends DisposableChangeNotifier
} }
@internal @internal
void updateMuted(bool muted, {bool shouldSendSignal = false}) { void updateMuted(
bool muted, {
bool shouldNotify = true,
bool shouldSendSignal = false,
}) {
if (_muted == muted) return; if (_muted == muted) return;
_muted = muted; _muted = muted;
events.emit(InternalTrackMuteUpdatedEvent( if (shouldNotify) {
track: this, events.emit(InternalTrackMuteUpdatedEvent(
muted: muted, track: this,
shouldSendSignal: shouldSendSignal, muted: muted,
)); shouldSendSignal: shouldSendSignal,
));
}
} }
@internal @internal