onCallUpdate method
Implementation
Future<void> onCallUpdate(final CallUpdate callUpdate) async {
final context = NavigationService().context;
_dialedNumber = callUpdate.call.remote_identity ?? 'Unknown';
switch (callUpdate.callState.state) {
case CallStateEnum.CALL_INITIATION:
call = callUpdate;
update(['call-area']);
if (context != null) {
AutoRouter.of(context)
.push(OutgoingCallRoute(dialedNumber: _dialedNumber));
}
break;
case CallStateEnum.ACCEPTED:
call = callUpdate;
update(['call-area']);
break;
case CallStateEnum.CONFIRMED:
call = callUpdate;
update(['call-area']);
if (context != null) {
AutoRouter.of(context)
.push(OngoingCallRoute(dialedNumber: _dialedNumber));
}
break;
case CallStateEnum.ENDED:
case CallStateEnum.FAILED:
call = null;
update(['call-area']);
if (context != null) {
AutoRouter.of(context).push(Home());
CherryToast(
icon: Icons.call_end,
themeColor: Colors.pink,
description:
Text("Call Ended", style: TextStyle(color: Colors.black)),
toastPosition: Position.bottom,
animationDuration: Duration(seconds: 10),
autoDismiss: true)
.show(context);
}
break;
case CallStateEnum.PROGRESS:
call = callUpdate;
update(['call-area']);
final String callDirection = callUpdate.call.direction;
if (context != null) {
if (callDirection == 'INCOMING' &&
MobileSdkRouter().currentPath !=
MobileSdkRouter.incomingCallRoute) {
AutoRouter.of(context).push(IncomingCallRoute());
} else if (callDirection == 'OUTGOING' &&
MobileSdkRouter().currentPath !=
MobileSdkRouter.outgoingCallRoute) {
AutoRouter.of(context)
.push(OutgoingCallRoute(dialedNumber: _dialedNumber));
}
}
break;
case CallStateEnum.STREAM:
call = callUpdate;
update(['call-area']);
break;
case CallStateEnum.HOLD:
case CallStateEnum.UNHOLD:
case CallStateEnum.MUTED:
case CallStateEnum.UNMUTED:
call = callUpdate;
update(['call-area']);
break;
case CallStateEnum.NONE:
call = callUpdate;
update(['call-area']);
break;
case CallStateEnum.CONNECTING:
call = callUpdate;
update(['call-area']);
break;
case CallStateEnum.REFER:
call = callUpdate;
update(['call-area']);
break;
}
}