Use high level track APIs in example app & docs (#36)

This commit is contained in:
David Zhao
2021-11-26 23:51:37 -08:00
committed by GitHub
parent c50e0269cf
commit 66dbc94c1a
4 changed files with 23 additions and 45 deletions
+14 -5
View File
@@ -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
+2 -2
View File
@@ -26,7 +26,7 @@ class _ConnectPageState extends State<ConnectPage> {
final _uriCtrl = TextEditingController();
final _tokenCtrl = TextEditingController();
bool _simulcast = false;
bool _simulcast = true;
bool _busy = false;
@override
@@ -48,7 +48,7 @@ class _ConnectPageState extends State<ConnectPage> {
_uriCtrl.text = prefs.getString(_storeKeyUri) ?? '';
_tokenCtrl.text = prefs.getString(_storeKeyToken) ?? '';
setState(() {
_simulcast = prefs.getBool(_storeKeySimulcast) ?? false;
_simulcast = prefs.getBool(_storeKeySimulcast) ?? true;
});
}
+7 -9
View File
@@ -68,19 +68,17 @@ class _RoomPageState extends State<RoomPage> {
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() {
-29
View File
@@ -53,47 +53,18 @@ class _ControlsWidgetState extends State<ControlsWidget> {
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<void> _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 {