How to detect the end of a session

What are possible ways to detect whether a user has left?

I have some audios that I would like to be occupied only by one user. Once the user is gone, the audio should be free for other users to listen to.

How would you implement this?

Things I thought:

  • I could let ajax send a ping every … seconds and detect on the server if I don’t get a signal for … seconds
  • I could use Drab to peek at a hidden html tag with the audio_id every … seconds and see if I still find it

But are there easier solutions? Is there a signal if a session ends?

Many thanks for any help!

Best
Andreas

What are possible ways to detect whether a user has left?

You can open a websocket connection and “guess” that the user has left once the connection is dropped.

3 Likes

Ok, that is a good idea, so I could use something like Phoenix.Presence