Skip to content

Commit

Permalink
improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Nov 6, 2024
1 parent 496784c commit aab5d1b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 72 deletions.
11 changes: 10 additions & 1 deletion lib/src/context/media_device_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ class MediaDeviceContext extends ChangeNotifier {

LocalAudioTrack? get localAudioTrack => _roomCtx.localAudioTrack;

StreamSubscription? _deviceChangeSub;

Future<void> loadDevices() async {
_loadDevices(await Hardware.instance.enumerateDevices());
Hardware.instance.onDeviceChange.stream.listen(_loadDevices);
_deviceChangeSub =
Hardware.instance.onDeviceChange.stream.listen(_loadDevices);
}

_loadDevices(List<MediaDevice> devices) {
Expand Down Expand Up @@ -311,4 +314,10 @@ class MediaDeviceContext extends ChangeNotifier {
}
notifyListeners();
}

@override
void dispose() {
super.dispose();
_deviceChangeSub?.cancel();
}
}
29 changes: 18 additions & 11 deletions lib/src/context/room_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RoomContext extends ChangeNotifier with ChatContextMixin {
_listener = _room.createListener();
_listener
..on<RoomConnectedEvent>((event) {
Debug.event('RoomContext: RoomConnectedEvent');
Debug.event('RoomContext: RoomConnectedEvent $roomName');
chatContextSetup(_listener, _room.localParticipant!);
_connectionState = _room.connectionState;
_connected = true;
Expand All @@ -72,7 +72,7 @@ class RoomContext extends ChangeNotifier with ChatContextMixin {
notifyListeners();
})
..on<RoomDisconnectedEvent>((event) {
Debug.event('RoomContext: RoomDisconnectedEvent');
Debug.event('RoomContext: RoomDisconnectedEvent $roomName');
_connectionState = _room.connectionState;
chatContextSetup(null, null);
_connected = false;
Expand All @@ -81,18 +81,18 @@ class RoomContext extends ChangeNotifier with ChatContextMixin {
notifyListeners();
})
..on<RoomReconnectedEvent>((event) {
Debug.event('RoomContext: RoomReconnectedEvent');
Debug.event('RoomContext: RoomReconnectedEvent $roomName');
_connectionState = _room.connectionState;
notifyListeners();
})
..on<RoomReconnectingEvent>((event) {
Debug.event('RoomContext: RoomReconnectingEvent');
Debug.event('RoomContext: RoomReconnectingEvent $roomName');
_connectionState = _room.connectionState;
notifyListeners();
})
..on<RoomMetadataChangedEvent>((event) {
Debug.event(
'RoomContext: RoomMetadataChangedEvent metadata = ${event.metadata}');
'RoomContext: RoomMetadataChangedEvent $roomName metadata = ${event.metadata}');
_roomMetadata = event.metadata;
notifyListeners();
})
Expand All @@ -104,22 +104,22 @@ class RoomContext extends ChangeNotifier with ChatContextMixin {
})
..on<ParticipantConnectedEvent>((event) {
Debug.event(
'RoomContext: ParticipantConnectedEvent participant = ${event.participant.identity}');
'RoomContext: ParticipantConnectedEvent $roomName participant = ${event.participant.identity}');
_buildParticipants();
})
..on<ParticipantDisconnectedEvent>((event) {
Debug.event(
'RoomContext: ParticipantDisconnectedEvent participant = ${event.participant.identity}');
'RoomContext: ParticipantDisconnectedEvent $roomName participant = ${event.participant.identity}');
_participants
.removeWhere((p) => p.identity == event.participant.identity);
notifyListeners();
})
..on<TrackPublishedEvent>((event) {
Debug.event('ParticipantContext: TrackPublishedEvent');
Debug.event('ParticipantContext: TrackPublishedEvent $roomName');
_buildParticipants();
})
..on<TrackUnpublishedEvent>((event) {
Debug.event('ParticipantContext: TrackUnpublishedEvent');
Debug.event('ParticipantContext: TrackUnpublishedEvent $roomName');
_buildParticipants();
})
..on<LocalTrackPublishedEvent>((event) {
Expand Down Expand Up @@ -228,6 +228,8 @@ class RoomContext extends ChangeNotifier with ChatContextMixin {
/// Get the connected status.
bool get connected => _connected;

LocalParticipant? get localParticipant => _room.localParticipant;

int get participantCount => _participants.length;

final List<Participant> _participants = [];
Expand Down Expand Up @@ -305,8 +307,13 @@ class RoomContext extends ChangeNotifier with ChatContextMixin {
}

@override
void dispose() {
_listener.dispose();
void dispose() async {
await _listener.dispose();
Debug.event('RoomContext disposed ${roomName ?? ''}');
if (_room.connectionState == ConnectionState.connected) {
await _room.disconnect();
}
await _room.dispose();
super.dispose();
}
}
3 changes: 1 addition & 2 deletions lib/src/ui/builder/room/room_participants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import 'package:flutter/material.dart';
import 'package:livekit_client/livekit_client.dart';
import 'package:provider/provider.dart';

import '../../../context/participant_context.dart';
import '../../../context/room_context.dart';
import '../../../debug/logger.dart';

Expand All @@ -35,7 +34,7 @@ class RoomParticipants extends StatelessWidget {
return Consumer<RoomContext>(
builder: (context, roomCtx, child) {
Debug.log('====> RoomParticipants for ${roomCtx.roomName}');
return Selector<ParticipantContext, List<Participant>>(
return Selector<RoomContext, List<Participant>>(
selector: (context, participants) => roomCtx.participants,
builder: (context, participants, child) {
return builder(context, participants);
Expand Down
111 changes: 53 additions & 58 deletions lib/src/ui/widgets/participant/participant_status_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,68 +47,63 @@ class ParticipantStatusBar extends StatelessWidget {
'===> ParticipantStatusBar for ${participantContext.name}');
var trackCtx = Provider.of<TrackReferenceContext?>(context);
var isScreenShare = trackCtx?.isScreenShare ?? false;
return Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 6),
color: Colors.black.withOpacity(0.6),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (showMuteStatus && !isScreenShare)
ParticipantMutedIndicator(
builder: (context, isMuted) => isMuted
? const Icon(
Icons.mic_off,
color: Colors.white54,
size: 20,
)
: const SizedBox(),
),
if (isScreenShare)
const Icon(
Icons.screen_share,
color: Colors.white54,
size: 20,
),
if (showName)
ParticipantName(
builder: (context, name) => name != null
? Flexible(
child: Text(
isScreenShare ? '$name\'s screen' : name,
style: const TextStyle(
color: Colors.white54,
fontSize: 16,
),
overflow: TextOverflow.ellipsis,
return Container(
padding: const EdgeInsets.symmetric(horizontal: 6),
color: Colors.black.withOpacity(0.6),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (showMuteStatus && !isScreenShare)
ParticipantMutedIndicator(
builder: (context, isMuted) => isMuted
? const Icon(
Icons.mic_off,
color: Colors.white54,
size: 20,
)
: const SizedBox(),
),
if (isScreenShare)
const Icon(
Icons.screen_share,
color: Colors.white54,
size: 20,
),
if (showName)
ParticipantName(
builder: (context, name) => name != null
? Flexible(
child: Text(
isScreenShare ? '$name\'s screen' : name,
style: const TextStyle(
color: Colors.white54,
fontSize: 16,
),
)
: Container(),
),
if (showConnectionQuality)
ConnectionQualityIndicator(
builder: (context, connectionQuality) =>
ConnectionQualityIndicatorWidget(
connectionQuality: connectionQuality,
),
overflow: TextOverflow.ellipsis,
),
)
: Container(),
),
if (showConnectionQuality)
ConnectionQualityIndicator(
builder: (context, connectionQuality) =>
ConnectionQualityIndicatorWidget(
connectionQuality: connectionQuality,
),
if (showE2EEStatus)
E2EEncryptionIndicator(
builder: (context, isEncrypted) => Padding(
padding: const EdgeInsets.only(left: 5),
child: Icon(
isEncrypted ? Icons.lock : Icons.lock_open,
color: Colors.white54,
size: 20,
),
),
if (showE2EEStatus)
E2EEncryptionIndicator(
builder: (context, isEncrypted) => Padding(
padding: const EdgeInsets.only(left: 5),
child: Icon(
isEncrypted ? Icons.lock : Icons.lock_open,
color: Colors.white54,
size: 20,
),
),
]),
),
),
]),
);
},
);
Expand Down

0 comments on commit aab5d1b

Please sign in to comment.