3

I'm working on a Restful Web Application. I divide frontend and backend, using Angular2 for the front, and NodeJS for the back.

I would like to use Notifications and push them to specific users.

Sample : If my user decide to subscribe, he could get a Desktop notification when I decide to send one or if my NodeJS serveur want to send a message to a user group.

I have seen a lot of differents modules for the frontend and backend, but I'm a little bit lost.

Architecturally, how should I add this service in my application? Should I use specific node modules?

2
  • Did you find a solution? I have the same question. Websockets are no solution since your goal is to send notifications to Desktop, so users can close their browsers and receive notifications. Please shared your knowledge to help me and others. You can answer your own question and people can give you credit for that. Commented Jan 11, 2018 at 9:09
  • Finally we didn't integrate this feature. At the time it was new, so I hope it's easier to integrate now. Don't hesitate to share your solution if you find something! I think this kind of need should become usual. Commented Jan 12, 2018 at 10:27

2 Answers 2

2

You talk about desktop notifications. I guess you want the user to receive its notifications also when the browser or app is closed. In that case you need a Service Worker. A Service Worker is a script that your browser runs in the background, to which the message is being pushed when the browser or app is closed. For a nice introduction to Service Workers, read this. Angular has a Service Workers implemented in production version since 5.0.0. Klik here to read more about it.

At the backend you need a special Node module to send the notification. For instance node-pushserver, but there are many others. This special node module connects to a messaging service whom actual send the message. You can use for instance Google's cross-platform messaging solution Firebase Cloud Messaging (FCM) (the successor of Google Cloud Messaging (GCM)). It can send to Web, iOS and Android.

At the client side you need to register the Service Worker for push notification. Then you will get an endpoint that needs to be stored at the node server side. You send a push request with this endpoint to the messaging service every time.

You can also make use of a paid push notification provider to do the job. Click here for a list of them.

Setting up a WebSocket connection (like socket.io) won't work since it can't stay connected with the Service Worker.

Sign up to request clarification or add additional context in comments.

2 Comments

Great, that's exactly the information I was looking for. Angular 5 seems to fill the gaps on these topics.
@LewisGodgiven - Good luck !!
0

You can use WebSockets for pushing data from the Node.js server. Add the ws package to your server's package.json. Take a look at the BidServer.ts here: https://github.com/Farata/angular2typescript/tree/master/chapter8/http_websocket_samples/server/bids

The Angular client is here: https://github.com/Farata/angular2typescript/tree/master/chapter8/http_websocket_samples/client/app/bids

2 Comments

In fact I suppose if I use WebSockets, my client application has to be opened. If I understand how notifications works, I should be able to send a desktop notification to my users even if their browsers are closed? See notification : developer.mozilla.org/en/docs/Web/API/notification
On the server, you can check if a websocket is closed to not send notifications to the clients that closed their browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.