Skip to content

Commit

Permalink
revert changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Oct 25, 2023
1 parent d8d677d commit e8ad32c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
14 changes: 12 additions & 2 deletions example/lib/pages/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class _RoomPageState extends State<RoomPage> {
@override
void initState() {
super.initState();
// add callback for a `RoomEvent` as opposed to a `ParticipantEvent`
widget.room.addListener(_onRoomDidUpdate);
// add callbacks for finer grained events
_setUpListeners();
_sortParticipants();
Expand All @@ -50,6 +52,7 @@ class _RoomPageState extends State<RoomPage> {
void dispose() {
// always dispose listener
(() async {
widget.room.removeListener(_onRoomDidUpdate);
await _listener.dispose();
await widget.room.dispose();
})();
Expand All @@ -65,13 +68,16 @@ class _RoomPageState extends State<RoomPage> {
WidgetsBindingCompatible.instance
?.addPostFrameCallback((timeStamp) => Navigator.pop(context));
})
..on<ParticipantEvent>((event) {
print('Participant event');
// sort participants on many track events as noted in documentation linked above
_sortParticipants();
})
..on<RoomRecordingStatusChanged>((event) {
context.showRecordingStatusChangedDialog(event.activeRecording);
})
..on<LocalTrackPublishedEvent>((_) => _sortParticipants())
..on<LocalTrackUnpublishedEvent>((_) => _sortParticipants())
..on<TrackSubscribedEvent>((_) => _sortParticipants())
..on<TrackUnsubscribedEvent>((_) => _sortParticipants())
..on<TrackE2EEStateEvent>(_onE2EEStateEvent)
..on<ParticipantNameUpdatedEvent>((event) {
print(
Expand Down Expand Up @@ -114,6 +120,10 @@ class _RoomPageState extends State<RoomPage> {
}
}

void _onRoomDidUpdate() {
_sortParticipants();
}

void _onE2EEStateEvent(TrackE2EEStateEvent e2eeState) {
print('e2ee state: $e2eeState');
}
Expand Down
32 changes: 32 additions & 0 deletions example/lib/widgets/video_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:livekit_client/livekit_client.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'dart:math' as math;

import 'package:livekit_example/theme.dart';

class VideoWidget extends StatelessWidget {
final VideoTrack? track;
final RTCVideoRenderer renderer;
bool get hasVideo => track != null && !(track?.muted ?? true);
const VideoWidget(this.renderer, this.track, {Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => hasVideo
? VideoTrackRenderer(
key: ValueKey(track!.sid),
renderer,
track!,
fit: RTCVideoViewObjectFit.RTCVideoViewObjectFitContain,
)
: Container(
alignment: Alignment.center,
child: LayoutBuilder(
builder: (ctx, constraints) => Icon(
Icons.videocam_off_outlined,
color: LKColors.lkBlue,
size: math.min(constraints.maxHeight, constraints.maxWidth) * 0.3,
),
),
);
}

0 comments on commit e8ad32c

Please sign in to comment.