@@ -24,8 +24,8 @@ import {
24
24
MessagePayload ,
25
25
deleteToken ,
26
26
getToken ,
27
- onMessage ,
28
- onBackgroundMessage
27
+ onBackgroundMessage ,
28
+ onMessage
29
29
} from '@firebase/messaging-exp' ;
30
30
import { NextFn , Observer , Unsubscribe } from '@firebase/util' ;
31
31
@@ -46,6 +46,47 @@ export interface MessagingCompat {
46
46
) : Unsubscribe ;
47
47
}
48
48
49
+ export function isSupported ( ) : boolean {
50
+ if ( self && 'ServiceWorkerGlobalScope' in self ) {
51
+ // Running in ServiceWorker context
52
+ return isSwSupported ( ) ;
53
+ } else {
54
+ // Assume we are in the window context.
55
+ return isWindowSupported ( ) ;
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Checks to see if the required APIs exist.
61
+ */
62
+ function isWindowSupported ( ) : boolean {
63
+ return (
64
+ 'indexedDB' in window &&
65
+ indexedDB !== null &&
66
+ navigator . cookieEnabled &&
67
+ 'serviceWorker' in navigator &&
68
+ 'PushManager' in window &&
69
+ 'Notification' in window &&
70
+ 'fetch' in window &&
71
+ ServiceWorkerRegistration . prototype . hasOwnProperty ( 'showNotification' ) &&
72
+ PushSubscription . prototype . hasOwnProperty ( 'getKey' )
73
+ ) ;
74
+ }
75
+
76
+ /**
77
+ * Checks to see if the required APIs exist within SW Context.
78
+ */
79
+ function isSwSupported ( ) : boolean {
80
+ return (
81
+ 'indexedDB' in self &&
82
+ indexedDB !== null &&
83
+ 'PushManager' in self &&
84
+ 'Notification' in self &&
85
+ ServiceWorkerRegistration . prototype . hasOwnProperty ( 'showNotification' ) &&
86
+ PushSubscription . prototype . hasOwnProperty ( 'getKey' )
87
+ ) ;
88
+ }
89
+
49
90
export class MessagingCompatImpl implements MessagingCompat , _FirebaseService {
50
91
swRegistration ?: ServiceWorkerRegistration ;
51
92
vapidKey ?: string ;
0 commit comments