email@example.com +1 400 3113 11
PURE template has webSocket server (WSS). WSS are used as notification controller. What does it mean? First, WSS doesn’t send “big” data, like content (comments, activities and etc.) – WSS sends only notifications about some events on server – not more. Second, WSS do own authorization of users. WSS does nothing else.
To understand how it works, please, pay your attention on next scheme.
So, there are a few simple steps:
As you see during an action (adding comment) server did not send any notifications via WSS, just saved an information about such action (event) into database. Time to go on the next step.
Client receives confirmation about successful operation. And at this moment client sends command “wake up” to WSS. Pay your attention, client sends just command without any information, because all necessary information is in database. What does WSS?
That’s all. Clients get such package and should decide what to do next: make some request to server (for new comments in post or for new messages in chat and etc.) or, maybe, do nothing. Job of WSS only say: “we have something new here” and nothing more.
Why we’ve chosen such scheme? Answer is very simple – to minimize a burden on WSS and … Yes one more important moment – to make universal mechanism of communication. WSS does not have any handles for some situations. WSS only reads and sends events – nothing more. And it allows to developers use WSS in own projects. Everything what developer needs – save event in database (sever part), call wakeup command (client part) and make handle for event on client part (a reaction of client on event).