implemented tracks, local & remote participants
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
|
||||
import '../proto/livekit_models.pb.dart';
|
||||
import 'track.dart';
|
||||
|
||||
class LocalAudioTrack extends Track {
|
||||
LocalAudioTrack(String name, MediaStreamTrack track) : super(TrackType.AUDIO, name, track);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import '../participant/local_participant.dart';
|
||||
import '../proto/livekit_models.pb.dart';
|
||||
import 'track.dart';
|
||||
import 'track_publication.dart';
|
||||
|
||||
class LocalTrackPublication extends TrackPublication {
|
||||
LocalParticipant _participant;
|
||||
|
||||
LocalTrackPublication(TrackInfo info, Track track, this._participant)
|
||||
: super.fromInfo(info) {
|
||||
this.track = track;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
|
||||
import 'video_track.dart';
|
||||
|
||||
class LocalVideoTrack extends VideoTrack {
|
||||
LocalVideoTrack(String name, MediaStreamTrack mediaTrack)
|
||||
: super(name, mediaTrack);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import '../proto/livekit_models.pb.dart';
|
||||
import '../proto/livekit_rtc.pbserver.dart';
|
||||
import '../participant/remote_participant.dart';
|
||||
import 'track.dart';
|
||||
import 'track_publication.dart';
|
||||
|
||||
class RemoteTrackPublication extends TrackPublication {
|
||||
RemoteParticipant _participant;
|
||||
bool _unsubscribed = false;
|
||||
bool _disabled = false;
|
||||
VideoQuality _videoQuality = VideoQuality.HIGH;
|
||||
|
||||
VideoQuality get videoQuality => _videoQuality;
|
||||
set videoQuality(VideoQuality val) {
|
||||
_videoQuality = val;
|
||||
_sendUpdateTrackSettings();
|
||||
}
|
||||
|
||||
bool get enabled => !_disabled;
|
||||
set enabled(bool val) {
|
||||
_disabled = !val;
|
||||
_sendUpdateTrackSettings();
|
||||
}
|
||||
|
||||
bool get subscribed {
|
||||
if (_unsubscribed) {
|
||||
return false;
|
||||
}
|
||||
return super.subscribed;
|
||||
}
|
||||
|
||||
set subscribed(bool val) {
|
||||
_unsubscribed = !val;
|
||||
_sendUpdateTrackSettings();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
RemoteTrackPublication(TrackInfo info, this._participant, [Track? track])
|
||||
: super.fromInfo(info) {
|
||||
this.track = track;
|
||||
}
|
||||
|
||||
_sendUpdateTrackSettings() {
|
||||
var settings = new UpdateTrackSettings(
|
||||
trackSids: [sid],
|
||||
disabled: _disabled,
|
||||
);
|
||||
if (kind == TrackType.VIDEO) {
|
||||
settings.quality = _videoQuality;
|
||||
}
|
||||
_participant.client.sendUpdateTrackSettings(settings);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../proto/livekit_models.pb.dart';
|
||||
|
||||
class TrackDimension {
|
||||
int width;
|
||||
int height;
|
||||
@@ -6,5 +11,41 @@ class TrackDimension {
|
||||
}
|
||||
|
||||
class Track {
|
||||
String name;
|
||||
TrackType kind;
|
||||
MediaStreamTrack mediaTrack;
|
||||
String? sid;
|
||||
RTCRtpTransceiver? transceiver;
|
||||
String? _cid;
|
||||
|
||||
Track(this.kind, this.name, this.mediaTrack);
|
||||
|
||||
RTCRtpMediaType get mediaType {
|
||||
switch (kind) {
|
||||
case TrackType.AUDIO:
|
||||
return RTCRtpMediaType.RTCRtpMediaTypeAudio;
|
||||
case TrackType.VIDEO:
|
||||
return RTCRtpMediaType.RTCRtpMediaTypeVideo;
|
||||
// this should never happen
|
||||
default:
|
||||
return RTCRtpMediaType.RTCRtpMediaTypeAudio;
|
||||
}
|
||||
}
|
||||
|
||||
String getCid() {
|
||||
var cid = _cid;
|
||||
if (cid == null) {
|
||||
cid = mediaTrack.id;
|
||||
}
|
||||
if (cid == null) {
|
||||
var uuid = Uuid();
|
||||
cid = uuid.v4();
|
||||
_cid = cid;
|
||||
}
|
||||
return cid;
|
||||
}
|
||||
|
||||
stop() {
|
||||
mediaTrack.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,16 @@ class TrackPublication {
|
||||
bool simulcasted = false;
|
||||
TrackDimension? dimension;
|
||||
|
||||
bool get isSubscribed => track != null;
|
||||
|
||||
TrackPublication({required this.sid, required this.name, required this.kind});
|
||||
bool get subscribed => track != null;
|
||||
|
||||
TrackPublication.fromInfo(TrackInfo info)
|
||||
: sid = info.sid,
|
||||
name = info.name,
|
||||
kind = info.type {
|
||||
_updateFromInfo(info);
|
||||
updateFromInfo(info);
|
||||
}
|
||||
|
||||
_updateFromInfo(TrackInfo info) {
|
||||
updateFromInfo(TrackInfo info) {
|
||||
muted = info.muted;
|
||||
simulcasted = info.simulcast;
|
||||
if (info.type == TrackType.VIDEO) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
|
||||
import '../proto/livekit_models.pb.dart';
|
||||
import 'track.dart';
|
||||
|
||||
class VideoTrack extends Track {
|
||||
VideoTrack(String name, MediaStreamTrack mediaTrack)
|
||||
: super(TrackType.VIDEO, name, mediaTrack);
|
||||
|
||||
// TODO: keep list of video renderers
|
||||
|
||||
@override
|
||||
stop() {
|
||||
super.stop();
|
||||
// TODO: remove renderer
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user