Organize events (#13)
* move internal events & remove unused events * `TrackUnpublishedEvent` for local tracks * update example since we have local track unpublish events * use flutter_webrtc 0.6.9
This commit is contained in:
@@ -47,11 +47,7 @@ class _ControlsWidgetState extends State<ControlsWidget> {
|
||||
|
||||
void _unpublishAll() async {
|
||||
final result = await context.showUnPublishDialog();
|
||||
if (result == true) {
|
||||
await participant.unpublishAllTracks();
|
||||
// Force to update UI for now
|
||||
participant.notifyListeners();
|
||||
}
|
||||
if (result == true) await participant.unpublishAllTracks();
|
||||
}
|
||||
|
||||
void _muteAudio() {
|
||||
|
||||
@@ -110,12 +110,10 @@ packages:
|
||||
flutter_webrtc:
|
||||
dependency: transitive
|
||||
description:
|
||||
path: "."
|
||||
ref: master
|
||||
resolved-ref: "32d83d85fa2faebcd37a19534f8a84273b12cbce"
|
||||
url: "https://github.com/flutter-webrtc/flutter-webrtc"
|
||||
source: git
|
||||
version: "0.6.8"
|
||||
name: flutter_webrtc
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.9"
|
||||
google_fonts:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// Flutter Client SDK to LiveKit.
|
||||
library livekit_client;
|
||||
|
||||
export 'src/exceptions.dart';
|
||||
export 'src/events.dart';
|
||||
export 'src/exceptions.dart';
|
||||
export 'src/livekit.dart';
|
||||
export 'src/managers/event.dart';
|
||||
export 'src/options.dart';
|
||||
@@ -21,5 +21,5 @@ export 'src/track/remote_track_publication.dart';
|
||||
export 'src/track/track.dart';
|
||||
export 'src/track/track_publication.dart';
|
||||
export 'src/track/video_track.dart';
|
||||
export 'src/types.dart' show RTCConfiguration, RTCIceServer, RTCIceTransportPolicy, Reliability;
|
||||
export 'src/types.dart';
|
||||
export 'src/widget/video_track_renderer.dart';
|
||||
|
||||
+2
-67
@@ -68,10 +68,6 @@ class ActiveSpeakersChangedEvent with RoomEvent {
|
||||
});
|
||||
}
|
||||
|
||||
class AudioPlaybackChangedEvent with RoomEvent {
|
||||
const AudioPlaybackChangedEvent();
|
||||
}
|
||||
|
||||
/// When a new [Track] is published to [Room] *after* the current participant has
|
||||
/// joined. It will not fire for tracks that are already published.
|
||||
/// Emitted by [Room] and [RemoteParticipant].
|
||||
@@ -87,8 +83,8 @@ class TrackPublishedEvent with RoomEvent, ParticipantEvent {
|
||||
/// The participant has unpublished one of their [Track].
|
||||
/// Emitted by [Room] and [RemoteParticipant].
|
||||
class TrackUnpublishedEvent with RoomEvent, ParticipantEvent {
|
||||
final RemoteParticipant participant;
|
||||
final RemoteTrackPublication publication;
|
||||
final Participant participant;
|
||||
final TrackPublication publication;
|
||||
const TrackUnpublishedEvent({
|
||||
required this.participant,
|
||||
required this.publication,
|
||||
@@ -217,13 +213,6 @@ class EngineReconnectedEvent with EngineEvent {
|
||||
const EngineReconnectedEvent();
|
||||
}
|
||||
|
||||
// class EngineParticipantUpdateEvent with EngineEvent {
|
||||
// final List<lk_models.ParticipantInfo> participants;
|
||||
// const EngineParticipantUpdateEvent({
|
||||
// required this.participants,
|
||||
// });
|
||||
// }
|
||||
|
||||
class EngineTrackAddedEvent with EngineEvent {
|
||||
final rtc.MediaStreamTrack track;
|
||||
final rtc.MediaStream stream;
|
||||
@@ -253,60 +242,6 @@ class EngineRemoteMuteChangedEvent with EngineEvent {
|
||||
});
|
||||
}
|
||||
|
||||
// added
|
||||
abstract class EngineIceStateUpdatedEvent with EngineEvent {
|
||||
final rtc.RTCIceConnectionState iceState;
|
||||
final bool isPrimary;
|
||||
const EngineIceStateUpdatedEvent({
|
||||
required this.iceState,
|
||||
required this.isPrimary,
|
||||
});
|
||||
}
|
||||
|
||||
class EngineSubscriberIceStateUpdatedEvent extends EngineIceStateUpdatedEvent {
|
||||
const EngineSubscriberIceStateUpdatedEvent({
|
||||
required rtc.RTCIceConnectionState state,
|
||||
required bool isPrimary,
|
||||
}) : super(
|
||||
iceState: state,
|
||||
isPrimary: isPrimary,
|
||||
);
|
||||
}
|
||||
|
||||
class EnginePublisherIceStateUpdatedEvent extends EngineIceStateUpdatedEvent {
|
||||
const EnginePublisherIceStateUpdatedEvent({
|
||||
required rtc.RTCIceConnectionState state,
|
||||
required bool isPrimary,
|
||||
}) : super(
|
||||
iceState: state,
|
||||
isPrimary: isPrimary,
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Track events
|
||||
//
|
||||
|
||||
class TrackMessageEvent with TrackEvent {
|
||||
const TrackMessageEvent();
|
||||
}
|
||||
|
||||
class TrackUpdateSettingsEvent with TrackEvent {
|
||||
const TrackUpdateSettingsEvent();
|
||||
}
|
||||
|
||||
class TrackUpdateSubscriptionEvent with TrackEvent {
|
||||
const TrackUpdateSubscriptionEvent();
|
||||
}
|
||||
|
||||
class TrackAudioPlaybackStartedEvent with TrackEvent {
|
||||
const TrackAudioPlaybackStartedEvent();
|
||||
}
|
||||
|
||||
class TrackAudioPlaybackFailedEvent with TrackEvent {
|
||||
const TrackAudioPlaybackFailedEvent();
|
||||
}
|
||||
|
||||
//
|
||||
// Signal events
|
||||
//
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// added
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../events.dart';
|
||||
|
||||
@internal
|
||||
abstract class EngineIceStateUpdatedEvent with EngineEvent {
|
||||
final rtc.RTCIceConnectionState iceState;
|
||||
final bool isPrimary;
|
||||
const EngineIceStateUpdatedEvent({
|
||||
required this.iceState,
|
||||
required this.isPrimary,
|
||||
});
|
||||
}
|
||||
|
||||
@internal
|
||||
class EngineSubscriberIceStateUpdatedEvent extends EngineIceStateUpdatedEvent {
|
||||
const EngineSubscriberIceStateUpdatedEvent({
|
||||
required rtc.RTCIceConnectionState state,
|
||||
required bool isPrimary,
|
||||
}) : super(
|
||||
iceState: state,
|
||||
isPrimary: isPrimary,
|
||||
);
|
||||
}
|
||||
|
||||
@internal
|
||||
class EnginePublisherIceStateUpdatedEvent extends EngineIceStateUpdatedEvent {
|
||||
const EnginePublisherIceStateUpdatedEvent({
|
||||
required rtc.RTCIceConnectionState state,
|
||||
required bool isPrimary,
|
||||
}) : super(
|
||||
iceState: state,
|
||||
isPrimary: isPrimary,
|
||||
);
|
||||
}
|
||||
@@ -151,14 +151,11 @@ class LocalParticipant extends Participant {
|
||||
|
||||
/// Unpublish a track that's already published
|
||||
@override
|
||||
Future<void> unpublishTrack(String trackSid, {bool notify = false}) async {
|
||||
Future<void> unpublishTrack(String trackSid, {bool notify = true}) async {
|
||||
logger.finer('Unpublish track sid: $trackSid, notify: $notify');
|
||||
final pub = trackPublications.remove(trackSid);
|
||||
if (pub is! LocalTrackPublication) return;
|
||||
|
||||
// final existing = tracks.values.where((element) => element.track == track);
|
||||
// if (existing.isEmpty) return;
|
||||
// final pub = existing.first;
|
||||
final track = pub.track;
|
||||
if (track != null) {
|
||||
await track.stop();
|
||||
@@ -178,6 +175,13 @@ class LocalParticipant extends Participant {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
[events, roomEvents].emit(TrackUnpublishedEvent(
|
||||
participant: this,
|
||||
publication: pub,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Publish a new data payload to the room.
|
||||
|
||||
@@ -152,7 +152,7 @@ class RemoteParticipant extends Participant {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> unpublishTrack(String trackSid, {bool notify = false}) async {
|
||||
Future<void> unpublishTrack(String trackSid, {bool notify = true}) async {
|
||||
logger.finer('Unpublish track sid: $trackSid, notify: $notify');
|
||||
final pub = trackPublications.remove(trackSid);
|
||||
if (pub is! RemoteTrackPublication) return;
|
||||
@@ -166,10 +166,6 @@ class RemoteParticipant extends Participant {
|
||||
track: track,
|
||||
publication: pub,
|
||||
));
|
||||
|
||||
// if (track is AudioTrack) {
|
||||
// await AudioManager().decrementSubscriptionCounter();
|
||||
// }
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'constants.dart';
|
||||
import 'events.dart';
|
||||
import 'exceptions.dart';
|
||||
import 'extensions.dart';
|
||||
import 'internal/events.dart';
|
||||
import 'logger.dart';
|
||||
import 'managers/delay.dart';
|
||||
import 'managers/event.dart';
|
||||
|
||||
+4
-6
@@ -98,12 +98,10 @@ packages:
|
||||
flutter_webrtc:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: master
|
||||
resolved-ref: "32d83d85fa2faebcd37a19534f8a84273b12cbce"
|
||||
url: "https://github.com/flutter-webrtc/flutter-webrtc"
|
||||
source: git
|
||||
version: "0.6.8"
|
||||
name: flutter_webrtc
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.9"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
+2
-8
@@ -15,14 +15,8 @@ dependencies:
|
||||
logging: ^1.0.2
|
||||
uuid: ^3.0.4
|
||||
synchronized: ^3.0.0
|
||||
protobuf: ^2.0.0
|
||||
|
||||
flutter_webrtc:
|
||||
# This will use custom webrtc build from
|
||||
# https://github.com/webrtc-sdk/Specs/releases
|
||||
git:
|
||||
url: https://github.com/flutter-webrtc/flutter-webrtc
|
||||
ref: master
|
||||
protobuf: ^2.0.0
|
||||
flutter_webrtc: ^0.6.9
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user