I try to add Web Push Notification through Firebase (Google Cloud Message), everything seems to have turned out, but after the first notification comes, the next ones just do not come. In order to resume receiving alerts on localhost, you have to close the browser and open it again. It is not clear why such a strange work.
I get token subscriptions (subscriber_id) without problems, and then referring to the API I post to Google Cloud. The code response is 200 from google, that is all passed, but the alerts stubbornly do not want to come after I receive the first notification. There is a suspicion that the problem lies in the /serviceworker.js root file, which is responsible for receiving push notifications in the browser. Can anyone come across a similar problem I will be grateful for your help
The code in the controller:
@conn ||= Faraday.new(:url => 'http://ift.tt/2cu385O') do |faraday|
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
response = @conn.post do |req|
req.url '/fcm/send'
req.headers['Content-Type'] = 'application/json'
req.headers['Authorization'] = 'key= ' + secret_key
req.body = '{ "to": " + subscriber_id + '" }'
end
Response:
post http://ift.tt/1TmHkUo
User-Agent: "Faraday v0.9.2"
Content-Type: "application/json"
Authorization: "key= some_key"
200
content-type: "application/json; charset=UTF-8"
date: "Wed, 20 Dec 2017 16:15:35 GMT"
expires: "Wed, 20 Dec 2017 16:15:35 GMT"
cache-control: "private, max-age=0"
x-content-type-options: "nosniff"
x-frame-options: "SAMEORIGIN"
x-xss-protection: "1; mode=block"
server: "GSE"
alt-svc: "hq=\":443\"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=\":443\"; ma=2592000; v=\"41,39,38,37,35\""
connection: "close"
transfer-encoding: "chunked"
The code in the /serviceworker.js file is:
function onPush(event) {
var title = (event.data && event.data.text()) || "Yay a message";
event.waitUntil(
self.registration.showNotification(title, {
body: "New message!",
icon: "/assets/test.jpg",
tag: "push-simple-demo-notification-tag"
})
)}
self.addEventListener("push", onPush);
Aucun commentaire:
Enregistrer un commentaire