File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
snippets/messaging-next/service-worker Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,21 @@ function initInSw() {
4040
4141function onBackgroundMessage ( ) {
4242 // [START messaging_on_background_message]
43- // TODO(snippet): This snippet is not yet translated to the @exp SDK
43+ const { getMessaging } = require ( "firebase/messaging" ) ;
44+ const { onBackgroundMessage } = require ( "firebase/messaging/sw" ) ;
45+
46+ const messaging = getMessaging ( ) ;
47+ onBackgroundMessage ( messaging , ( payload ) => {
48+ console . log ( '[firebase-messaging-sw.js] Received background message ' , payload ) ;
49+ // Customize notification here
50+ const notificationTitle = 'Background Message Title' ;
51+ const notificationOptions = {
52+ body : 'Background Message body.' ,
53+ icon : '/firebase-logo.png'
54+ } ;
55+
56+ self . registration . showNotification ( notificationTitle ,
57+ notificationOptions ) ;
58+ } ) ;
4459 // [END messaging_on_background_message]
4560}
Original file line number Diff line number Diff line change 44// To make edits to the snippets in this file, please edit the source
55
66// [START messaging_on_background_message_modular]
7- // TODO(snippet): This snippet is not yet translated to the @exp SDK
7+ import { getMessaging } from "firebase/messaging" ;
8+ import { onBackgroundMessage } from "firebase/messaging/sw" ;
9+
10+ const messaging = getMessaging ( ) ;
11+ onBackgroundMessage ( messaging , ( payload ) => {
12+ console . log ( '[firebase-messaging-sw.js] Received background message ' , payload ) ;
13+ // Customize notification here
14+ const notificationTitle = 'Background Message Title' ;
15+ const notificationOptions = {
16+ body : 'Background Message body.' ,
17+ icon : '/firebase-logo.png'
18+ } ;
19+
20+ self . registration . showNotification ( notificationTitle ,
21+ notificationOptions ) ;
22+ } ) ;
823// [END messaging_on_background_message_modular]
You can’t perform that action at this time.
0 commit comments