-
-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Description
Hi, from the ESP8266 I send the FCM notification to my PWA, but I can't make the notification appear as a "banner"; I only see it in the top bar.
Is there an option to enable notifications on PWAs?
Here's what I currently use to increase the priority.
SERVICE WORKER :
----------------------------------------
// Initialize Firebase
initializeApp(firebaseConfig);
self.addEventListener('install', (event) => self.skipWaiting());
self.addEventListener('activate', (event) => self.clients.claim());
// 🔹 Push event (ricezione notifiche background)
self.addEventListener('push', (event) => {
const payload = event.data?.json() || {};
if (!payload.notification) return;
const { title, body, icon } = payload.notification;
event.waitUntil(
self.registration.showNotification(title, {
body,
icon: icon || '/app/Immagini/icon-192.png',
// 🔥 AGGIUNTI (per aumentare probabilità banner)
requireInteraction: true,
silent: false,
vibrate: [200, 100, 200],
tag: 'alert-pwa',
renotify: true,
data: payload.data || {}
})
);
});
ESP8266 :
----------------------------------------
Messages::Message msg;
msg.topic(USER_UID);
{
Messages::Notification notification;
notification.title(DEVICE_NAME);
notification.body(message);
msg.notification(notification);
}
// --- FORCE BANNER ON ANDROID (PWA) ---
{
Messages::AndroidConfig androidConfig;
androidConfig.priority(Messages::AndroidMessagePriority::_HIGH);
Messages::AndroidNotification androidNotification;
androidNotification.notification_priority(Messages::NotificationPriority::PRIORITY_HIGH);
// IMPORTANT: This ID must be unique or correspond to an "Urgent" channel
androidNotification.channel_id(F("high_priority_channel"));
androidNotification.default_sound(true);
androidNotification.default_vibrate_timings(true);
androidConfig.notification(androidNotification);
msg.android(androidConfig);
}
Messages::Parent parent(FIREBASE_PROJECT_ID);
{
String payload = messaging.send(aClient, parent, msg);
if (aClient.lastError().code() == 0) {
Serial.println(F("✅ Notification sent successfully!"));
saveFirebaseNotification(DEVICE_NAME, message);
} ```
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels