B
B
beem72021-04-10 22:34:13
Node.js
beem7, 2021-04-10 22:34:13

How to make something similar to PUSH notifications, but so that they do not come in OS notifications, but simply in the ws / http front-end?

I know about things like push, webpush, etc., but as far as I understand, these notifications can only come in the standard Android/iOS/Windows 10/browser notification system.

But it is necessary to implement such notifications, but so that they simply come via WebSocket to the front-end from the microservice on the back-end, so that they can be processed there and issued simply in the front-end interface. Better not even WebSocket, but HTTP.

Approximately worked out the following algorithm:
1. The user enters the page. At the same time, an XHR / fetch request is immediately sent to a special microservice route.
2. The route handler hangs, waiting for data in the database. (Either the database checks at a short interval, or the database has a method that can be called and it will hang until some change occurs). And if the HTTP timeout has ended, then the client again makes such a request. That is, long-polling.
3. And then an event occurs on the server.
4. The route handler stops hanging and returns the event data to the client.
5. The client receives this response from the request. Perhaps there are several events (especially if sleep is used in paragraph 2).
6. The client makes a request again, but this time passes the id-s of the received messages in the parameters.
7. The server removes messages from the table by these ids, and then see point 2.

Each client has a certain accountName, which lies in each message in the table, and is used both for adding messages (p. 3), for receiving (p. 4), and for deleting (p. 7). This protects against
interaction with other people's messages.

Everything seems to be fine, but what if the user opens several clients with one accountName? Some of them will definitely read and clear the queue faster than others. And it is necessary that everyone receive this data at once.

Instead of accountName, you can come up with some kind of id for each client, but how then to clean up unnecessary queues, because now they are not even limited by the number of accounts in the system?

In general, the task is not so simple. Maybe there is some ready-made solution so that this microservice does not cycle itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mitya_k, 2021-04-10
@mitya_k

Ajax pooling, server sent events and websocket technologies will help you.
And logically, if you do not use push messages, you will have to save the generated device id in the database when installing / authorizing the application. And each message will be associated with an accountName and a device. About the same thing is done by firabase or other push notification services.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question