joinVideoChannel method

Future<void> joinVideoChannel()

Function to join the video call.

Implementation

Future<void> joinVideoChannel() async {
  if (value.layoutType == Layout.oneToOne && value.users.length == 1) return;

  // [generatedRtmId] is the unique ID for a user generated using the timestamp in milliseconds.
  value = value.copyWith(
    generatedRtmId: value.connectionData!.rtmUid ??
        DateTime.now().millisecondsSinceEpoch.toString(),
  );
  await value.engine?.setParameters("{\"rtc.using_ui_kit\": 1}");
  await value.engine?.enableVideo();
  await value.engine?.enableAudioVolumeIndication(
      interval: 200, smooth: 3, reportVad: true);
  if (value.connectionData?.tokenUrl != null) {
    await getToken(
      tokenUrl: value.connectionData!.tokenUrl,
      channelName: value.connectionData!.channelName,
      uid: value.connectionData!.uid,
      sessionController: this,
    );
    if (value.connectionData!.rtmEnabled) {
      await getRtmToken(
        tokenUrl: value.connectionData!.tokenUrl,
        sessionController: this,
      );
    }
  }

  await value.engine?.startPreview();

  await value.engine?.joinChannel(
    token: value.connectionData?.tempToken ?? value.generatedToken ?? "",
    channelId: value.connectionData!.channelName,
    uid: value.connectionData!.uid!,
    options: ChannelMediaOptions(
      channelProfile: ChannelProfileType.channelProfileLiveBroadcasting,
      clientRoleType: ClientRoleType.clientRoleBroadcaster,
    ),
  );
}