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