R
R
rst6302022-03-31 15:28:24
Push technologies
rst630, 2022-03-31 15:28:24

How does firebase receive push notifications?

I'm trying to set up push notifications through firebase but it doesn't work.

At the front:

import { initializeApp } from "firebase/app";
import { getMessaging, getToken, onMessage  } from "firebase/messaging";

const firebaseConfig = {
    apiKey: "xxxxxx,
    authDomain: "xxxxx",
    databaseURL: 'xxxxx',
    projectId: "xxxx",
    storageBucket: "xxxxxx",
    messagingSenderId: "xxxxx",
    appId: "xxxx",
    measurementId: "xxxxx"
};

const app = initializeApp(firebaseConfig);
const messaging = getMessaging();

getToken(messaging).then((currentToken) => {
    if (currentToken) {
        console.log(currentToken)
    } else {
        console.log('No registration token available. Request permission to generate one.');
    }
}).catch((err) => {
    console.log('An error occurred while retrieving token. ', err);
});

onMessage(messaging, (payload) => {
    console.log('Message received. ', payload);
});

I go to the page, take the client's token - and send him a push from the back, in the firebase admin panel you can see that the message counter is increasing, but they are not in the received status. onMessage is also silent.

And here I don’t quite understand through what channel he should have received them at all?

firebase does not poll any api, does not connect to the socket - where do they come from?


To send, I use the https://github.com/laravel-notification-channels/fcm package - everything seems to be fine here - the request goes away, the response is null As a token, I hardcoded the key for tests:
User::first()->notify(new PushNotification)
public function routeNotificationForFcm() {
        return 'xxxxxx'; // Ключ взял из выхлопа console.log на фронте
}

It's about the browser on the desktop. On android / ios, this apparently works differently by internal means of ios - I haven’t gotten there yet - just to get a web push for the test.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rst630, 2022-03-31
@rst630

the problem was that I didn't pass vapidKey to getToken() which can be obtained in cloud messagind certificates - they just weren't generated.
But the question through which channel the data comes is still relevant. I don't see any xhr or ws messages when push comes in
6245aa52179db816599531.png

A
AlexVWill, 2022-03-31
@AlexVWill

And here I don’t quite understand through what channel he should have received them at all?

Are you sure you did everything according to the instructions? https://firebase.google.com/docs/cloud-messaging/j...
For at the very beginning it says
Add and initialize the FCM SDK
1. If you haven't already, install the Firebase JS SDK and initialize Firebase.

And the link is given: https://firebase.google.com/docs/web/setup#add-sdk...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question