how can I fire broadcast event when a user goes offline

221 Views Asked by At

I have now created a controller and an endpoint that users call every few seconds to make sure they are online. At each call, I save the time of their last visit, and if no request is made to the user beyond the specified time, the user is considered offline. What I'm looking for now is for an event to run and broadcast a message when a user does not send any request beyond the specified time.

What is clear is that when an user is offline, no event is called and as a result nothing is done.

Several ways came to my mind to solve this problem and I finally decided to ask a question here.

  1. Call an artisan command every few seconds using different methods (such as daemon). That command gets the list of users who did not call the online endpoint beyond the specified time. And puts a broadcast in the queue list for each user who goes offline.
  2. Instead of calling continuously, use commonly called endpoints (such as the home page) to periodically call commands.

Is there a better way to do this?

0

There are 0 best solutions below