deprecate setter for enabled, organize RemoteTrackPublication

This commit is contained in:
Hiroshi Horie
2022-01-11 00:07:35 +07:00
parent 810f6ba7e8
commit 0f41aed902
+39 -22
View File
@@ -24,20 +24,22 @@ import 'track_publication.dart';
/// control if we should subscribe to the track, and its quality (for video). /// control if we should subscribe to the track, and its quality (for video).
class RemoteTrackPublication<T extends RemoteTrack> class RemoteTrackPublication<T extends RemoteTrack>
extends TrackPublication<T> { extends TrackPublication<T> {
/// The [RemoteParticipant] this [RemoteTrackPublication] belongs to.
@override @override
final RemoteParticipant participant; final RemoteParticipant participant;
bool get enabled => _enabled;
bool _enabled = true; bool _enabled = true;
lk_models.VideoQuality _videoQuality = lk_models.VideoQuality.HIGH; lk_models.VideoQuality _videoQuality = lk_models.VideoQuality.HIGH;
lk_models.VideoQuality get videoQuality => _videoQuality; lk_models.VideoQuality get videoQuality => _videoQuality;
StreamState _streamState = StreamState.paused;
/// The server may pause the track when they are bandwidth limitations and resume /// 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 /// when there is more capacity. This property will be updated when the track is
/// paused / resumed by the server. See [TrackStreamStateUpdatedEvent] for the /// paused / resumed by the server. See [TrackStreamStateUpdatedEvent] for the
/// relevant event. /// relevant event.
StreamState get streamState => _streamState; StreamState get streamState => _streamState;
StreamState _streamState = StreamState.paused;
// latest TrackInfo // latest TrackInfo
bool _metadataMuted = false; bool _metadataMuted = false;
@@ -46,13 +48,29 @@ class RemoteTrackPublication<T extends RemoteTrack>
bool _subscriptionAllowed = true; bool _subscriptionAllowed = true;
bool get subscriptionAllowed => _subscriptionAllowed; 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 @internal
Future<void> updateStreamState(StreamState streamState) async { Future<void> updateStreamState(StreamState streamState) async {
// return if no change // return if no change
if (_streamState == streamState) return; if (_streamState == streamState) return;
_streamState = streamState; _streamState = streamState;
[participant.events, participant.room.events] [
.emit(TrackStreamStateUpdatedEvent( participant.events,
participant.room.events,
].emit(TrackStreamStateUpdatedEvent(
participant: participant, participant: participant,
trackPublication: this, trackPublication: this,
streamState: streamState, streamState: streamState,
@@ -205,17 +223,16 @@ class RemoteTrackPublication<T extends RemoteTrack>
_sendUpdateTrackSettings(); _sendUpdateTrackSettings();
} }
bool get enabled => _enabled; Future<void> enable() async {
set enabled(bool newValue) { if (_enabled) return;
if (_enabled == newValue) return; _enabled = true;
_enabled = newValue;
_sendUpdateTrackSettings(); _sendUpdateTrackSettings();
} }
@Deprecated('use subscribe() or unsubscribe() instead') Future<void> disable() async {
set subscribed(bool val) { if (!_enabled) return;
logger.fine('setting subscribed = ${val}'); _enabled = false;
val ? subscribe() : unsubscribe(); _sendUpdateTrackSettings();
} }
Future<void> subscribe() async { Future<void> subscribe() async {
@@ -299,17 +316,17 @@ class RemoteTrackPublication<T extends RemoteTrack>
return true; return true;
} }
@override // Deprecated --------------------------------------------------
bool get subscribed {
// always return false when subscription is not allowed @Deprecated('use subscribe() or unsubscribe() instead')
if (!_subscriptionAllowed) return false; set subscribed(bool newValue) {
return super.subscribed; logger.fine('Setting subscribed = ${newValue}');
newValue ? subscribe() : unsubscribe();
} }
TrackSubscriptionState get subscriptionState { @Deprecated('Use enable() or disable() instead')
if (!_subscriptionAllowed) return TrackSubscriptionState.notAllowed; set enabled(bool newValue) {
return super.subscribed logger.fine('Setting enabled = ${newValue}');
? TrackSubscriptionState.subscribed newValue ? enable() : disable();
: TrackSubscriptionState.unsubscribed;
} }
} }