TF-1246: Enable FCM for Web browser

This commit is contained in:
ManhNTX
2022-11-29 20:11:15 +07:00
committed by Dat H. Pham
parent d990426c8e
commit 045c7383e6
7 changed files with 45 additions and 5 deletions
@@ -1,6 +1,9 @@
import 'package:core/utils/app_logger.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:tmail_ui_user/features/push_notification/domain/exceptions/fcm_exception.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/services/fcm_service.dart';
@pragma('vm:entry-point')
@@ -26,9 +29,14 @@ class FcmReceiver {
}
void getFcmToken() async {
final token = await FirebaseMessaging.instance.getToken();
log('FcmReceiver::onFcmToken():token: $token');
FcmService.instance.handleRefreshToken(token);
try {
final token = await FirebaseMessaging.instance.getToken(vapidKey: kIsWeb ? dotenv.get('FIREBASE_WEB_VAPID_PUBLIC_KEY', fallback: '') : null);
log('FcmReceiver::onFcmToken():token: $token');
FcmService.instance.handleRefreshToken(token);
} catch(e) {
log('FcmReceiver::onFcmToken():exception: $e');
throw NotLoadedFCMTokenException();
}
}
void onRefreshFcmToken() {