toggleCloudRecording function

Future<void> toggleCloudRecording({
  1. required AgoraClient client,
})

Function to start and stop cloud recording

Implementation

Future<void> toggleCloudRecording({required AgoraClient client}) async {
  if (client.sessionController.value.isCloudRecording ==
      RecordingState.recording) {
    //stop cloud recording
    client.sessionController.value = client.sessionController.value.copyWith(
      isCloudRecording: RecordingState.loading,
    );
    await client.sessionController
        .stopCloudRecording(connectionData: client.agoraConnectionData);
    client.sessionController.value = client.sessionController.value.copyWith(
      isCloudRecording: RecordingState.off,
    );
  } else if (client.sessionController.value.isCloudRecording ==
      RecordingState.off) {
    //start cloud recording
    client.sessionController.value = client.sessionController.value.copyWith(
      isCloudRecording: RecordingState.loading,
    );
    await client.sessionController
        .startCloudRecording(connectionData: client.agoraConnectionData);
    client.sessionController.value = client.sessionController.value.copyWith(
      isCloudRecording: RecordingState.recording,
    );
  } else {
    //do nothing
  }
}