switchCamera method

Future<void> switchCamera()

Changes the local video device to the next one from the OngoingCall.devices list.

Implementation

Future<void> switchCamera() async {
  if (PlatformUtils.isMobile) {
    keepUi();
  }

  final List<DeviceDetails> cameras =
      _currentCall.value.devices.video().toList();
  if (cameras.length > 1) {
    final DeviceDetails? videoDevice = _currentCall.value.videoDevice.value;
    int selected =
        videoDevice == null
            ? 0
            : cameras.indexWhere(
              (e) => e.deviceId() == videoDevice.deviceId(),
            );
    selected += 1;
    cameraSwitched.toggle();
    await _currentCall.value.setVideoDevice(
      cameras[selected % cameras.length],
    );
  }
}