Switch to new event system (#9)
* `SignalEvents` and `synchronized` mode for `EventsListenable` * cascade syntax * clean up * `RoomEvents` * `ParticipantEvents` * all events implemented * make it compile with M1 macs * dispose logic * cleaner connect logic * ask to publish * fix initial EngineTrackAddedEvent glitch * fix unpublishTrack bug * clean up * better events docs * organize event types * clean up * cleaner wait logic * wait for event instead of using Completer * notifyListeners
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import '../events.dart';
|
||||
import '../extensions.dart';
|
||||
import '../logger.dart';
|
||||
import '../managers/event.dart';
|
||||
import '../participant/local_participant.dart';
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import 'track.dart';
|
||||
@@ -23,15 +26,20 @@ class LocalTrackPublication extends TrackPublication {
|
||||
|
||||
super.muted = val;
|
||||
track?.mediaStreamTrack.enabled = !val;
|
||||
_participant.engine.client.sendMuteTrack(sid, val);
|
||||
_participant.engine.signalClient.sendMuteTrack(sid, val);
|
||||
|
||||
if (val) {
|
||||
_participant.delegate?.onTrackMuted(_participant, this);
|
||||
_participant.roomDelegate?.onTrackMuted(_participant, this);
|
||||
// Track muted
|
||||
[_participant.events, _participant.roomEvents].emit(TrackMutedEvent(
|
||||
participant: _participant,
|
||||
track: this,
|
||||
));
|
||||
} else {
|
||||
_participant.delegate?.onTrackUnmuted(_participant, this);
|
||||
_participant.roomDelegate?.onTrackUnmuted(_participant, this);
|
||||
// Track un-muted
|
||||
[_participant.events, _participant.roomEvents].emit(TrackUnmutedEvent(
|
||||
participant: _participant,
|
||||
track: this,
|
||||
));
|
||||
}
|
||||
_participant.muteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import 'package:livekit_client/livekit_client.dart';
|
||||
|
||||
import '../participant/remote_participant.dart';
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../proto/livekit_rtc.pb.dart' as lk_rtc;
|
||||
import 'track.dart';
|
||||
import '../extensions.dart';
|
||||
|
||||
import 'track_publication.dart';
|
||||
|
||||
/// Represents a track publication from a RemoteParticipant. Provides methods to
|
||||
@@ -50,16 +54,21 @@ class RemoteTrackPublication extends TrackPublication {
|
||||
}
|
||||
super.muted = val;
|
||||
if (val) {
|
||||
_participant.delegate?.onTrackMuted(_participant, this);
|
||||
_participant.roomDelegate?.onTrackMuted(_participant, this);
|
||||
// Track muted
|
||||
[_participant.events, _participant.roomEvents].emit(TrackMutedEvent(
|
||||
participant: _participant,
|
||||
track: this,
|
||||
));
|
||||
} else {
|
||||
_participant.delegate?.onTrackUnmuted(_participant, this);
|
||||
_participant.roomDelegate?.onTrackUnmuted(_participant, this);
|
||||
// Track un-muted
|
||||
[_participant.events, _participant.roomEvents].emit(TrackUnmutedEvent(
|
||||
participant: _participant,
|
||||
track: this,
|
||||
));
|
||||
}
|
||||
if (subscribed) {
|
||||
track?.mediaStreamTrack.enabled = !val;
|
||||
}
|
||||
_participant.muteChanged();
|
||||
}
|
||||
|
||||
RemoteTrackPublication(
|
||||
|
||||
+12
-11
@@ -1,28 +1,29 @@
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
import 'package:livekit_client/src/classes/change_notifier.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
|
||||
class TrackDimension {
|
||||
int width;
|
||||
int height;
|
||||
|
||||
TrackDimension(this.width, this.height);
|
||||
}
|
||||
|
||||
/// Wrapper around a MediaStreamTrack with additional metadata.
|
||||
class Track {
|
||||
/// Base for [AudioTrack] and [VideoTrack],
|
||||
/// can not be instantiated directly.
|
||||
abstract class Track extends LKChangeNotifier {
|
||||
static const cameraName = 'camera';
|
||||
static const screenShareName = 'screen';
|
||||
|
||||
String name;
|
||||
lk_models.TrackType kind;
|
||||
final String name;
|
||||
final lk_models.TrackType kind;
|
||||
rtc.MediaStreamTrack mediaStreamTrack;
|
||||
|
||||
String? sid;
|
||||
rtc.RTCRtpTransceiver? transceiver;
|
||||
String? _cid;
|
||||
|
||||
Track(this.kind, this.name, this.mediaStreamTrack);
|
||||
Track(
|
||||
this.kind,
|
||||
this.name,
|
||||
this.mediaStreamTrack,
|
||||
);
|
||||
|
||||
bool get muted => mediaStreamTrack.muted == null ? false : mediaStreamTrack.muted!;
|
||||
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../types.dart';
|
||||
import 'track.dart';
|
||||
|
||||
/// Represents a track that's published to the server. This class contains
|
||||
/// metadata associated with tracks.
|
||||
class TrackPublication {
|
||||
///
|
||||
/// Base for [RemoteTrackPublication] and [LocalTrackPublication],
|
||||
/// can not be instantiated directly.
|
||||
|
||||
abstract class TrackPublication {
|
||||
final String name;
|
||||
final String sid;
|
||||
final lk_models.TrackType kind;
|
||||
|
||||
Track? track;
|
||||
String name;
|
||||
String sid;
|
||||
lk_models.TrackType kind;
|
||||
bool muted = false;
|
||||
bool simulcasted = false;
|
||||
TrackDimension? dimension;
|
||||
@@ -31,4 +37,12 @@ class TrackPublication {
|
||||
dimension = TrackDimension(info.width, info.height);
|
||||
}
|
||||
}
|
||||
|
||||
// Equality operators
|
||||
// Object is considered equal when sid is equal
|
||||
@override
|
||||
int get hashCode => sid.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is TrackPublication && sid == other.sid;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import 'track.dart';
|
||||
|
||||
/// A video track will notify when its mediaTrack has changed.
|
||||
class VideoTrack extends Track with ChangeNotifier {
|
||||
class VideoTrack extends Track {
|
||||
rtc.MediaStream _mediaStream;
|
||||
|
||||
VideoTrack(
|
||||
|
||||
Reference in New Issue
Block a user