Files
client-sdk-flutter/lib/src/track/remote_track_publication.dart
T
Hiroshi HorieandGitHub ab31ddabb9 Apply Flutter best practices [Non-Breaking] (#2)
* Add flutter_lints package

* Use key in widget constructors

lint: use_key_in_widget_constructors

* Unnecessary new keyword

lint: unnecessary_new

* Prefer const with constant constructors

* Exclude protobuf files from analyzer

* Private field could be final

* Annotate overridden members

* Use initializing formals when possible

* Don't access members with `this` unless avoiding shadowing

* Prefer is! operator

* Use isEmpty instead of length

* Use collection literals when possible

* Revert comment changes

* Cleaner null testing

* Misc fixes

* Avoid using `forEach` with a function literal

* Prefer `final` over `var` where applicable

* Enforce stricter type-checking

* Ignore VS Code files

* Flutter format

* Prefer using lowerCamelCase for constant names

* flutter format -l 100

* Disable `avoid_print` for examples

* Slight improvements to example

Should solve lint error: no_logic_in_create_state
2021-08-31 16:35:07 +09:00

79 lines
2.1 KiB
Dart

import '../proto/livekit_models.pb.dart';
import '../proto/livekit_rtc.pbserver.dart';
import '../participant/remote_participant.dart';
import 'track.dart';
import 'track_publication.dart';
/// Represents a track publication from a RemoteParticipant. Provides methods to
/// control if we should subscribe to the track, and its quality (for video).
class RemoteTrackPublication extends TrackPublication {
final RemoteParticipant _participant;
bool _unsubscribed = false;
bool _disabled = false;
VideoQuality _videoQuality = VideoQuality.HIGH;
VideoQuality get videoQuality => _videoQuality;
set videoQuality(VideoQuality val) {
if (val == _videoQuality) return;
_videoQuality = val;
_sendUpdateTrackSettings();
}
bool get enabled => !_disabled;
set enabled(bool val) {
if (_disabled == !val) return;
_disabled = !val;
_sendUpdateTrackSettings();
}
@override
bool get subscribed {
if (_unsubscribed) {
return false;
}
return super.subscribed;
}
set subscribed(bool val) {
if (_unsubscribed == !val) return;
_unsubscribed = !val;
_sendUpdateTrackSettings();
}
/// for internal use
/// {@nodoc}
@override
set muted(bool val) {
if (val == muted) {
return;
}
super.muted = val;
if (val) {
_participant.delegate?.onTrackMuted(_participant, this);
_participant.roomDelegate?.onTrackMuted(_participant, this);
} else {
_participant.delegate?.onTrackUnmuted(_participant, this);
_participant.roomDelegate?.onTrackUnmuted(_participant, this);
}
if (subscribed) {
track?.mediaTrack.enabled = !val;
}
_participant.muteChanged();
}
RemoteTrackPublication(TrackInfo info, this._participant, [Track? track]) : super.fromInfo(info) {
this.track = track;
}
void _sendUpdateTrackSettings() {
final settings = UpdateTrackSettings(
trackSids: [sid],
disabled: _disabled,
);
if (kind == TrackType.VIDEO) {
settings.quality = _videoQuality;
}
_participant.client.sendUpdateTrackSettings(settings);
}
}