From 66dbc94c1aedb7c4814d5f11febb60ed6a982de9 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 26 Nov 2021 23:51:37 -0800 Subject: [PATCH] Use high level track APIs in example app & docs (#36) --- README.md | 19 ++++++++++++++----- example/lib/pages/connect.dart | 4 ++-- example/lib/pages/room.dart | 16 +++++++--------- example/lib/widgets/controls.dart | 29 ----------------------------- 4 files changed, 23 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index f924609..ed83bf7 100644 --- a/README.md +++ b/README.md @@ -85,14 +85,23 @@ We built a multi-user conferencing app as an example in the [example/](example/) var room = await LiveKitClient.connect(url, token); try { // video will fail when running in ios simulator - var localVideo = await LocalVideoTrack.createCameraTrack(); - await room.localParticipant.publishVideoTrack(localVideo); + await room.localParticipant.setCameraEnabled(true); } catch (e) { print('could not publish video: $e'); } -var localAudio = await LocalAudioTrack.createTrack(); -await room.localParticipant.publishAudioTrack(localAudio); +await room.localParticipant.setMicrophoneEnabled(true); +``` + +### Advanced track manipulation + +The setCameraEnabled/setMicrophoneEnabled helpers are wrappers around the Track API. + +You can also manually create and publish tracks: + +```dart +var localVideo = await LocalVideoTrack.createCameraTrack(); +await room.localParticipant.publishVideoTrack(localVideo); ``` ### Rendering video @@ -116,7 +125,7 @@ Widget build(BuildContext context) { ### Audio handling -Audio tracks are rendered automatically as long as you are subscribed to them. +Audio tracks are played automatically as long as you are subscribed to them. ### Handling changes diff --git a/example/lib/pages/connect.dart b/example/lib/pages/connect.dart index 076694e..e5857a1 100644 --- a/example/lib/pages/connect.dart +++ b/example/lib/pages/connect.dart @@ -26,7 +26,7 @@ class _ConnectPageState extends State { final _uriCtrl = TextEditingController(); final _tokenCtrl = TextEditingController(); - bool _simulcast = false; + bool _simulcast = true; bool _busy = false; @override @@ -48,7 +48,7 @@ class _ConnectPageState extends State { _uriCtrl.text = prefs.getString(_storeKeyUri) ?? ''; _tokenCtrl.text = prefs.getString(_storeKeyToken) ?? ''; setState(() { - _simulcast = prefs.getBool(_storeKeySimulcast) ?? false; + _simulcast = prefs.getBool(_storeKeySimulcast) ?? true; }); } diff --git a/example/lib/pages/room.dart b/example/lib/pages/room.dart index f5340ae..6903bce 100644 --- a/example/lib/pages/room.dart +++ b/example/lib/pages/room.dart @@ -68,19 +68,17 @@ class _RoomPageState extends State { if (result != true) return; // video will fail when running in ios simulator try { - // Create video track - final localVideo = await LocalVideoTrack.createCameraTrack(); - // Try to publish the video - await widget.room.localParticipant.publishVideoTrack(localVideo); - - // Create mic track - final localAudio = await LocalAudioTrack.create(); - // // Try to publish audio - await widget.room.localParticipant.publishAudioTrack(localAudio); + await widget.room.localParticipant.setCameraEnabled(true); } catch (error) { print('could not publish video: $error'); await context.showErrorDialog(error); } + try { + await widget.room.localParticipant.setMicrophoneEnabled(true); + } catch (error) { + print('could not publish audio: $error'); + await context.showErrorDialog(error); + } } void _onRoomDidUpdate() { diff --git a/example/lib/widgets/controls.dart b/example/lib/widgets/controls.dart index 3026b06..f0af946 100644 --- a/example/lib/widgets/controls.dart +++ b/example/lib/widgets/controls.dart @@ -53,47 +53,18 @@ class _ControlsWidgetState extends State { void _disableAudio() async { await participant.setMicrophoneEnabled(false); - // The following code is an example how to mute a track - // if (participant.hasAudio) { - // final audioPub = participant.audioTracks.first; - // audioPub.muted = true; - // } } Future _enableAudio() async { await participant.setMicrophoneEnabled(true); - // The following code is an example how to unmute / publish a audio track - // if (participant.hasAudio) { - // final audioPub = participant.audioTracks.first; - // audioPub.muted = false; - // } else { - // // publish audio track - // final audioTrack = await LocalAudioTrack.create(); - // await participant.publishAudioTrack(audioTrack); - // } } void _disableVideo() async { await participant.setCameraEnabled(false); - // The following code is an example how to mute a video track - // if (participant.hasVideo) { - // final videoPub = participant.videoTracks.first; - // videoPub.muted = true; - // } } void _enableVideo() async { await participant.setCameraEnabled(true); - // The following code is an example how to unmute / publish a video track - // if (participant.hasVideo) { - // print('Un-muting video'); - // final videoPub = participant.videoTracks.first; - // videoPub.muted = false; - // } else { - // // publish audio track - // final videoTrack = await LocalVideoTrack.createCameraTrack(); - // await participant.publishVideoTrack(videoTrack); - // } } void _toggleCamera() async {