Implementing push notification using Node.js - node.js

I was curious to know that can we implement push notification to our client via our Node.js server just like we send emails using nodemailler in Node.js? If yes! Then how? Can anyone please briefly elaborate. Also a point to note that the push notification should be user specific just like our mails are which are distinguished by our mail id.
Thanks in advance.

You can achieve this using Firebase Cloud Messaging. Here's a high level overview:
Each client registers with FCM and sends it's unique token to your node.js server.
The server saves this token and associates it with the user.
When it comes time to send the push notification, you use the FCM node.js library to send a push notification to the token associated with the user you want.

Not sure if it is the best way.
You might open a port on server side and listen to that port from client side. I am talking about socket programming. New notifications will be sent through that open port.

Related

How to send data to client with node express when client has not ask for?

My Question is above. I want that when an event triggered like a new Mail comes in or an other client has connected to the server, my application send to the existing connection a request(?) which say something like "Hey you not alone !". I know how to answer on request from client but how can i send the client information when he has not ask for it explicit.
i hav draw an simple image to visualize what i mean
You cannot directly do this. However, you can archive this by Server-sent Event which is making use of long-polling.
Reference:
https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events
As per my understanding you are looking for a way to send data / message from server to client side.
if so there are two ways to do it.
Create an API and pool is after certain interval of time from client side.
Create a socket server, connect your client with socket which will give you maintain the socketId on server

How can I securely implement a notification system using socket?

I am currently working on a web application using the MEAN stack. It has a social aspect to it so I want to be able to push notifications to users.
The way I do it now is when something happens that should be a notification it gets stored in a mongo database with an unread flag. Each client will send a get request to the server every 30 second and will receive every notification marked as unread, and will then mark it as read.
I want to switch to using a message queue and sockets so less network resources will be used, and also provide the user with a real-time experience. I've thought about using redis and its pubsub structure but I can't seem to figure out how to do this securely. If I push out notifications to the affected users, won't it be easy for someone malicious to subscribe to somebody else's channel and receive notifications not meant for them? Am I missing something or is it just the wrong approach for such a system?
Edit: Figure I update with the solution I went with if anyone else reading this is having the same problem.
Instead of using rabbitmq, as the answer suggested, I figured that a much more easy and elegant solution is to just use socket.io. When new sockets connects to the server I save a mapping from the userID to the socketId in a redis in-memory DB. (After I've validated their token) That way, if I need to push a notification to a user I just look up the socketId in the redis DB, and then send it to the correct socket.
This way I don't need any security beyond that as socketIDs are unguessable, and the message is only sent across the single socket that belongs to the given user.
This way it will only get sent through the connection of the given socket, as socketIDs are only used server side to keep track of all the connection. This means no one else can "listen" using someone else's socketID.
you can use RabbitMQ for this. Also authentication is there. Please go through following link and try.
https://www.rabbitmq.com/access-control.html
also, you can apply authentication in existing structure using subscription auth tokens with all subscribed users only.
even redis has its security with topics. Please have a look in link below
https://redis.io/topics/security

How to send push notification using XMPP Server?

I want to develop a chat application in iphone. I'm using ejabberd xmpp server. Now i'm able to send message to other user.
Now i want to receive the message with push notification.
I heard that we can use xmpp servers to send push notifications.
So Can anyone tell me, I want to know how
Is it possible to send push notification with ejabberd
Is it possible send push notifications from ejabberd xmpp server using node js.
Please give any suggestion to start using notifications for messages in xmpp.
If you want to send push notifications with ejabberd community edition, you need to add an ejabberd module, which sends the offline messages to a specified push notification provider. This provider send the notifications to apple APNS or googles GCM.
You could develop a module by self or maybe you will find some in inet. mod_zeropush (https://github.com/ZeroPush/mod_zeropush) would be one of them, but the zeropush service by self is canceled. Another one would be mod_onesignal (https://github.com/nobreak/mod_onesignal). OneSignal is a free to use Push Notification provider.
XMPP requires a persistent socket connection or a "persistent" BOSH connection during your whole XMPP session. Whenever your iOS app goes in background iOS kills your socket connection, and your Openfire server kills your XMPP session. This means the user goes offline. Which is also the reason why incoming messages for this user go to the offline storage.
A more straight forward approach is to do something in openfire, when openfire can't deliver a message it stores it in offline table, we can do some interception on that part and initiate the push process with the message.

push notification like facebook

i want to build a push notifications service like facebook with nodejs and socketio. i have a question:
- how server can know what exactly client to send notification when many client connected to server?
Thanks for help!
Associate sockets with users when they connect, so when you have to notify user "Test" just look at the user.sockets[] list and send him whatever info you want to send.
In other words, Node.js doesn't have to "know" about users, you should take care of that and talk with Node.js in "socket" terms.
You can use socket.io's room feature. You can subscribe each client to its unique room and then emit an event in that room so that user will be the only one to get that.

server send push notification to client browser without using polling

I am developing a web app in which I want that when some changes in database occurs, server sends response to particular client(like push notification). And I want this notification to be sent client's browser. I don't want to use polling.
What can I do?
I think it's possible using SSE, but I am not clear.
I want to know
Is it possible to send response to particular client without client's request(without polling).
How server will detect that particular client?
please help me.
There is Web Notification. And there you can see the browsers that support it.

Resources