2

I'm dev-ing nodejs server for push server. so I downloaded private key and set up this file. but I faced with some problems. as I see many examples, there is a token. I realized that token is for sending to specific device. but I wanna send all devices.

const admin = require('firebase-admin');
const serviceAccount = require('./firebase_account/firebase_account.json');

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "url"
  });


const registrationToken =""
const payload={
    notification:{
        title:"title",
        body:"body"
    }
}

admin.messaging().sendToDevice(registrationToken,payload,"")
    .then(function(response){
        console.log(response)
    })
    .catch(function(error){
        console.log(response)
    })

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
jakchang
  • 402
  • 5
  • 13

1 Answers1

1

There is no way built in API to send a message to all devices. The most common approach to implement this is to subscribe all clients to a specific topic (e.g. /topics/all), and then send a message to that topic.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807