|
|
|
@ -1,46 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:diplomaticquarterapp/config/config.dart';
|
|
|
|
import 'package:diplomaticquarterapp/config/config.dart';
|
|
|
|
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
|
|
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
|
|
import 'package:diplomaticquarterapp/models/LiveCare/IncomingCallData.dart';
|
|
|
|
import 'package:diplomaticquarterapp/models/LiveCare/IncomingCallData.dart';
|
|
|
|
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
|
|
|
|
import 'package:diplomaticquarterapp/pages/landing/landing_page.dart';
|
|
|
|
import 'package:diplomaticquarterapp/pages/livecare/incoming_call.dart';
|
|
|
|
import 'package:diplomaticquarterapp/pages/livecare/incoming_call.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app-permissions.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app-permissions.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:huawei_push/huawei_push.dart' as h_push;
|
|
|
|
|
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart' as fir;
|
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart' as fir;
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart';
|
|
|
|
import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:huawei_push/huawei_push.dart' as h_push;
|
|
|
|
|
|
|
|
|
|
|
|
import 'app_shared_preferences.dart';
|
|
|
|
import 'app_shared_preferences.dart';
|
|
|
|
import 'navigation_service.dart';
|
|
|
|
import 'navigation_service.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// |--> Push Notification Background
|
|
|
|
// |--> Push Notification Background
|
|
|
|
Future<dynamic> backgroundMessageHandler(dynamic message) async {
|
|
|
|
Future<dynamic> backgroundMessageHandler(dynamic message) async {
|
|
|
|
|
|
|
|
|
|
|
|
fir.RemoteMessage message_;
|
|
|
|
fir.RemoteMessage message_;
|
|
|
|
if(message is h_push.RemoteMessage){ // if huawei remote message convert it to Firebase Remote Message
|
|
|
|
if (message is h_push.RemoteMessage) {
|
|
|
|
|
|
|
|
// if huawei remote message convert it to Firebase Remote Message
|
|
|
|
message_ = toFirebaseRemoteMessage(message);
|
|
|
|
message_ = toFirebaseRemoteMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (message_.data != null && message_.data['is_call'] == 'true') {
|
|
|
|
if (message.data != null && message.data['is_call'] == 'true') {
|
|
|
|
_incomingCall(message_.data);
|
|
|
|
_incomingCall(message.data);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
h_push.Push.localNotification({
|
|
|
|
h_push.Push.localNotification({h_push.HMSLocalNotificationAttr.TITLE: 'Background Message', h_push.HMSLocalNotificationAttr.MESSAGE: "By: BackgroundMessageHandler"});
|
|
|
|
h_push.HMSLocalNotificationAttr.TITLE: 'Background Message',
|
|
|
|
|
|
|
|
h_push.HMSLocalNotificationAttr.MESSAGE: "By: BackgroundMessageHandler"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Push Notification Background <--|
|
|
|
|
// Push Notification Background <--|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RemoteMessage toFirebaseRemoteMessage(h_push.RemoteMessage message) {
|
|
|
|
RemoteMessage toFirebaseRemoteMessage(h_push.RemoteMessage message) {
|
|
|
|
final payload_data = jsonDecode(message.data);
|
|
|
|
final payload_data = jsonDecode(message.data);
|
|
|
|
final fire_message = RemoteMessage(
|
|
|
|
final fire_message = RemoteMessage(
|
|
|
|
@ -71,19 +63,19 @@ RemoteMessage toFirebaseRemoteMessage(h_push.RemoteMessage message){
|
|
|
|
ticker: message.notification.ticker,
|
|
|
|
ticker: message.notification.ticker,
|
|
|
|
tag: message.notification.tag,
|
|
|
|
tag: message.notification.tag,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
));
|
|
|
|
);
|
|
|
|
|
|
|
|
return fire_message;
|
|
|
|
return fire_message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_incomingCall(Map data) async {
|
|
|
|
_incomingCall(Map data) async {
|
|
|
|
|
|
|
|
print("_incomingCall CALLED!!!!!! $data");
|
|
|
|
|
|
|
|
// print(ModalRoute.of(currentContext).settings.name);
|
|
|
|
LandingPage.incomingCallData = IncomingCallData.fromJson(data);
|
|
|
|
LandingPage.incomingCallData = IncomingCallData.fromJson(data);
|
|
|
|
if (LandingPage.isOpenCallPage == false) {
|
|
|
|
if (LandingPage.isOpenCallPage == false) {
|
|
|
|
LandingPage.isOpenCallPage = true;
|
|
|
|
LandingPage.isOpenCallPage = true;
|
|
|
|
final permited = await AppPermission.askVideoCallPermission(currentContext);
|
|
|
|
final permited = await AppPermission.askVideoCallPermission(currentContext);
|
|
|
|
if(permited)
|
|
|
|
if (permited) await NavigationService.navigateToPage(IncomingCall(incomingCallData: LandingPage.incomingCallData));
|
|
|
|
await NavigationService.navigateToPage(IncomingCall(incomingCallData: LandingPage.incomingCallData));
|
|
|
|
// LandingPage.isOpenCallPage = false;
|
|
|
|
LandingPage.isOpenCallPage = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await Future.delayed(Duration(milliseconds: 500));
|
|
|
|
await Future.delayed(Duration(milliseconds: 500));
|
|
|
|
await AppSharedPreferences().remove('call_data');
|
|
|
|
await AppSharedPreferences().remove('call_data');
|
|
|
|
@ -102,11 +94,11 @@ class PushNotificationHandler{
|
|
|
|
init() async {
|
|
|
|
init() async {
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
final permission = await FirebaseMessaging.instance.requestPermission();
|
|
|
|
final permission = await FirebaseMessaging.instance.requestPermission();
|
|
|
|
if(permission.authorizationStatus == AuthorizationStatus.denied)
|
|
|
|
if (permission.authorizationStatus == AuthorizationStatus.denied) return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(Platform.isAndroid && (await FlutterHmsGmsAvailability.isHmsAvailable)) { // 'Android HMS' (Handle Huawei Push_Kit Streams)
|
|
|
|
if (Platform.isAndroid && (await FlutterHmsGmsAvailability.isHmsAvailable)) {
|
|
|
|
|
|
|
|
// 'Android HMS' (Handle Huawei Push_Kit Streams)
|
|
|
|
|
|
|
|
|
|
|
|
h_push.Push.enableLogger();
|
|
|
|
h_push.Push.enableLogger();
|
|
|
|
final result = await h_push.Push.setAutoInitEnabled(true);
|
|
|
|
final result = await h_push.Push.setAutoInitEnabled(true);
|
|
|
|
@ -119,16 +111,14 @@ class PushNotificationHandler{
|
|
|
|
newMessage(toFirebaseRemoteMessage(message));
|
|
|
|
newMessage(toFirebaseRemoteMessage(message));
|
|
|
|
}, onError: (e) => print(e.toString()));
|
|
|
|
}, onError: (e) => print(e.toString()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h_push.Push.getTokenStream.listen((token) {
|
|
|
|
h_push.Push.getTokenStream.listen((token) {
|
|
|
|
onToken(token);
|
|
|
|
onToken(token);
|
|
|
|
}, onError: (e) => print(e.toString()));
|
|
|
|
}, onError: (e) => print(e.toString()));
|
|
|
|
await h_push.Push.getToken('');
|
|
|
|
await h_push.Push.getToken('');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h_push.Push.registerBackgroundMessageHandler(backgroundMessageHandler);
|
|
|
|
h_push.Push.registerBackgroundMessageHandler(backgroundMessageHandler);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
}else{ // 'Android GMS or iOS' (Handle Firebase Messaging Streams)
|
|
|
|
// 'Android GMS or iOS' (Handle Firebase Messaging Streams)
|
|
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
|
|
|
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
|
|
|
newMessage(message);
|
|
|
|
newMessage(message);
|
|
|
|
@ -145,16 +135,12 @@ class PushNotificationHandler{
|
|
|
|
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
|
|
|
|
|
|
|
|
final fcmToken = await FirebaseMessaging.instance.getToken();
|
|
|
|
final fcmToken = await FirebaseMessaging.instance.getToken();
|
|
|
|
if(fcmToken != null)
|
|
|
|
if (fcmToken != null) onToken(fcmToken);
|
|
|
|
onToken(fcmToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newMessage(RemoteMessage remoteMessage) {
|
|
|
|
newMessage(RemoteMessage remoteMessage) {
|
|
|
|
if(remoteMessage.data['is_call'] == 'true' || remoteMessage.data['is_call'] == true)
|
|
|
|
if (remoteMessage.data['is_call'] == 'true' || remoteMessage.data['is_call'] == true) _incomingCall(remoteMessage.data);
|
|
|
|
_incomingCall(remoteMessage.data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onToken(String token) async {
|
|
|
|
onToken(String token) async {
|
|
|
|
@ -169,7 +155,6 @@ class PushNotificationHandler{
|
|
|
|
_incomingCall(call_data);
|
|
|
|
_incomingCall(call_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* todo verify all functionality */
|
|
|
|
/* todo verify all functionality */
|
|
|
|
|