Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Get user data in websocket handlers #984

Closed
S1ipKn0T opened this issue May 11, 2022 · 0 comments
Closed

Get user data in websocket handlers #984

S1ipKn0T opened this issue May 11, 2022 · 0 comments

Comments

@S1ipKn0T
Copy link

S1ipKn0T commented May 11, 2022

This is my onClose function code in WebSocketHandler.php file:

 public function onClose(ConnectionInterface $connection)
    {

        $allChannels = $this->channelManager->getChannels($connection->app->id);

        foreach ($allChannels as $channelData) {
            $data = $channelData;
        }
        dd($data);

        $this->channelManager->removeFromAllChannels($connection);

        DashboardLogger::disconnection($connection);

        StatisticsLogger::disconnection($connection);
    }

and when the user closes the tab or browser my onClose function gives me $data in console logging which is this response:

BeyondCode\LaravelWebSockets\WebSockets\Channels\PresenceChannel {#719
  #users: array:1 [
    1 => array:9 [
      "id" => 1
      "email" => "[email protected]"
      "username" => "BlackHill"
      "type" => 0
      "steam_id" => "76561198107211703"
      "stay_login" => 0
      "email_verified_at" => null
      "created_at" => "2022-03-21T22:54:53.000000Z"
      "updated_at" => "2022-04-23T20:13:19.000000Z"
    ]
  ]
  #sockets: array:1 [
    "161595151.817952840" => "1"
  ]
  #channelName: "presence-users"
}

I need to access #users array to apply changes to any user who leaves.
In this issue they managed to get channelName but I did not get #users using their solution!

@S1ipKn0T S1ipKn0T reopened this May 11, 2022
@mpociot mpociot closed this as completed Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants