I am currently building an Ionic app with Express and MongoDB.
How to develop an api or a system to enable instant update to view templates with new data? Also, how to notify a list of user?
event{
time : time,
invited : [ ] // send a notification everyone in the list when an event happens
}
I think using SocketIO would be good here. But I can't figure out how to design this. I have read many books and watched some video tutorials but haven't found anybody discussing this .
Your help would be appreciated here.
I would do it the following way :
Define a collection in MongoDB that holds your notifications. The schema would look like following :
Whenever you need to add a new notification into the system, you insert a new record into the above collection. The property
tois an array which indicates the receivers of the notification. This can be an array an ids.Now when a user loads your web page, retrieve notifications whose
toproperty contains the id of the corresponding user. Once you display the notifications, you may update theseenproperty.Making it Realtime :
If you want to develop an in-house solution, you can use socket.io for this. You can publish the same notification instance that you store in MongoDB to Socket.io. Basically, you need to look at the
toproperty and broadcast an event only to those users from Socket.io.Take a look at the following links :
getStream : You can build powerful notification feeds and make them realtime using this hosted API. They have a free plan which lets you add 3M activities per month. They also offer a Node.js client which works pretty well.
Push Notifications using Socket.io.
Designing a Feed