Use high level track APIs in example app & docs (#36)
This commit is contained in:
@@ -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);
|
var room = await LiveKitClient.connect(url, token);
|
||||||
try {
|
try {
|
||||||
// video will fail when running in ios simulator
|
// video will fail when running in ios simulator
|
||||||
var localVideo = await LocalVideoTrack.createCameraTrack();
|
await room.localParticipant.setCameraEnabled(true);
|
||||||
await room.localParticipant.publishVideoTrack(localVideo);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('could not publish video: $e');
|
print('could not publish video: $e');
|
||||||
}
|
}
|
||||||
|
|
||||||
var localAudio = await LocalAudioTrack.createTrack();
|
await room.localParticipant.setMicrophoneEnabled(true);
|
||||||
await room.localParticipant.publishAudioTrack(localAudio);
|
```
|
||||||
|
|
||||||
|
### 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
|
### Rendering video
|
||||||
@@ -116,7 +125,7 @@ Widget build(BuildContext context) {
|
|||||||
|
|
||||||
### Audio handling
|
### 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
|
### Handling changes
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class _ConnectPageState extends State<ConnectPage> {
|
|||||||
|
|
||||||
final _uriCtrl = TextEditingController();
|
final _uriCtrl = TextEditingController();
|
||||||
final _tokenCtrl = TextEditingController();
|
final _tokenCtrl = TextEditingController();
|
||||||
bool _simulcast = false;
|
bool _simulcast = true;
|
||||||
bool _busy = false;
|
bool _busy = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -48,7 +48,7 @@ class _ConnectPageState extends State<ConnectPage> {
|
|||||||
_uriCtrl.text = prefs.getString(_storeKeyUri) ?? '';
|
_uriCtrl.text = prefs.getString(_storeKeyUri) ?? '';
|
||||||
_tokenCtrl.text = prefs.getString(_storeKeyToken) ?? '';
|
_tokenCtrl.text = prefs.getString(_storeKeyToken) ?? '';
|
||||||
setState(() {
|
setState(() {
|
||||||
_simulcast = prefs.getBool(_storeKeySimulcast) ?? false;
|
_simulcast = prefs.getBool(_storeKeySimulcast) ?? true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,19 +68,17 @@ class _RoomPageState extends State<RoomPage> {
|
|||||||
if (result != true) return;
|
if (result != true) return;
|
||||||
// video will fail when running in ios simulator
|
// video will fail when running in ios simulator
|
||||||
try {
|
try {
|
||||||
// Create video track
|
await widget.room.localParticipant.setCameraEnabled(true);
|
||||||
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);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
print('could not publish video: $error');
|
print('could not publish video: $error');
|
||||||
await context.showErrorDialog(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() {
|
void _onRoomDidUpdate() {
|
||||||
|
|||||||
@@ -53,47 +53,18 @@ class _ControlsWidgetState extends State<ControlsWidget> {
|
|||||||
|
|
||||||
void _disableAudio() async {
|
void _disableAudio() async {
|
||||||
await participant.setMicrophoneEnabled(false);
|
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 {
|
Future<void> _enableAudio() async {
|
||||||
await participant.setMicrophoneEnabled(true);
|
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 {
|
void _disableVideo() async {
|
||||||
await participant.setCameraEnabled(false);
|
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 {
|
void _enableVideo() async {
|
||||||
await participant.setCameraEnabled(true);
|
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 {
|
void _toggleCamera() async {
|
||||||
|
|||||||
Reference in New Issue
Block a user