topheman/webrtc-remote-control

beforeunload event not working on Safari Mobile

topheman opened this issue · 1 comments

On the remote side, the beforeunload event is subscribed so that conn.disconnect() could be called, to ensure the connexion to master closes when you close the window :

https://github.com/topheman/webrtc-remote-control/blob/master/packages/core/remote/src/core.remote.js#L69-L75

It seems the beforeunload event is not triggered on Safari Mobile. Is there a way to fix this ?

One way of fixing this could be to send a heartbeat on the datachannel from remote to master with a trace like this :

{
  "__HEARTBEAT": "2022-04-24T16:30:23.006Z"
}
  • This shouldn't be re-emitted on the data event to the end user
  • A heartbeat could be sent e every 5s or 10s
  • On master, a connexion could be removed after 2 periods of heartbeat have passed without any heart beat message

Questions :

  • Only do that on devices that don't support beforeunload ?
  • What about networking problems and if we disconnect a client that shouldn't be disconnected ? Find use cases