Skip to content

Commit b67c807

Browse files
authored
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
1 parent 84618cf commit b67c807

File tree

10 files changed

+62
-103
lines changed

10 files changed

+62
-103
lines changed

example/lib/widgets/controls.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ class _ControlsWidgetState extends State<ControlsWidget> {
4747

4848
void _unpublishAll() async {
4949
final result = await context.showUnPublishDialog();
50-
if (result == true) {
51-
await participant.unpublishAllTracks();
52-
// Force to update UI for now
53-
participant.notifyListeners();
54-
}
50+
if (result == true) await participant.unpublishAllTracks();
5551
}
5652

5753
void _muteAudio() {

example/pubspec.lock

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ packages:
110110
flutter_webrtc:
111111
dependency: transitive
112112
description:
113-
path: "."
114-
ref: master
115-
resolved-ref: "32d83d85fa2faebcd37a19534f8a84273b12cbce"
116-
url: "https://github.com/flutter-webrtc/flutter-webrtc"
117-
source: git
118-
version: "0.6.8"
113+
name: flutter_webrtc
114+
url: "https://pub.dartlang.org"
115+
source: hosted
116+
version: "0.6.9"
119117
google_fonts:
120118
dependency: "direct main"
121119
description:

lib/livekit_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/// Flutter Client SDK to LiveKit.
22
library livekit_client;
33

4-
export 'src/exceptions.dart';
54
export 'src/events.dart';
5+
export 'src/exceptions.dart';
66
export 'src/livekit.dart';
77
export 'src/managers/event.dart';
88
export 'src/options.dart';
@@ -21,5 +21,5 @@ export 'src/track/remote_track_publication.dart';
2121
export 'src/track/track.dart';
2222
export 'src/track/track_publication.dart';
2323
export 'src/track/video_track.dart';
24-
export 'src/types.dart' show RTCConfiguration, RTCIceServer, RTCIceTransportPolicy, Reliability;
24+
export 'src/types.dart';
2525
export 'src/widget/video_track_renderer.dart';

lib/src/events.dart

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ class ActiveSpeakersChangedEvent with RoomEvent {
6868
});
6969
}
7070

