|
|
|
@ -20,8 +20,8 @@ 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:flutter_ios_voip_kit/call_state_type.dart';
|
|
|
|
import 'package:flutter_ios_voip_kit/call_state_type.dart';
|
|
|
|
import 'package:flutter_ios_voip_kit/flutter_ios_voip_kit.dart';
|
|
|
|
import 'package:flutter_ios_voip_kit/flutter_ios_voip_kit.dart';
|
|
|
|
import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
|
|
|
|
// import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
|
|
|
|
import 'package:huawei_push/huawei_push.dart' as h_push;
|
|
|
|
// 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';
|
|
|
|
@ -30,11 +30,11 @@ import 'navigation_service.dart';
|
|
|
|
Future<dynamic> backgroundMessageHandler(dynamic message) async {
|
|
|
|
Future<dynamic> backgroundMessageHandler(dynamic message) async {
|
|
|
|
print("Firebase backgroundMessageHandler!!!");
|
|
|
|
print("Firebase backgroundMessageHandler!!!");
|
|
|
|
fir.RemoteMessage message_;
|
|
|
|
fir.RemoteMessage message_;
|
|
|
|
if (message is h_push.RemoteMessage) {
|
|
|
|
// if (message is h_push.RemoteMessage) {
|
|
|
|
// if huawei remote message convert it to Firebase Remote Message
|
|
|
|
// // if huawei remote message convert it to Firebase Remote Message
|
|
|
|
message_ = toFirebaseRemoteMessage(message);
|
|
|
|
// message_ = toFirebaseRemoteMessage(message);
|
|
|
|
h_push.Push.localNotification({h_push.HMSLocalNotificationAttr.TITLE: 'Background Message', h_push.HMSLocalNotificationAttr.MESSAGE: "By: BackgroundMessageHandler"});
|
|
|
|
// h_push.Push.localNotification({h_push.HMSLocalNotificationAttr.TITLE: 'Background Message', h_push.HMSLocalNotificationAttr.MESSAGE: "By: BackgroundMessageHandler"});
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (message.data != null && (message.data['is_call'] == 'true' || message.data['is_call'] == true)) {
|
|
|
|
if (message.data != null && (message.data['is_call'] == 'true' || message.data['is_call'] == true)) {
|
|
|
|
_incomingCall(message.data);
|
|
|
|
_incomingCall(message.data);
|
|
|
|
@ -53,39 +53,39 @@ Future<dynamic> backgroundMessageHandler(dynamic message) async {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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(
|
|
|
|
from: message.from,
|
|
|
|
// from: message.from,
|
|
|
|
collapseKey: message.collapseKey,
|
|
|
|
// collapseKey: message.collapseKey,
|
|
|
|
data: payload_data['data'],
|
|
|
|
// data: payload_data['data'],
|
|
|
|
messageId: message.messageId,
|
|
|
|
// messageId: message.messageId,
|
|
|
|
sentTime: DateTime.fromMillisecondsSinceEpoch(message.sentTime * 1000),
|
|
|
|
// sentTime: DateTime.fromMillisecondsSinceEpoch(message.sentTime * 1000),
|
|
|
|
ttl: message.ttl,
|
|
|
|
// ttl: message.ttl,
|
|
|
|
category: null,
|
|
|
|
// category: null,
|
|
|
|
messageType: message.type,
|
|
|
|
// messageType: message.type,
|
|
|
|
notification: RemoteNotification(
|
|
|
|
// notification: RemoteNotification(
|
|
|
|
title: message.notification.title,
|
|
|
|
// title: message.notification.title,
|
|
|
|
titleLocArgs: (message.notification.titleLocalizationArgs ?? []).map((e) => e.toString()).toList(),
|
|
|
|
// titleLocArgs: (message.notification.titleLocalizationArgs ?? []).map((e) => e.toString()).toList(),
|
|
|
|
titleLocKey: message.notification.titleLocalizationKey,
|
|
|
|
// titleLocKey: message.notification.titleLocalizationKey,
|
|
|
|
body: message.notification.body,
|
|
|
|
// body: message.notification.body,
|
|
|
|
bodyLocArgs: (message.notification.bodyLocalizationArgs ?? []).map((e) => e.toString()).toList(),
|
|
|
|
// bodyLocArgs: (message.notification.bodyLocalizationArgs ?? []).map((e) => e.toString()).toList(),
|
|
|
|
bodyLocKey: message.notification.bodyLocalizationKey,
|
|
|
|
// bodyLocKey: message.notification.bodyLocalizationKey,
|
|
|
|
android: AndroidNotification(
|
|
|
|
// android: AndroidNotification(
|
|
|
|
channelId: message.notification.channelId,
|
|
|
|
// channelId: message.notification.channelId,
|
|
|
|
clickAction: message.notification.clickAction,
|
|
|
|
// clickAction: message.notification.clickAction,
|
|
|
|
color: message.notification.color,
|
|
|
|
// color: message.notification.color,
|
|
|
|
count: null,
|
|
|
|
// count: null,
|
|
|
|
imageUrl: message.notification.imageUrl.path,
|
|
|
|
// imageUrl: message.notification.imageUrl.path,
|
|
|
|
link: message.notification.link.path,
|
|
|
|
// link: message.notification.link.path,
|
|
|
|
smallIcon: message.notification.icon,
|
|
|
|
// smallIcon: message.notification.icon,
|
|
|
|
sound: message.notification.sound,
|
|
|
|
// sound: message.notification.sound,
|
|
|
|
ticker: message.notification.ticker,
|
|
|
|
// ticker: message.notification.ticker,
|
|
|
|
tag: message.notification.tag,
|
|
|
|
// tag: message.notification.tag,
|
|
|
|
),
|
|
|
|
// ),
|
|
|
|
));
|
|
|
|
// ));
|
|
|
|
return fire_message;
|
|
|
|
// return fire_message;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// callPage(String sessionID, String token, String isWebrtc, String callerIdString) async {
|
|
|
|
// callPage(String sessionID, String token, String isWebrtc, String callerIdString) async {
|
|
|
|
callPage(String sessionID, String token) async {
|
|
|
|
callPage(String sessionID, String token) async {
|
|
|
|
@ -115,7 +115,7 @@ class PushNotificationHandler {
|
|
|
|
final BuildContext context;
|
|
|
|
final BuildContext context;
|
|
|
|
static PushNotificationHandler _instance;
|
|
|
|
static PushNotificationHandler _instance;
|
|
|
|
final voIPKit = FlutterIOSVoIPKit.instance;
|
|
|
|
final voIPKit = FlutterIOSVoIPKit.instance;
|
|
|
|
HmsApiAvailability hmsApiAvailability;
|
|
|
|
// HmsApiAvailability hmsApiAvailability;
|
|
|
|
|
|
|
|
|
|
|
|
Timer timeOutTimer;
|
|
|
|
Timer timeOutTimer;
|
|
|
|
bool isTalking = false;
|
|
|
|
bool isTalking = false;
|
|
|
|
@ -161,7 +161,7 @@ class PushNotificationHandler {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init() async {
|
|
|
|
init() async {
|
|
|
|
hmsApiAvailability = new HmsApiAvailability();
|
|
|
|
// hmsApiAvailability = new HmsApiAvailability();
|
|
|
|
// VoIP Callbacks
|
|
|
|
// VoIP Callbacks
|
|
|
|
voIPKit.getVoIPToken().then((value) {
|
|
|
|
voIPKit.getVoIPToken().then((value) {
|
|
|
|
print('🎈 example: getVoIPToken: $value');
|
|
|
|
print('🎈 example: getVoIPToken: $value');
|
|
|
|
@ -223,12 +223,12 @@ class PushNotificationHandler {
|
|
|
|
|
|
|
|
|
|
|
|
// if (Platform.isAndroid && (!await FlutterHmsGmsAvailability.isHmsAvailable)) {
|
|
|
|
// if (Platform.isAndroid && (!await FlutterHmsGmsAvailability.isHmsAvailable)) {
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
await hmsApiAvailability.isHMSAvailable().then((value) async {
|
|
|
|
// await hmsApiAvailability.isHMSAvailable().then((value) async {
|
|
|
|
if (value != 0) {
|
|
|
|
// if (value != 0) {
|
|
|
|
final fcmToken = await FirebaseMessaging.instance.getToken();
|
|
|
|
// final fcmToken = await FirebaseMessaging.instance.getToken();
|
|
|
|
if (fcmToken != null) onToken(fcmToken);
|
|
|
|
// if (fcmToken != null) onToken(fcmToken);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
@ -288,29 +288,29 @@ class PushNotificationHandler {
|
|
|
|
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
|
|
|
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
await hmsApiAvailability.isHMSAvailable().then((value) async {
|
|
|
|
// await hmsApiAvailability.isHMSAvailable().then((value) async {
|
|
|
|
if (value == 0) {
|
|
|
|
// if (value == 0) {
|
|
|
|
h_push.Push.enableLogger();
|
|
|
|
// h_push.Push.enableLogger();
|
|
|
|
final result = await h_push.Push.setAutoInitEnabled(true);
|
|
|
|
// final result = await h_push.Push.setAutoInitEnabled(true);
|
|
|
|
|
|
|
|
//
|
|
|
|
h_push.Push.onNotificationOpenedApp.listen((message) {
|
|
|
|
// h_push.Push.onNotificationOpenedApp.listen((message) {
|
|
|
|
newMessage(toFirebaseRemoteMessage(message));
|
|
|
|
// newMessage(toFirebaseRemoteMessage(message));
|
|
|
|
}, onError: (e) => print(e.toString()));
|
|
|
|
// }, onError: (e) => print(e.toString()));
|
|
|
|
|
|
|
|
//
|
|
|
|
h_push.Push.onMessageReceivedStream.listen((message) {
|
|
|
|
// h_push.Push.onMessageReceivedStream.listen((message) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}).catchError((err) {
|
|
|
|
// }).catchError((err) {
|
|
|
|
print(err);
|
|
|
|
// print(err);
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|