[Vuejs]-Perform some backend functionality when browser tab is closed

0👍

You can achieve it with a websocket presence channels combined to a publishing. Redis handles a publishing/subscribing mechanism which allows you to react on real-time and trigger some Laravel code.

You need:

  • Laravel Echo client which connects to a presence channel ( https://github.com/tlaverdure/laravel-echo-server#presence-channels )

  • a Laravel Echo Server which publishes channel content to Redis

  • a Redis Server

  • an Artisan command which subscribes to Redis and retrieves channel’s content => some Laravel code (care, it must be a stand-alone process because PHP is not asynchronous!)

The mechanism is automatically triggered on joining but also on leaving and often the leaving means “tab closed”

Leave a comment