stateChanged method
Implementation
void stateChanged(
ChatCallKitCallState newState, ChatCallKitCallState preState) async {
switch (newState) {
case ChatCallKitCallState.idle:
{
tools.log("ChatCallKitManagerImpl:stateChanged: state changed to idle");
await _chat.clearCurrentCallInfo();
await _rtc.clearCurrentCallInfo();
}
break;
case ChatCallKitCallState.outgoing:
{
tools.log("ChatCallKitManagerImpl:stateChanged: state changed to outgoing");
if (_chat.model.curCall == null) return;
if (_chat.model.curCall?.callType != ChatCallKitCallType.audio_1v1) {
await _rtc.enableVideo();
await _rtc.startPreview();
}
try {
await fetchToken();
} on ChatCallKitError catch (e) {
onError(e);
}
}
break;
case ChatCallKitCallState.alerting:
{
tools.log("ChatCallKitManagerImpl:stateChanged: state changed to alerting");
if (_chat.model.curCall == null) return;
await _rtc.initEngine();
tools.log("ChatCallKitManagerImpl: initEngine called");
if (_chat.model.curCall != null) {
if (_chat.model.curCall!.callType !=
ChatCallKitCallType.audio_1v1) {
tools.log("ChatCallKitManagerImpl: enable video");
await _rtc.enableVideo();
await _rtc.startPreview();
}
for (var value in handlers) {
tools.log(
"ChatCallKitManagerImpl: onReceiveCall called, "
"remoteUserAccount: ${_chat.model.curCall!.remoteUserAccount}, "
"callId: ${_chat.model.curCall!.callId}, "
"callType: ${_chat.model.curCall!.callType}, "
"ext: ${_chat.model.curCall!.ext}"
);
value.onReceiveCall.call(
_chat.model.curCall!.remoteUserAccount!,
_chat.model.curCall!.callId,
_chat.model.curCall!.callType,
_chat.model.curCall!.ext,
);
}
}
}
break;
case ChatCallKitCallState.answering:
{
tools.log("ChatCallKitManagerImpl:stateChanged: state changed to answering");
if (_chat.model.curCall == null) return;
if (_chat.model.curCall!.callType == ChatCallKitCallType.multi &&
_chat.model.curCall!.isCaller) {
// 多人主叫时,需要开启摄像头
tools.log("ChatCallKitManagerImpl: enable video");
await _rtc.enableVideo();
await _rtc.startPreview();
try {
tools.log("ChatCallKitManagerImpl: fetchToken called");
await fetchToken();
} on ChatCallKitError catch (e) {
onError(e);
}
}
}
break;
}
}