Closed idac89 closed 3 years ago
Ok, let's check on the web and then Android.
firebase-messaging-sw.js
in your public folder?The web worker should contain this script:
importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-app.js')
importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-messaging.js')
if (firebase && firebase.messaging && firebase.messaging.isSupported()) {
firebase.initializeApp({ projectId: 'xxxxxx', apiKey: 'xxxxxxx', appId: 'x:xxxxxxxxxxxxxxxxx', messagingSenderId: 'xxxxxxxxx' })
const messaging = firebase.messaging()
}
self.addEventListener('notificationclick', event => {
if (event.action) {
clients.openWindow(event.action)
}
event.notification.close()
})
If you use browser policies in you project, just make sure those import from gstatic.com are not being blocked by your policy.
Thanks for your answer! 1- I'm testing notification running Meteor on localhost:3000 2- The firebase-messaging-sw.js was in public folder but was a little bit different from the one that you've posted. I've edited it now. 3- There are no policy blocking gstatic.com domain.
Ok, thanks! I will try the app on a test environment over a SSL and let you know!
I've tried many ways without any success. Any hint? Thankyou
Did it work for you on IOS? I see you mentioned it didn't work on Android and Web. Also do you import this:
import { webPushSubscribe } from 'meteor/activitree:push'
and do the subscription anytime after your website is loaded?
Thanks For reply! Unfortunately nothing seems ti work on iPhone too.
Yes! For testing purposes I've tried putting the call to webPushSubscribe() in a method called via Meteor.call on a button click but I get: Expetion while invoking method "testsubscribe" TypeError: webPushSubscribe Is not a function.
Obviously i've import { webPushSubscribe } from 'meteor/activitree:push' on top of file.
Hi, please read this thread to better understand Meteor.call(): https://stackoverflow.com/questions/39229966/meteor-call-method-meteor-js
To explain it further, for this case, a Meteor package can be configured to add code to the client bundle, to the server bundle or to both. Generating a Push token is exclusively a client feature and you cannot call this function using a Meteor Method. You just need to execute the function itself. Example:
In your App.js (with React):
import React, { useEffect, useState } from 'react'
import { webPushSubscribe } from 'meteor/activitree:push'
const App = props => {
// ..........
useEffect(() => {
// wait a number of seconds before you ask a user to accept receiving notifications
setTimeout(() => {
webPushSubscribe()
}, 5000) // 5 seconds
}, [])
// .........
}
Ouch! I've understood! Now I finally got web client token registered on db but when I try to send a push notification i get: Push: Sent message "test" to 0 iOS apps | 0 Android apps | 1 web apps Push, GUIDE: The "Push.appCOllection" - No APN clients have registered on the server yet... Succesfully sent message: projects/meteor-push-35e5d/messages/xxxxxxxxxxx
But i don't see any push notification
Update: Randomly i see the push notification.
I've 2 buttons For testing purposes:
Hi @idac89, did you manage to implement Push and consistently get tokens?
Hi! Yes, when i click on the button that call webPushSubscribe, It Just get token and write It on db. And when I try to send webpush notification It works randomly.
" It Just get token and write It on db." Not sure I understand right, do you expect to do something else, or extra? It sends randomly or receives randomly in the browser. The package has a debug flag which when turned on it you get to see everything in the console. With this in mind, did you turn debug ON and do you see the sending "receipt" in the server console? Is the sending successful or does it show sent to 0 or ... I will close this for the time being. I would consider that if the package is able to send once, there is nothing wrong with it. If however you find an issue, or you want to improve upon the existing package or need an extra feature, please feel free to open a PR and I will make sure to merge it for you in due time.
Hi all! I can't get the _push_app_tokens populated with Android or Web client. I've set both server and client startup js files as in the example app. The debug write the configuration then says: Firebase Admin for Android Messaging configured Push: Send worker started, using interval: 3000
But If I try to send a notification with Push.send i get: Push, GUIDE: The "Push.appCollection" might be empty. No clients have registered on the server yet...
What can I do to give it a try forcing a client registration and check when it goes into some errors?
Thanks in advance