11import  {  Component ,  OnInit  }  from  '@angular/core' ; 
22import  {  AngularFireMessaging  }  from  '@angular/fire/messaging' ; 
33import  {  trace  }  from  '@angular/fire/performance' ; 
4- import  {  Observable ,  fromEvent  }  from  'rxjs' ; 
5- import  {  tap ,  map ,  filter  }  from  'rxjs/operators' ; 
6- import  *  as  firebase  from  'firebase/app' ; 
7- import  'firebase/messaging' ; 
4+ import  {  Observable  }  from  'rxjs' ; 
5+ import  {  tap  }  from  'rxjs/operators' ; 
86import  {  SwPush  }  from  '@angular/service-worker' ; 
7+ import  {  environment  }  from  '../../environments/environment' ; 
98
109@Component ( { 
1110  selector : 'app-messaging' , 
@@ -25,8 +24,15 @@ export class MessagingComponent implements OnInit {
2524  message$ : Observable < any > ; 
2625  showRequest  =  false ; 
2726
28-   constructor ( public  readonly  messaging : AngularFireMessaging ,  swPush : SwPush )  { 
29-     messaging . usePublicVapidKey ( 'BIDPctnXHQDIjcOXxDS6qQcz-QTws7bL8v7UPgFnS1Ky5BZL3jS3-XXfxwRHmAUMOk7pXme7ttOBvVoIfX57PEo' ) . then ( ( )  =>  { 
27+   constructor ( public  readonly  messaging : AngularFireMessaging ,  readonly  swpush : SwPush )  { 
28+     swpush . messages . subscribe ( it  =>  console . log ( 'swpush' ,  it ) ) ; 
29+     messaging . usePublicVapidKey ( environment . vapidKey ) . then ( async  ( )  =>  { 
30+       if  ( navigator  &&  navigator . serviceWorker )  { 
31+         const  registration  =  await  navigator . serviceWorker . getRegistration ( ) ; 
32+         if  ( registration )  { 
33+           await  messaging . useServiceWorker ( registration ) ; 
34+         } 
35+       } 
3036      this . message$  =  messaging . messages ; 
3137      this . token$  =  messaging . tokenChanges . pipe ( 
3238        trace ( 'token' ) , 
0 commit comments