Comment puis-je récupérer à partir d'un ordinateur client WebSocket aller dormir ou app va fond (Safari sur iPad)

StackOverflow https://stackoverflow.com/questions/8853048

Question

J'ai navigateur client Javascript qui ouvre un WebSocket (en utilisant socket.io) pour demander un début de processus de longue durée, et obtient ensuite un rappel lorsque le processus est terminé. Quand je reçois le rappel, mettre à jour la page Web pour informer l'utilisateur le processus terminé.

Cela fonctionne bien, sauf sur mon iPad quand je passe à une autre application, puis revenir (il ne fait jamais le rappel, parce que je suppose que l'application n'est pas en ligne à l'époque). Je suppose que la même chose va se passer sur un ordinateur portable ou un autre ordinateur qui sommeille en attendant le rappel.

Y at-il un moyen standard (ou tout autre moyen) pour faire face à ce scénario? Merci.

Pour référence, si vous souhaitez voir la page de problème, il est à http://amigen.perfectapi.com/

Était-ce utile?

La solution

There are a couple of things to consider in this scenario:

Detect the app going off/on line

See: Online and offline events.

When your app detects the online event after the computer wakes up you can get any information that you've missed.

For older web browsers you'll need to do this in a cleverer way. At Pusher we've added a ping - pong check between the client and server. If the client doesn't receive a ping within a certain amount of time it knows there's a connection problem. If the server sends a ping and doesn't get a pong back with a certain time it knows there's a problem.

A ping pong mechanism is defined in the spec but a way of sending a ping or pong hasn't been defined on the WebSocket API as yet.

Fetching missed information

Most realtime servers only deliver messages to connected to clients. If a client isn't connected, maybe due to temporary network disturbance or their computer has been asleep for a while, then those clients will miss the message.

Some frameworks do provide access to messages through a history/cache. For those that don't you'll need to detect the problem (as above) and then fetch any missed messages. A good way to do this is by providing a timestamp or sequence ID with each messages so you can make a call to your web server to say "give me all messages since X".

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top