TF-2460 Fix real time updates for web are broken

This commit is contained in:
dab246
2024-03-22 17:03:15 +07:00
committed by Dat H. Pham
parent bdc140fcce
commit 971b228107
4 changed files with 53 additions and 1 deletions
@@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_message_controller.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/services/fcm_service.dart';
import 'package:tmail_ui_user/main/utils/app_config.dart';
import 'package:universal_html/html.dart' as html;
@pragma('vm:entry-point')
Future<void> handleFirebaseBackgroundMessage(RemoteMessage message) async {
@@ -29,6 +30,9 @@ class FcmReceiver {
_onForegroundMessage();
_onBackgroundMessage();
if (PlatformInfo.isWeb) {
_onMessageBroadcastChannel();
}
if (PlatformInfo.isIOS) {
notificationInteractionChannel.setMethodCallHandler((call) async {
@@ -49,6 +53,11 @@ class FcmReceiver {
FirebaseMessaging.onBackgroundMessage(handleFirebaseBackgroundMessage);
}
void _onMessageBroadcastChannel() {
final broadcast = html.BroadcastChannel('background-message');
broadcast.onMessage.listen(FcmService.instance.handleMessageEventBroadcastChannel);
}
Future<String?> _getInitialToken() async {
final token = await FirebaseMessaging.instance.getToken(
vapidKey: PlatformInfo.isWeb ? AppConfig.fcmVapidPublicKeyWeb : null