Scenario
I’m developing an online multiplayer game that uses XMPP (via WebSockets) to relay moves via an external component (ejabberd_service
). There is a chance that the Internet connection is patchy and drops off for a few seconds. I ideally want to handle this disruption in the following way:
- After 10 seconds, other users get notified that a given user is offline, but keep the connection open in case the user reconnects
- After 40 seconds, we give up waiting and close the connection. The user has to open a new connection to rejoin the game (or play a new game)
Problem
-
I know how to use
websocket_ping_interval
andwebsocket_timeout
to set a “hard timeout” that closes the connection after 40 seconds. This would send adisconnected
presence to the component, which can then inform the other users. However, in this setup there is no way for the other users to know after 10 seconds that the user is in the process of disconnecting. -
On the other hand, if I set
websocket_timeout
to 10 seconds, I can notify the other users immediately, but I’m also closing the connection early which gives less time for the disconnected user to reconnect.
Is there a way ejabberd can send some kind of “soft timeout” alert to my component after 10 seconds, but still keep the connection open for 40 seconds? It would be good to do it at the WebSocket level, so I can reduce data usage by sending less stanzas across.
Other considerations
-
I’m going on the assumption that closing a connection adds some overhead and should be avoided. If the overhead of closing and reopening the connection can be reduced (e.g. by using
mod_stream_mgmt
) then perhaps I could go with a hard timeout of 10 seconds and let the disconnected client negotiate a new connection (but resuming the same stream)? -
I looked at
mod_ping
, but I’m trying to handle this on the existing TCP/WebSocket level if possible to avoid the overhead of additional stanzas. Also, the only options fortimeout_action
arekill
andnone
; I couldn’t find any way to trigger something else (such as notifying my component).
My problem is different from ejabberd online status when user loses connection. That question is about message delivery failing because the client is offline. In my case, I am not sending any messages but want to be notified when a client has been unreachable for a certain amount of time (and I’m hoping to piggyback on whatever mechanism WebSockets uses to check that the connection is active).