import { Inject , Injectable , PLATFORM_ID } from '@angular/core' ; import { AngularFireLiteApp } from '../core.service' ; import { isPlatformBrowser } from '@angular/common' ; import { from , Observable , Subject } from 'rxjs' ; import { FirebaseMessaging } from '@firebase/messaging-types' ; import 'firebase/messaging' ; @ Injectable ( ) export class AngularFireLiteMessaging { private readonly messaging : FirebaseMessaging ; private readonly browser = isPlatformBrowser ( this . platformId ) ; constructor ( private app , @ Inject ( PLATFORM_ID ) private platformId ) { this . messaging = app . instance ( ) . messaging ( ) ; } instance ( ) { if ( this . browser ) { return this . messaging ; } } token ( ) { if ( this . browser ) { return from ( this . messaging . getToken ( ) ) ; } } tokenRefresh ( ) { if ( this . browser ) { const REFRESH_TOKEN = new Subject ( ) ; this . messaging . onMessage ( ( ) => { this . messaging . getToken ( ) . then ( ( token ) => { REFRESH_TOKEN . next ( token ) ; } ) ; } ) ; return REFRESH_TOKEN ; } } requestPermission ( ) { if ( this . browser ) { return from ( this . messaging . requestPermission ( ) ) ; } } deleteToken ( token ) { if ( this . browser ) { return from ( ( this . messaging . deleteToken ( token ) ) ) ; } } }