|
|
|
|
@ -476,166 +476,166 @@ class PushNotificationHandler {
|
|
|
|
|
} else if (status.isDenied) {
|
|
|
|
|
// Notification permissions denied
|
|
|
|
|
|
|
|
|
|
await requestPermissions();
|
|
|
|
|
await requestPermissions();
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
voIPKit.getVoIPToken().then((value) {
|
|
|
|
|
log("🎈 APNS VOIP KIT TOKEN: $value");
|
|
|
|
|
Utils.saveStringFromPrefs(CacheConst.voipToken, value ?? "");
|
|
|
|
|
// AppSharedPreferences().setString(APNS_TOKEN, value!);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
voIPKit.onDidUpdatePushToken = (String token) {
|
|
|
|
|
log('🎈 example: onDidUpdatePushToken: $token');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
voIPKit.onDidReceiveIncomingPush = (
|
|
|
|
|
Map<String, dynamic> payload,
|
|
|
|
|
) async {
|
|
|
|
|
log('🎈 example: onDidReceiveIncomingPush $payload');
|
|
|
|
|
// _timeOut();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
voIPKit.onDidRejectIncomingCall = (
|
|
|
|
|
String uuid,
|
|
|
|
|
String callerId,
|
|
|
|
|
) async {
|
|
|
|
|
try {
|
|
|
|
|
log('🎈 example: onDidRejectIncomingCall $uuid - $callerId');
|
|
|
|
|
timeOutTimer.cancel();
|
|
|
|
|
// Cleanup on reject with API call
|
|
|
|
|
if (_currentCallId != null) {
|
|
|
|
|
await _endCallAndCleanup(_currentCallId!, isDeclined: true);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
log(err.toString());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
voIPKit.onDidAcceptIncomingCall = (
|
|
|
|
|
String uuid,
|
|
|
|
|
String callerId,
|
|
|
|
|
) async {
|
|
|
|
|
log('🎈 example: onDidAcceptIncomingCall $uuid - $callerId');
|
|
|
|
|
await voIPKit.acceptIncomingCall(callerState: CallStateType.calling);
|
|
|
|
|
await voIPKit.callConnected();
|
|
|
|
|
|
|
|
|
|
// Cleanup on accept - cancel timer and reset flags
|
|
|
|
|
_callTimeoutTimer?.cancel();
|
|
|
|
|
_callTimeoutTimer = null;
|
|
|
|
|
_isCallInProgress = false;
|
|
|
|
|
_currentCallId = null;
|
|
|
|
|
await Future.delayed(Duration(seconds: 2)).then((val) async {
|
|
|
|
|
await voIPKit.endCall();
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
voIPKit.getVoIPToken().then((value) {
|
|
|
|
|
log("🎈 APNS VOIP KIT TOKEN: $value");
|
|
|
|
|
Utils.saveStringFromPrefs(CacheConst.voipToken, value ?? "");
|
|
|
|
|
// AppSharedPreferences().setString(APNS_TOKEN, value!);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Navigator.pushNamed(
|
|
|
|
|
// locator<NavigationService>().navigatorKey.currentContext!,
|
|
|
|
|
// "zoom_call_page",
|
|
|
|
|
// arguments: CallArguments("hoover-dam", "123", "Patient", "40", "1", false),
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// Navigator.pushNamed(navigatorKey.currentContext!, VIDEO_CALL_SCREEN,
|
|
|
|
|
// arguments: VideoArgus(
|
|
|
|
|
// reservationId: int.parse(callerId), token: null, isVideo: true));
|
|
|
|
|
voIPKit.onDidUpdatePushToken = (String token) {
|
|
|
|
|
log('🎈 example: onDidUpdatePushToken: $token');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
voIPKit.onDidReceiveIncomingPush = (
|
|
|
|
|
Map<String, dynamic> payload,
|
|
|
|
|
) async {
|
|
|
|
|
log('🎈 example: onDidReceiveIncomingPush $payload');
|
|
|
|
|
// _timeOut();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
voIPKit.onDidRejectIncomingCall = (
|
|
|
|
|
String uuid,
|
|
|
|
|
String callerId,
|
|
|
|
|
) async {
|
|
|
|
|
try {
|
|
|
|
|
log('🎈 example: onDidRejectIncomingCall $uuid - $callerId');
|
|
|
|
|
timeOutTimer.cancel();
|
|
|
|
|
// Cleanup on reject with API call
|
|
|
|
|
if (_currentCallId != null) {
|
|
|
|
|
await _endCallAndCleanup(_currentCallId!, isDeclined: true);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
log(err.toString());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
voIPKit.onDidAcceptIncomingCall = (
|
|
|
|
|
String uuid,
|
|
|
|
|
String callerId,
|
|
|
|
|
) async {
|
|
|
|
|
log('🎈 example: onDidAcceptIncomingCall $uuid - $callerId');
|
|
|
|
|
await voIPKit.acceptIncomingCall(callerState: CallStateType.calling);
|
|
|
|
|
await voIPKit.callConnected();
|
|
|
|
|
|
|
|
|
|
// Cleanup on accept - cancel timer and reset flags
|
|
|
|
|
_callTimeoutTimer?.cancel();
|
|
|
|
|
_callTimeoutTimer = null;
|
|
|
|
|
_isCallInProgress = false;
|
|
|
|
|
_currentCallId = null;
|
|
|
|
|
await Future.delayed(Duration(seconds: 2)).then((val) async {
|
|
|
|
|
await voIPKit.endCall();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Navigator.pushNamed(
|
|
|
|
|
// locator<NavigationService>().navigatorKey.currentContext!,
|
|
|
|
|
// "zoom_call_page",
|
|
|
|
|
// arguments: CallArguments("hoover-dam", "123", "Patient", "40", "1", false),
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// Navigator.pushNamed(navigatorKey.currentContext!, VIDEO_CALL_SCREEN,
|
|
|
|
|
// arguments: VideoArgus(
|
|
|
|
|
// reservationId: int.parse(callerId), token: null, isVideo: true));
|
|
|
|
|
|
|
|
|
|
// timeOutTimer.cancel();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// timeOutTimer.cancel();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
try {
|
|
|
|
|
final fcmToken = await FirebaseMessaging.instance.getToken().catchError((err) {
|
|
|
|
|
log(err);
|
|
|
|
|
});
|
|
|
|
|
if (fcmToken != null) onToken(fcmToken);
|
|
|
|
|
// }
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
log("Notification Exception: $ex");
|
|
|
|
|
}
|
|
|
|
|
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
try {
|
|
|
|
|
final fcmToken = await FirebaseMessaging.instance.getToken().catchError((err) {
|
|
|
|
|
log(err);
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
final permission = await FirebaseMessaging.instance.requestPermission();
|
|
|
|
|
await FirebaseMessaging.instance.getAPNSToken().then((value) async {
|
|
|
|
|
log("APNS token: $value");
|
|
|
|
|
await Utils.saveStringFromPrefs(CacheConst.apnsToken, value.toString());
|
|
|
|
|
});
|
|
|
|
|
if (fcmToken != null) onToken(fcmToken);
|
|
|
|
|
// }
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
log("Notification Exception: $ex");
|
|
|
|
|
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
|
|
|
|
|
alert: true, // Required to display a heads up notification
|
|
|
|
|
badge: true,
|
|
|
|
|
sound: true,
|
|
|
|
|
);
|
|
|
|
|
// if (permission.authorizationStatus == AuthorizationStatus.denied) return;
|
|
|
|
|
} else {
|
|
|
|
|
final permission = await FirebaseMessaging.instance.requestPermission();
|
|
|
|
|
}
|
|
|
|
|
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
final permission = await FirebaseMessaging.instance.requestPermission();
|
|
|
|
|
await FirebaseMessaging.instance.getAPNSToken().then((value) async {
|
|
|
|
|
log("APNS token: $value");
|
|
|
|
|
await Utils.saveStringFromPrefs(CacheConst.apnsToken, value.toString());
|
|
|
|
|
});
|
|
|
|
|
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
|
|
|
|
|
alert: true, // Required to display a heads up notification
|
|
|
|
|
badge: true,
|
|
|
|
|
sound: true,
|
|
|
|
|
);
|
|
|
|
|
// if (permission.authorizationStatus == AuthorizationStatus.denied) return;
|
|
|
|
|
} else {
|
|
|
|
|
final permission = await FirebaseMessaging.instance.requestPermission();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage? message) async {
|
|
|
|
|
|
|
|
|
|
if (message != null) {
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
await Future.delayed(Duration(milliseconds: 3000)).then((value) {
|
|
|
|
|
if (message != null) newMessage(message);
|
|
|
|
|
});
|
|
|
|
|
} else if (message != null) newMessage(message);
|
|
|
|
|
try {
|
|
|
|
|
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage? message) async {
|
|
|
|
|
if (message != null) {
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
await Future.delayed(Duration(milliseconds: 3000)).then((value) {
|
|
|
|
|
if (message != null) newMessage(message);
|
|
|
|
|
});
|
|
|
|
|
} else if (message != null) newMessage(message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
|
|
|
|
log("Firebase onMessage!!!");
|
|
|
|
|
// showCallkitIncoming();
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
await Future.delayed(Duration(milliseconds: 3000)).then((value) {
|
|
|
|
|
newMessage(message);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
newMessage(message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
|
|
|
|
log("Firebase onMessage!!!");
|
|
|
|
|
// showCallkitIncoming();
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
await Future.delayed(Duration(milliseconds: 3000)).then((value) {
|
|
|
|
|
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
|
|
|
|
|
log("Firebase onMessageOpenedApp!!!");
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
await Future.delayed(Duration(milliseconds: 3000)).then((value) {
|
|
|
|
|
newMessage(message);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
newMessage(message);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
newMessage(message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
|
|
|
|
|
log("Firebase onMessageOpenedApp!!!");
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
await Future.delayed(Duration(milliseconds: 3000)).then((value) {
|
|
|
|
|
newMessage(message);
|
|
|
|
|
FirebaseMessaging.instance.getAPNSToken().then((String? token) {
|
|
|
|
|
log("Push Notification getAPNSToken: ${token!}");
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
log("Push Notification getAPNSToken ERR: ${err.toString()}");
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
newMessage(message);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
FirebaseMessaging.instance.getAPNSToken().then((String? token) {
|
|
|
|
|
log("Push Notification getAPNSToken: ${token!}");
|
|
|
|
|
FirebaseMessaging.instance.getToken().then((String? token) {
|
|
|
|
|
log("Push Notification getToken: ${token!}");
|
|
|
|
|
onToken(token!);
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
log("Push Notification getAPNSToken ERR: ${err.toString()}");
|
|
|
|
|
log(err.toString());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.instance.getToken().then((String? token) {
|
|
|
|
|
log("Push Notification getToken: ${token!}");
|
|
|
|
|
onToken(token!);
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
log(err.toString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.instance.onTokenRefresh.listen((fcm_token) {
|
|
|
|
|
log("Push Notification onTokenRefresh: $fcm_token");
|
|
|
|
|
onToken(fcm_token);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
final deviceInfo = DeviceInfoPlugin();
|
|
|
|
|
final androidInfo = await deviceInfo.androidInfo;
|
|
|
|
|
|
|
|
|
|
// int sdkInt = androidInfo.version.sdkInt ?? 0;
|
|
|
|
|
// if (sdkInt >= 33) {
|
|
|
|
|
// await FlutterCallkitIncoming.requestFullIntentPermission();
|
|
|
|
|
// }
|
|
|
|
|
FirebaseMessaging.instance.onTokenRefresh.listen((fcm_token) {
|
|
|
|
|
log("Push Notification onTokenRefresh: $fcm_token");
|
|
|
|
|
onToken(fcm_token);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
final deviceInfo = DeviceInfoPlugin();
|
|
|
|
|
final androidInfo = await deviceInfo.androidInfo;
|
|
|
|
|
|
|
|
|
|
// int sdkInt = androidInfo.version.sdkInt ?? 0;
|
|
|
|
|
// if (sdkInt >= 33) {
|
|
|
|
|
// await FlutterCallkitIncoming.requestFullIntentPermission();
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|