fetchToken method

Future<void> fetchToken()

Implementation

Future<void> fetchToken() async {
  if (_chat.model.hasJoined) return;
  if (_chat.model.curCall == null ||
      _rtc.agoraAppId == null ||
      rtcTokenHandler == null) return;

  Map<String, int> agoraToken = await rtcTokenHandler!.call(
    _chat.model.curCall!.channel,
    _rtc.agoraAppId!,
  );

  if (_chat.model.curCall == null || agoraToken.isEmpty) return;

  String? username = ChatClient.getInstance.currentUserId;

  if (username == null) return;

  await _rtc.joinChannel(
    _chat.model.curCall!.callType,
    agoraToken.keys.first,
    _chat.model.curCall!.channel,
    _chat.model.agoraUid ?? agoraToken.values.first,
  );
}