fcmCallMessageCallBack function
Future<void>
fcmCallMessageCallBack({
- BuildContext? context,
- String? where,
- RemoteMessage? message,
- dynamic error()?,
- dynamic callBack()?,
Implementation
Future<void> fcmCallMessageCallBack({
BuildContext? context,
String? where,
RemoteMessage? message,
Function(String)? error,
Function(CallModel)? callBack,
}) async {
try {
if (message == null) return;
showLogI('========Firebase message:=========');
if (message.data.isNotEmpty && message.data['callId'] != null) {
showLogL(json.encode(message.data));
var _callId = message.data['callId'] ?? "";
callType = message.data['callType'] ?? "";
roomName = message.data['roomName'] ?? "";
// String updateAt = message.data['updatedAt'].toString() ?? "";
if (isCheckTimerCall("")) {
Future.delayed(const Duration(seconds: 2), () async {
if (roomName != null && callType != "chat") {
final data = MappingModelHelper.mapFirebaseCall(message, where);
if (data != null) {
final status = data.status ?? "";
if (isCheckRoom(status: status, currentRoomName: currentRoomName, roomName: roomName)) {
switch (status) {
case 'actionCallIncoming':
showLogI('Firebase=====>>>>>actionCallIncoming<<<<<=====');
if (where == "onBackground") {
await showCallkitIncoming(currentuuid!, roomName ?? "", data: message.data);
}
break;
case 'actionCallStart':
showLogI('Firebase======>>>>>actionCallStart<<<<<========');
onStartCall(_callId, data, status: status);
break;
case 'actionCallAccept':
showLogI('Firebase====>>>>>actionCallAccept<<<<<======');
onAcceptCall(_callId, status: status);
break;
case 'actionCallEnd':
showLogI('Firebase=====>>>>>actionCallEnd<<<<<=========');
await onEndCall(_callId, status: status, where: where);
break;
case 'actionCallDecline':
showLogI('Firebase=====>>>>>actionCallDecline<<<<<======');
await onEndCall(_callId, status: status, where: where);
break;
case 'actionCallTimeout':
showLogI('Firebase======>>>>>actionCallTimeout<<<<<======');
showSnackbarInfo(context, content: "Cuộc gọi bị timeout, vui lòng thử lại");
await onEndCall(_callId, status: status, where: where);
break;
case 'actionCallFailed':
showLogI('Firebase=====>>>>>actionCallFailed<<<<<========');
showSnackbarInfo(context, content: "Cuộc gọi bị lỗi");
await onEndCall(_callId, status: status, where: where);
break;
}
if (callBack != null) {
callId = _callId;
return callBack(data);
}
} else {
if (error != null) {
error(StatusHelper.getMessageCallError(errorCode: 507));
}
}
}
}
});
showLogI('=========================================================');
}
} else {
NotificationHelper.showNotification(message: message);
}
} catch (e) {
showLogE(e.toString(), className: "fcmCallMessageCallBack - CallHelper");
}
}