71-
class AudioPlaybackChangedEvent with RoomEvent {
72-
const AudioPlaybackChangedEvent();
73-
}
74-
7571
/// When a new [Track] is published to [Room] *after* the current participant has
7672
/// joined. It will not fire for tracks that are already published.
7773
/// Emitted by [Room] and [RemoteParticipant].
@@ -87,8 +83,8 @@ class TrackPublishedEvent with RoomEvent, ParticipantEvent {
8783
/// The participant has unpublished one of their [Track].
8884
/// Emitted by [Room] and [RemoteParticipant].
8985
class TrackUnpublishedEvent with RoomEvent, ParticipantEvent {
90-
final RemoteParticipant participant;
91-
final RemoteTrackPublication publication;
86+
final Participant participant;
87+
final TrackPublication publication;
9288
const TrackUnpublishedEvent({
9389
required this.participant,
9490
required this.publication,
@@ -217,13 +213,6 @@ class EngineReconnectedEvent with EngineEvent {
217213
const EngineReconnectedEvent();
218214
}
219215

220-
// class EngineParticipantUpdateEvent with EngineEvent {
221-
// final List<lk_models.ParticipantInfo> participants;
222-
// const EngineParticipantUpdateEvent({
223-
// required this.participants,
224-
// });
225-
// }
226-
227216
class EngineTrackAddedEvent with EngineEvent {
228217
final rtc.MediaStreamTrack track;
229218
final rtc.MediaStream stream;
@@ -253,60 +242,6 @@ class EngineRemoteMuteChangedEvent with EngineEvent {
253242
});
254243
}
255244

256-
// added
257-
abstract class EngineIceStateUpdatedEvent with EngineEvent {
258-
final rtc.RTCIceConnectionState iceState;
259-
final bool isPrimary;
260-
const EngineIceStateUpdatedEvent({
261-
required this.iceState,
262-
required this.isPrimary,
263-
});
264-
}
265-
266-
class EngineSubscriberIceStateUpdatedEvent extends EngineIceStateUpdatedEvent {
267-
const EngineSubscriberIceStateUpdatedEvent({
268-
required rtc.RTCIceConnectionState state,
269-
required bool isPrimary,
270-
}) : super(
271-
iceState: state,
272-
isPrimary: isPrimary,
273-
);
274-
}
275-
276-
class EnginePublisherIceStateUpdatedEvent extends EngineIceStateUpdatedEvent {
277-
const EnginePublisherIceStateUpdatedEvent({
278-
required rtc.RTCIceConnectionState state,
279-
required bool isPrimary,
280-
}) : super(
281-
iceState: state,
282-
isPrimary: isPrimary,
283-
);
284-
}
285-
286-
//
287-
// Track events
288-
//
289-
290-
class TrackMessageEvent with TrackEvent {
291-
const TrackMessageEvent();
292-
}
293-
294-
class TrackUpdateSettingsEvent with TrackEvent {
295-
const TrackUpdateSettingsEvent();
296-
}
297-
298-
class TrackUpdateSubscriptionEvent with TrackEvent {
299-
const TrackUpdateSubscriptionEvent();
300-
}
301-
302-
class TrackAudioPlaybackStartedEvent with TrackEvent {
303-
const TrackAudioPlaybackStartedEvent();
304-
}
305-
306-
class TrackAudioPlaybackFailedEvent with TrackEvent {
307-
const TrackAudioPlaybackFailedEvent();
308-
}
309-
310245
//
311246
// Signal events
312247
//

lib/src/internal/events.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// added
2+
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
3+
import 'package:meta/meta.dart';
4+
5+
import '../events.dart';
6+
7+
@internal
8+
abstract class EngineIceStateUpdatedEvent with EngineEvent {
9+
final rtc.RTCIceConnectionState iceState;
10+
final bool isPrimary;
11+
const EngineIceStateUpdatedEvent({
12+
required this.iceState,
13+
required this.isPrimary,
14+
});
15+
}
16+
17+
@internal
18+
class EngineSubscriberIceStateUpdatedEvent extends EngineIceStateUpdatedEvent {
19+
const EngineSubscriberIceStateUpdatedEvent({
20+
required rtc.RTCIceConnectionState state,
21+
required bool isPrimary,
22+
}) : super(
23+
iceState: state,
24+
isPrimary: isPrimary,
25+
);
26+
}
27+
28+
@internal
29+
class EnginePublisherIceStateUpdatedEvent extends EngineIceStateUpdatedEvent {
30+
const EnginePublisherIceStateUpdatedEvent({
31+
required rtc.RTCIceConnectionState state,
32+
required bool isPrimary,
33+
}) : super(
34+
iceState: state,
35+
isPrimary: isPrimary,
36+
);
37+
}

lib/src/participant/local_participant.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,11 @@ class LocalParticipant extends Participant {
151151

152152
/// Unpublish a track that's already published
153153
@override
154-
Future<void> unpublishTrack(String trackSid, {bool notify = false}) async {
154+
Future<void> unpublishTrack(String trackSid, {bool notify = true}) async {
155155
logger.finer('Unpublish track sid: $trackSid, notify: $notify');
156156
final pub = trackPublications.remove(trackSid);
157157
if (pub is! LocalTrackPublication) return;
158158

159-
// final existing = tracks.values.where((element) => element.track == track);
160-
// if (existing.isEmpty) return;
161-
// final pub = existing.first;
162159
final track = pub.track;
163160
if (track != null) {
164161
await track.stop();
@@ -178,6 +175,13 @@ class LocalParticipant extends Participant {
178175
}
179176
}
180177
}
178+
179+
if (notify) {
180+
[events, roomEvents].emit(TrackUnpublishedEvent(
181+
participant: this,
182+
publication: pub,
183+
));
184+
}
181185
}
182186

183187
/// Publish a new data payload to the room.

lib/src/participant/remote_participant.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class RemoteParticipant extends Participant {
152152
}
153153

154154
@override
155-
Future<void> unpublishTrack(String trackSid, {bool notify = false}) async {
155+
Future<void> unpublishTrack(String trackSid, {bool notify = true}) async {
156156
logger.finer('Unpublish track sid: $trackSid, notify: $notify');
157157
final pub = trackPublications.remove(trackSid);
158158
if (pub is! RemoteTrackPublication) return;
@@ -166,10 +166,6 @@ class RemoteParticipant extends Participant {
166166
track: track,
167167
publication: pub,
168168
));
169-
170-
// if (track is AudioTrack) {
171-
// await AudioManager().decrementSubscriptionCounter();
172-
// }
173169
}
174170

175171
if (notify) {

lib/src/rtc_engine.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'constants.dart';
99
import 'events.dart';
1010
import 'exceptions.dart';
1111
import 'extensions.dart';
12+
import 'internal/events.dart';
1213
import 'logger.dart';
1314
import 'managers/delay.dart';
1415
import 'managers/event.dart';

pubspec.lock

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ packages:
9898
flutter_webrtc:
9999
dependency: "direct main"
100100
description:
101-
path: "."
102-
ref: master
103-
resolved-ref: "32d83d85fa2faebcd37a19534f8a84273b12cbce"
104-
url: "https://github.com/flutter-webrtc/flutter-webrtc"
105-
source: git
106-
version: "0.6.8"
101+
name: flutter_webrtc
102+
url: "https://pub.dartlang.org"
103+
source: hosted
104+
version: "0.6.9"
107105
http:
108106
dependency: "direct main"
109107
description:

pubspec.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ dependencies:
1515
logging: ^1.0.2
1616
uuid: ^3.0.4
1717
synchronized: ^3.0.0
18-
protobuf: ^2.0.0
19-
20-
flutter_webrtc:
21-
# This will use custom webrtc build from
22-
# https://github.com/webrtc-sdk/Specs/releases
23-
git:
24-
url: https://github.com/flutter-webrtc/flutter-webrtc
25-
ref: master
18+
protobuf: ^2.0.0
19+
flutter_webrtc: ^0.6.9
2620

2721
dev_dependencies:
2822
flutter_test:

0 commit comments

Comments
 (0)