firebase / firebase/firebase-js-sdk

FR: Add topic subscription from PWA Javascript app

Open
#9,395 1 comment 0 reactions 0 assignees View on GitHub
api: messaging type: feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### Operating System

Android/Ios/Web

### Environment (if applicable)

ESP8266 and app PWA Javascript

### Firebase SDK Version

12.2.1

### Firebase SDK Product(s)

Messaging

### Project Tooling

Javascript
Library ESP8266 : https://github.com/mobizt/FirebaseClient
### Detailed Problem Description

Hi,

It would be very helpful if a user could be automatically subscribed to an FCM topic when they log in to the PWA using a VAPID key.

Currently, when I generate the token upon login, it's saved in the Firebase Realtime database at /fcmTokens. The problem is that this process is data-intensive (Firebase Data Consumption).

I send notifications via ESP8266 using the library https://github.com/mobizt/FirebaseClient
, which must read all the tokens in /fcmTokens and send the notifications individually, resulting in significant traffic increases due to SSL handshakes and memory heap consumption on the device.

This problem wouldn't arise if Firebase allowed topic subscriptions/unsubscriptions to be managed directly from PWAs, because then it would be possible to send a single notification to a topic, dramatically reducing traffic and memory usage.
### Steps and code to reproduce issue

from ESP8266 with FirebaseClient

void inviaNotificaFCM(const String& nomeDispositivo, const String& messaggio) {
DatabaseOptions opt;
opt.shallow = true;

String tokensRaw = Database.get(aClient, UID_UTENTE "/fcmTokens", opt);
if (tokensRaw.isEmpty()) {
Serial.println(F("⚠️ Nessun token trovato"));
return;
}

FirebaseJson tokensJson;
tokensJson.setJsonData(tokensRaw);

size_t len = tokensJson.iteratorBegin();
for (size_t i = 0; i < len; i++) {
FirebaseJson::IteratorValue val = tokensJson.valueAt(i);
String token = val.key;
if (!token.isEmpty()) inviaNotificaSingoloToken(token, nomeDispositivo.c_str(), messaggio);
delay(50);
}
tokensJson.iteratorEnd();

salvaNotificaFirebase(nomeDispositivo.c_str(), messaggio); // salva la notifica UNA VOLTA
}
--------------------------------------------------------------------------------------------
Tokens on firebase :
/fcmTokens (consume very high data to send message)
c4iIAz6zOf-1JtaxbkOCIx:APA91bGCNy5wiYnF_9UtIhXBdZnNyDRR2gPQ2hV7RYUmFHa5dfCq4ubSRv-JnfGhpppLyyE7XR94s4F2Z6nbl2TCXZoNjegohdYhHn3_1fEgK-uiJNjj31c
:
true
cGivRIdjTkYeexLbEkF_CV:APA91bHo1To9tYr1PRKTfuJLzBVQY3gDH2x1xNmJ9CwD6tBZsY_ve-cDqu37GHLWVbfLQPQUtMQCaljuqBoDq8s5V6wnrIo2_jZ6GK8g8vjXqbx1aw5rFMI
:
true
dqKC7Oo_1fOW4CEhkHQMhx:APA91bElPV-ytjLoPBHoXx71XyrD5qu1DhpvMX7AZTt4HZbsCeezv7dvEfck43Ut0viJ1r936_GIDDtMQ4gYLcsX3jOIGuUOhzlLRbgF5QRbo20YGIqIDDk
:
true
eBt752XEHSMiBsoKfvTbMF:APA91bGgPFnTdA_vIkpBqZjP9YotbkiLTJlc-Yf3vBpJ5DOYpVlF6myzRK8gwx9voAfmLTkFqf1nnXfGMYru40iFBMqIsOKPJiLJZBCH6jOiRJg-YzX2k0I
:
true
fLA_4cWxSbnKhMMoRpRGpO:APA91bEZsWqnkdiT-Dn1mmXsbuR8izy1-0fzLA84DqKFUsK1yO5HF8cdDXjYKYAeXgpipypg2O67KKafsCmDWRf3RhJ6uh9w2zgGqxmClBmKZA2fn6jp2KU
:
true
fLA_4cWxSbnKhMMoRpRGpO:APA91bFV8hde4TI0VWYlsBVIEVGQ39dDZnfUTBl5uLxuVdrPCn62udgkxEtjcEqP3YzhNeva0vaOrw2li-ffV3MzDNM1BLBMV-qa0G5cXkRFvEKVyjdjk9e
:
true

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.