DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

Answer: How I can change a mobx state upon a receival of a background message from firebase?

At this question:

This is achievable by placing at firebase-messaging-sw.js the following:

messaging.onBackgroundMessage(function(payload) {
  console.log('Received background message', payload)
  // Propagate message upon UI
  if(typeof payload.data !== 'undefined' && typeof payload.data['flag'] !== 'undefined' ) {
    self.clients.matchAll({includeUncontrolled: true}).then(function (clients) {
      //you can see your main window client in this list.
      clients.forEach(function(client) {
          client.postMessage({...payload});
      });
    })

I showcase how to trigger a mobx state change upon receival of a background message at firebase FCM.

Hope it helps.

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series