startSingleCall method
Implementation
Future<String> startSingleCall(
String userId, {
ChatCallKitCallType type = ChatCallKitCallType.audio_1v1,
int? agoraUid,
Map<String, String>? ext,
}) async {
if (userId.isEmpty) {
throw ChatCallKitError.process(
ChatCallKitErrorProcessCode.invalidParam, 'Require remote userId');
}
if (busy) {
throw ChatCallKitError.process(
ChatCallKitErrorProcessCode.busy, 'Current is busy');
}
model.curCall = ChatCallKitCall(
callId: ChatCallKitTools.randomStr,
channel: ChatCallKitTools.randomStr,
remoteUserAccount: userId,
callType: type,
isCaller: true,
ext: ext,
);
model.state = ChatCallKitCallState.outgoing;
await sendInviteMsgToCallee(userId, type, model.curCall?.callId ?? "",
model.curCall?.channel ?? "", ext);
if (!callTimerDic.containsKey(userId)) {
callTimerDic[userId] = Timer.periodic(
timeoutDuration,
(timer) {
timer.cancel();
callTimerDic.remove(userId);
if (model.curCall != null) {
sendCancelCallMsgToCallee(userId, model.curCall!.callId);
if (model.curCall!.callType != ChatCallKitCallType.multi) {
handler.onCallEndReason(model.curCall!.callId,
ChatCallKitCallEndReason.remoteNoResponse);
model.state = ChatCallKitCallState.idle;
}
}
},
);
}
return model.curCall!.callId;
}