问题
I am building browser application with real-time updates.
Application allows to read and edit spreadsheet together with other people online.
However, some people have poor Internet connection and disconnects may occur.
I want application to be able to update to the latest data after Internet reconnection.
Currently Pusher and application work so:
- Pusher connects to server and receives events.
- Other people make changes in spreadsheet.
- Application receives these changes from Pusher and is able to reflect them on spreadsheet.
- At some moment Internet disappears.
- Pusher detects this and automatically tries to reconnect.
- Other people make changes in spreadsheet.
- Application can't receive these changes because there is not Internet connection.
- After some time, for example 5 minutes, Internet connection seems to be ok.
- Now Pusher successfully reconnects to server.
- However, Pusher doesn't receives events from period when there was no Internet connection (list item #6).
- Other people make changes.
- Pusher receives events and application is able to handle them.
So my problem is: Pusher doesn't receive events after automatic reconnect which were triggered by other people during Internet disconnection.
I am using default Pusher configuration, private channel, latest stable version and don't do any magic.
回答1:
Pusher does not currently provide this functionality. To implement this yourself you would have to send a numeric ID with each message that increases in value. You would also need to store a cache of all sent messages in a database. Clients can keep track of the last ID they received. After disconnecting and reconnecting, they can send a request to your server asking for all messages greater than the last message ID they received. Your server should respond with messages matching that query in your database.
来源:https://stackoverflow.com/questions/42097246/pusher-doesnt-receive-events-after-reconnect