Comments (4)
How to send response to SERVER and get notification.... I need server side code.. please help
from web-push-codelab.
Where are you seeing a reference to GCM?
https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/
The only reference is at the very end regarding how to deal with old / non-standard browsers.
Regarding server side code, are you tried looking at the web-push libraries referenced in the code lab?
Otherwise a full node demo can be found here: https://github.com/gauntface/web-push-book/tree/master/src/demos/node-server
from web-push-codelab.
Hello,
I am trying to cover the basic scenario of having one user to register on multiple devices and having this one to receive notification from the server. I got some success, but the documentation is lacking and often refer to Android (which I do not mind since I just want browser notification).
What I did is refered here for client side and here for server side.
The problem is it's working only with a single device since I am storing the token on the server which come from the last device registered by the user. The official multiple devices documentation for Web introduces multi device and topics (at the same time) and at some point just doesn't give any detail about how to subscribe/unsubscribe and send for multi device and partially cover topic. For example, this page doesn't even say to send a HTTP request "DELETE" to unsubscribe (from topic or device), I had to figure that out in an Android page.
Now, I am experimenting the use of TOPICS instead of the "device" to represent a user. On every device, the user subscribe to a topics/. And the server send a notification to topics/. So far it works but I cannot delete the message token in the scenario that the user do not want to user notification (I just successfully remove from his topic). I am using the code in this repository (the only example, undocumented) that use messaging.deleteToken(currentToken)
which return me a successful promise, but the token is still there when requested messaging.getToken()
which doesn't make sense.
My new server code with Topics to handle multiple user devices looks like this to register a new device:
public void RegisterTopic(string userIdentifierForAllDevices, string singleDeviceNoticationKey)
{
var serverApiKey = ConfigurationManager.AppSettings["FirebaseServerKey"];
var firebaseGoogleUrl = $"https://iid.googleapis.com/iid/v1/{singleDeviceNoticationKey}/rel/topics/{userIdentifierForAllDevices}";
var httpClient = new WebClient();
httpClient.Headers.Add("Content-Type", "application/json");
httpClient.Headers.Add(HttpRequestHeader.Authorization, "key=" + serverApiKey);
object data = new{};
var json = JsonConvert.SerializeObject(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
var responsebytes = httpClient.UploadData(firebaseGoogleUrl, "POST", byteArray);
string responsebody = Encoding.UTF8.GetString(responsebytes);
dynamic responseObject = JsonConvert.DeserializeObject(responsebody);
}
To send a message, I am sending like I am doing in the first link I posted with a POST to https://fcm.googleapis.com/fcm/send. I found odd that I have 2 different URL (one with FCM and one with iid).
On the client side, I am doing as mentioned in this repository. Like I said, the problem is to unsubscribe as well as I found it awkward that I need to use topics for multiple devices.
from web-push-codelab.
It sounds like you are mixing up web push and Firebase Cloud Messaging.
Web Push is the web standard, Firebase Cloud Messaging does some magic behinds the scenes to return a firebase token that can be used with the Firebase Cloud Messaging API (NOT web push protocol).
This is the incorrect place to be asking for help, a better place would be to click the "Send Feedback" button on the top right of the documentation page you linked to.
That being said - Firebase Cloud Messaging will always return a token if you call getToken, this is by design. The expectation is that you simply don't send a message to a token if they unsubscribe OR you call deleteToken and save state that the user does not want to receive messages.
from web-push-codelab.
Related Issues (20)
- Unsubscribe Event does not remove subscription from browser settings
- Code worked but no pop up for notifications HOT 2
- the key in the authorization header does not correspond to the sender ID used to subscribe this user HOT 1
- How does it work?
- Doesn't redirect to new tab when click on Allow in notification
- web-push-codelab.glitch.me is down
- Bug: missing step in tutorial, in notification click
- Latency in google web push GCM responses after january 2019
- MissmatchSenderId HOT 1
- Send Push Message Error
- 403 - forbidden HOT 1
- push notifications are not working HOT 2
- The text is only shown in the console
- Web Notification & bug HOT 1
- Failed to execute 'atob' on 'Window' HOT 3
- Error in description
- Not working in Microsoft Edge HOT 1
- Does not load the page https://web-push-codelab.glitch.me/ HOT 7
- it helped me to show notification on web. thankyou so much for that but it isn't showing notification on mobile. what i have to do. Waiting for the solution with hope.
- Cannot read property 'pushManager' of null HOT 1
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-codelab.