Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions example/lib/pages/connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class _ConnectPageState extends State<ConnectPage> {
static const _storeKeyE2EE = 'e2ee';
static const _storeKeySharedKey = 'shared-key';
static const _storeKeyMultiCodec = 'multi-codec';
static const _storeKeyPreferredCodec = 'preferred-codec';

final _uriCtrl = TextEditingController();
final _tokenCtrl = TextEditingController();
Expand Down Expand Up @@ -96,6 +97,7 @@ class _ConnectPageState extends State<ConnectPage> {
_dynacast = prefs.getBool(_storeKeyDynacast) ?? true;
_e2ee = prefs.getBool(_storeKeyE2EE) ?? false;
_multiCodec = prefs.getBool(_storeKeyMultiCodec) ?? false;
_preferredCodec = prefs.getString(_storeKeyPreferredCodec) ?? 'VP8';
});
}

Expand All @@ -110,6 +112,7 @@ class _ConnectPageState extends State<ConnectPage> {
await prefs.setBool(_storeKeyDynacast, _dynacast);
await prefs.setBool(_storeKeyE2EE, _e2ee);
await prefs.setBool(_storeKeyMultiCodec, _multiCodec);
await prefs.setString(_storeKeyPreferredCodec, _preferredCodec);
}

Future<void> _connect(BuildContext ctx) async {
Expand Down Expand Up @@ -317,10 +320,11 @@ class _ConnectPageState extends State<ConnectPage> {
color: Colors.blueAccent,
),
onChanged: (String? value) {
// This is called when the user selects an item.
if (value == null) return;
setState(() {
_preferredCodec = value!;
_preferredCodec = value;
});
unawaited(_writePrefs());
},
items: ['Preferred Codec', 'AV1', 'VP9', 'VP8', 'H264', 'H265']
.map<DropdownMenuItem<String>>((String value) {
Expand Down
32 changes: 30 additions & 2 deletions example/lib/pages/prejoin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:livekit_client/livekit_client.dart';
import 'package:livekit_example/exts.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../theme.dart';
import 'room.dart';
Expand Down Expand Up @@ -43,6 +44,9 @@ class PreJoinPage extends StatefulWidget {
}

class _PreJoinPageState extends State<PreJoinPage> {
static const _prefKeyEnableVideo = 'prejoin-enable-video';
static const _prefKeyEnableAudio = 'prejoin-enable-audio';

List<MediaDevice> _audioInputs = [];
List<MediaDevice> _videoInputs = [];
StreamSubscription? _subscription;
Expand All @@ -60,8 +64,14 @@ class _PreJoinPageState extends State<PreJoinPage> {
@override
void initState() {
super.initState();
unawaited(_initStateAsync());
}

Future<void> _initStateAsync() async {
await _readPrefs();
_subscription = Hardware.instance.onDeviceChange.stream.listen(_loadDevices);
unawaited(Hardware.instance.enumerateDevices().then(_loadDevices));
final devices = await Hardware.instance.enumerateDevices();
await _loadDevices(devices);
}

@override
Expand All @@ -70,7 +80,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
super.deactivate();
}

void _loadDevices(List<MediaDevice> devices) async {
Future<void> _loadDevices(List<MediaDevice> devices) async {
_audioInputs = devices.where((d) => d.kind == 'audioinput').toList();
_videoInputs = devices.where((d) => d.kind == 'videoinput').toList();

Expand Down Expand Up @@ -98,6 +108,7 @@ class _PreJoinPageState extends State<PreJoinPage> {

Future<void> _setEnableVideo(value) async {
_enableVideo = value;
await _writePrefs();
if (!_enableVideo) {
await _videoTrack?.stop();
_videoTrack = null;
Expand All @@ -109,6 +120,7 @@ class _PreJoinPageState extends State<PreJoinPage> {

Future<void> _setEnableAudio(value) async {
_enableAudio = value;
await _writePrefs();
if (!_enableAudio) {
await _audioTrack?.stop();
_audioTrack = null;
Expand All @@ -119,6 +131,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
}

Future<void> _changeLocalAudioTrack() async {
if (!_enableAudio) return;
if (_audioTrack != null) {
await _audioTrack!.stop();
_audioTrack = null;
Expand All @@ -135,6 +148,7 @@ class _PreJoinPageState extends State<PreJoinPage> {
}

Future<void> _changeLocalVideoTrack() async {
if (!_enableVideo) return;
if (_videoTrack != null) {
await _videoTrack!.stop();
_videoTrack = null;
Expand Down Expand Up @@ -249,6 +263,20 @@ class _PreJoinPageState extends State<PreJoinPage> {
Navigator.of(context).pop();
}

Future<void> _readPrefs() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
_enableVideo = prefs.getBool(_prefKeyEnableVideo) ?? true;
_enableAudio = prefs.getBool(_prefKeyEnableAudio) ?? true;
});
}

Future<void> _writePrefs() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_prefKeyEnableVideo, _enableVideo);
await prefs.setBool(_prefKeyEnableAudio, _enableAudio);
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down