startInviteUsers method

Future<String> startInviteUsers(
  1. List<String> userIds,
  2. Map<String, String>? ext
)

Implementation

Future<String> startInviteUsers(
  List<String> userIds,
  Map<String, String>? ext,
) async {
  if (userIds.isEmpty) {
    throw ChatCallKitError.process(
        ChatCallKitErrorProcessCode.invalidParam, 'Require remote userId');
  }

  if (model.curCall != null) {
    for (var element in userIds) {
      if (model.curCall!.allUserAccounts.values.contains(element)) {
        continue;
      }
      sendInviteMsgToCallee(
        element,
        model.curCall!.callType,
        model.curCall!.callId,
        model.curCall!.channel,
        ext,
      );

      callTimerDic[element] = Timer.periodic(timeoutDuration, (timer) {
        timer.cancel();
        callTimerDic.remove(element);
        if (model.curCall != null) {
          sendCancelCallMsgToCallee(element, model.curCall!.callId);
          removeUser(element, ChatCallKitCallEndReason.remoteNoResponse);
        }
      });
    }
  } else {
    model.curCall = ChatCallKitCall(
      callId: ChatCallKitTools.randomStr,
      callType: ChatCallKitCallType.multi,
      isCaller: true,
      channel: ChatCallKitTools.randomStr,
      ext: ext,
    );

    model.state = ChatCallKitCallState.answering;
    for (var element in userIds) {
      sendInviteMsgToCallee(
        element,
        model.curCall!.callType,
        model.curCall!.callId,
        model.curCall!.channel,
        ext,
      );

      callTimerDic[element] = Timer.periodic(timeoutDuration, (timer) {
        timer.cancel();
        callTimerDic.remove(element);
        if (model.curCall != null) {
          sendCancelCallMsgToCallee(element, model.curCall!.callId);
          removeUser(element, ChatCallKitCallEndReason.remoteNoResponse);
        }
      });
    }
  }

  return model.curCall!.callId;
}