I'm using this bundle to integrate Ratchet websocket into my Symfony2 project: https://github.com/GeniusesOfSymfony/WebSocketBundle
I'm working on a chat application. The problem I encountered is how do I restrict access to the chat to logged in users?
The websocket is based on the WAMP PubSub protocol. My subscribe method in the ChatTopic class looks like this:
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request) {
$email = $this->clientManipulator->getClient($connection)->getUsername();
$user = $this->userRepository->getByEmail($email);
$msg = array();
$msg["type"] = "userJoined";
$msg["displayName"] = $user->getDisplayName();
$topic->broadcast(['msg' => json_encode($msg)]);
}
As you can see, I managed to get the user session inside my websocket and fetch all the user data from the db. I just don't know how to prevent unauthorized users from subscribing to the chat.
$connection->close(). - qooplmao