The Angular2+ directive angular2-notifications
is doing only the last part showing the message in UI/UX. And that is the least of your challenges.
You say:
The requirements are send push notification to all users who
notification granted while browser closed as well
The part 'while browser closed as well' is the tricky part.
This means 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 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.
I don't think setting up a WebSocket connection (like socket.io
) from Node to a Service Worker
is possible. It's complicated, some people say it's possible, others say no. See this for more info. I would at least say that it is not stable enough, so you need a 'real' push notification.
You can use a push notification provider to do the job. Click here for a list of them. You pay for these services.
If you want to do it yourself (free of costs) you can use Google's cross-platform messaging solution Firebase Cloud Messaging (FCM)
(the successor of Google Cloud Messaging (GCM)
).
To connect your NodeJS server with the FCM
you can use different libraries e.g. node-pushserver and many others.