Comments (2)
https://developers.google.com/web/fundamentals/push-notifications/display-a-notification
https://web-push-book.gauntface.com/demos/notification-examples/
смотрите доку и примеры, параметры добавлять нужно в эту функцию
self.registration.showNotification в виде json объекта 2 аргументом.
self.addEventListener('push', function(event) {
console.log('Получено push-сообщение', event);
var data = event.data.json(); // json данные, которые отправили в из php скрипта ( они могут быть любыми, главное json ).
var title = 'Ура, работает!';
var body = 'Было получено сообщение от сайта.';
var icon = '/icon-192x192.png';
var tag = 'simple-push-demo-notification-tag';
event.waitUntil(
self.registration.showNotification(title, {
body: body,
icon: icon,
tag: tag
})
);
});
from web-push-api.
У меня подключен fcm с дефолтными jsками, через пхп я отправляю такое:
$opts['postDataJson']['notification'] = array(
'title' => $push['title'],
'body' => $push['description'],
'icon' => $config['firebase_files'].$push['icon'],
'badge' => $config['firebase_files'].$push['badge'],
'image' => $config['firebase_files'].$push['image'],
'vibrate' => $push['vibrate'],
'requireInteraction' => $push['interaction']>0 ? 'true' : 'false',
'click_action' => 'URL/push.php?action=redirect&id='.$push['id'].'&subid='.$push['last_id'],
);
Иконка показывается, а badge и image не работает, мне нужно отредактировать скрипт firebase-messaging-sw.js?
Содержимое:
// firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-messaging.js');
firebase.initializeApp({
messagingSenderId: '1111111111111'
});
const messaging = firebase.messaging();
from web-push-api.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web-push-api.