From 0f41aed902bd2bea9d84595f4fb4ffef5fb88474 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Tue, 11 Jan 2022 00:07:35 +0700 Subject: [PATCH] deprecate setter for enabled, organize RemoteTrackPublication --- lib/src/publication/remote.dart | 61 +++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/lib/src/publication/remote.dart b/lib/src/publication/remote.dart index 2fa589d..a30152f 100644 --- a/lib/src/publication/remote.dart +++ b/lib/src/publication/remote.dart @@ -24,20 +24,22 @@ import 'track_publication.dart'; /// control if we should subscribe to the track, and its quality (for video). class RemoteTrackPublication extends TrackPublication { + /// The [RemoteParticipant] this [RemoteTrackPublication] belongs to. @override final RemoteParticipant participant; + bool get enabled => _enabled; bool _enabled = true; + lk_models.VideoQuality _videoQuality = lk_models.VideoQuality.HIGH; lk_models.VideoQuality get videoQuality => _videoQuality; - StreamState _streamState = StreamState.paused; - /// The server may pause the track when they are bandwidth limitations and resume /// when there is more capacity. This property will be updated when the track is /// paused / resumed by the server. See [TrackStreamStateUpdatedEvent] for the /// relevant event. StreamState get streamState => _streamState; + StreamState _streamState = StreamState.paused; // latest TrackInfo bool _metadataMuted = false; @@ -46,13 +48,29 @@ class RemoteTrackPublication bool _subscriptionAllowed = true; bool get subscriptionAllowed => _subscriptionAllowed; + @override + bool get subscribed { + // always return false when subscription is not allowed + if (!_subscriptionAllowed) return false; + return super.subscribed; + } + + TrackSubscriptionState get subscriptionState { + if (!_subscriptionAllowed) return TrackSubscriptionState.notAllowed; + return super.subscribed + ? TrackSubscriptionState.subscribed + : TrackSubscriptionState.unsubscribed; + } + @internal Future updateStreamState(StreamState streamState) async { // return if no change if (_streamState == streamState) return; _streamState = streamState; - [participant.events, participant.room.events] - .emit(TrackStreamStateUpdatedEvent( + [ + participant.events, + participant.room.events, + ].emit(TrackStreamStateUpdatedEvent( participant: participant, trackPublication: this, streamState: streamState, @@ -205,17 +223,16 @@ class RemoteTrackPublication _sendUpdateTrackSettings(); } - bool get enabled => _enabled; - set enabled(bool newValue) { - if (_enabled == newValue) return; - _enabled = newValue; + Future enable() async { + if (_enabled) return; + _enabled = true; _sendUpdateTrackSettings(); } - @Deprecated('use subscribe() or unsubscribe() instead') - set subscribed(bool val) { - logger.fine('setting subscribed = ${val}'); - val ? subscribe() : unsubscribe(); + Future disable() async { + if (!_enabled) return; + _enabled = false; + _sendUpdateTrackSettings(); } Future subscribe() async { @@ -299,17 +316,17 @@ class RemoteTrackPublication return true; } - @override - bool get subscribed { - // always return false when subscription is not allowed - if (!_subscriptionAllowed) return false; - return super.subscribed; + // Deprecated -------------------------------------------------- + + @Deprecated('use subscribe() or unsubscribe() instead') + set subscribed(bool newValue) { + logger.fine('Setting subscribed = ${newValue}'); + newValue ? subscribe() : unsubscribe(); } - TrackSubscriptionState get subscriptionState { - if (!_subscriptionAllowed) return TrackSubscriptionState.notAllowed; - return super.subscribed - ? TrackSubscriptionState.subscribed - : TrackSubscriptionState.unsubscribed; + @Deprecated('Use enable() or disable() instead') + set enabled(bool newValue) { + logger.fine('Setting enabled = ${newValue}'); + newValue ? enable() : disable(); } }