initiateCall static method

void initiateCall(
  1. Call call, {
  2. int? timeout,
  3. required dynamic onSuccess(
    1. Call call
    )?,
  4. required dynamic onError(
    1. CometChatException excep
    ),
})

Implementation

static void initiateCall(Call call,
    {int? timeout,
    required Function(Call call)? onSuccess,
    required Function(CometChatException excep) onError}) async {
  try {
    if (call.receiverUid.isEmpty) {
      onError(CometChatException(
          "Error", "Receiver UID is empty", "Receiver UID must be provided"));
    } else if (call.receiverType.isEmpty) {
      onError(CometChatException(
          "Error", "Receiver type is empty", "Receiver type must be provided"));
    } else if (call.type.isEmpty) {
      onError(CometChatException(
          "Error", "Call type is empty", "Call type must be provided"));
    } else {
      Map<String, dynamic> callMap = {};
      callMap["receiverUid"] = call.receiverUid;
      callMap["receiverType"] = call.receiverType;
      callMap["callType"] = call.type;
      if (call.metadata != null && call.metadata!.isNotEmpty) {
        callMap["metadata"] = json.encode(call.metadata);
      }
      if (call.muid.isNotEmpty) {
        callMap["muid"] = call.muid;
      }
      if (timeout != null) {
        callMap["timeout"] = timeout;
      }
      var result = await channel.invokeMethod('initiateCall', callMap);
      if (onSuccess != null) onSuccess(Call.fromMap(result));
    }
  } on PlatformException catch (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
}