call.flipCamera();
call.setCameraPosition(CameraPosition.front);
call.setCameraEnabled(enabled: false);
Camera and Microphone
Working with hardware devices can always have some level of complexity to it but the SDK does a lot to abstract the complexities and expose an intuitive interface for querying the connected devices and changing them throughout the call.
As a reminder, before attempting to access the user’s connected devices,
please ensure the appropriate permissions are set in both the iOS plist
file
and Android Manifest.
Camera Operations
Conveniently attached to the Call
class are a series of methods which can be used to flip the device’s camera, set the camera position, and disable the camera all together.
You can fetch the current camera via the call state:
var camera = call.state.value.videoInputDevice;
Audio Operations
Similar the Camera API, the Call
object also includes methods for performing audio actions like disabling the audio devices, configuring the audio input device and audio output device.
call.setAudioInputDevice(device);
call.setAudioOutputDevice(device);
call.setMicrophoneEnabled(enabled: true);
You can fetch the current input and output device via the call state:
var microphone = call.state.value.audioInputDevice;
var speaker = call.state.value.audioOutputDevice;
Listing Connected Devices
There may be cases where it becomes necessary to query all of the connected devices or listen to hardware changes such as when the user connects a new microphone or camera to their machine.
For this, the RtcMediaDeviceNotifier
can be used. Encapsulated in this class are methods and listeners for interacting with all connected devices.
RtcMediaDeviceNotifier.instance.onDeviceChange.listen((devices) {
final audioInputDevice = devices.where((device) => device.kind == RtcMediaDeviceKind.audioInput);
call.setAudioInputDevice(audioInputDevice.first);
});
When you need to fetch the list of video and audio devices available on the device, you can use the RtcMediaDeviceNotifier
class:
final videoDevices = RtcMediaDeviceNotifier.instance.audioOutputs();
final outputDevices = RtcMediaDeviceNotifier.instance.audioInputs();
final inputDevices = RtcMediaDeviceNotifier.instance.videoInputs();
When it comes to audio devices, WebRTC classifies them as two types, Earpiece
and Speaker
. These can be used to sort and further filter the devices connected to your app.