initCometChatCalls method

  1. @override
void initCometChatCalls(
  1. CallAppSettings callAppSettings,
  2. dynamic onSuccess(
    1. String success
    ),
  3. dynamic onError(
    1. CometChatCallsException e
    )
)
override

Implementation

@override
void initCometChatCalls(callAppSettings, onSuccess, onError) async {
  try {
    CometChatCallsUtils.showLog(tag, "initCometChatCalls: CALLED");
    if (callAppSettings.appId == null) {
      onError(CometChatCallsException(
          CometChatCallsConstants.codeCometChatCallsSDKInitError,
          "App ID is null, please set the App Id first",
          "App ID is null, please set the App Id first"));
    } else if (callAppSettings.region == null) {
      onError(CometChatCallsException(
          CometChatCallsConstants.codeCometChatCallsSDKInitError,
          "Region is null, please set the region first",
          "App ID is null, please set the App Id first"));
    } else {
      final result =
          await methodChannel.invokeMethod<Map>('initCometChatCalls', {
        "appID": callAppSettings.appId,
        "region": callAppSettings.region,
        "host": callAppSettings.host
      });
      CometChatCallsUtils.showLog(tag, "initCometChatCalls: RESULT: $result");
      if (result == null) {
        onError(CometChatCallsException(
            CometChatCallsConstants.codeCometChatCallsSDKInitError,
            "CometChatCalls SDK is not initialized, requested result is null",
            "CometChatCalls SDK is not initialized, requested result is null"));
      } else {
        ApiConnection.callAppSettings = callAppSettings;
        isSDKInitialized = true;
        onSuccess(result["message"]);
      }
    }
  } on PlatformException catch (platformException) {
    onError(CometChatCallsException(platformException.code,
        platformException.message, platformException.details));
  } catch (e) {
    onError(CometChatCallsException(
        CometChatCallsConstants.codeError, e.toString(), e.toString()));
  }
}