Skip to content
Media client

Connect and publish

Connect to a room, publish a camera and microphone, and share the screen.

Audio engine setup

The native media engine is built once per process, and whatever touches it first decides its audio profile. Call this first in main():

import 'package:flutter/widgets.dart';
import 'package:voxera_media_client/voxera_media_client.dart';
 
class MyApp extends StatelessWidget {
  const MyApp({super.key});
 
  @override
  Widget build(BuildContext context) => const SizedBox();
}
 
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await VoxeraMediaClient.initializeForRoom();
  runApp(const MyApp());
}

That keeps echo cancellation on. Listeners stay on a media session, and publishing a microphone uses the communication session and the loudspeaker.

Don't call initialize(mediaAudioProfile: true), because it turns echo cancellation off for the rest of the process. If the console shows [VoxeraMediaClient] the media engine was already initialized, something ran before this line.

Connect

Get url and token from the Token API. Always use the url from the response, not a saved one.

final room = Room(
  roomOptions: const RoomOptions(
    adaptiveStream: true,
    dynacast: true,
  ),
);
 
// Optional. This speeds up connecting.
await room.prepareConnection(url, token);
 
await room.connect(url, token);

Publish

try {
  // Video fails in the iOS simulator.
  await room.localParticipant?.setCameraEnabled(true);
} catch (error) {
  debugPrint('Could not publish video: $error');
}
 
await room.localParticipant?.setMicrophoneEnabled(true);

Whether a user may publish depends on their role. See Stage and roles and Seats and speakers.

Share the screen

await room.localParticipant?.setScreenShareEnabled(true);

Mute a local track

Call mute() and unmute() on a LocalTrackPublication, and read muted for its state. Each change emits TrackMutedEvent or TrackUnmutedEvent.

await trackPub.mute();
await trackPub.unmute();