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

Get user data in websocket handlers #984

@S1ipKn0T

Description

@S1ipKn0T

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" => "sd@sd.com"
      "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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions