WebSocket logic
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace NoccyLabs\Mercureact\Http\Middleware;
|
||||
|
||||
use NoccyLabs\Mercureact\Broker\TopicManager;
|
||||
use NoccyLabs\Mercureact\Broker\WsSubscriber;
|
||||
use NoccyLabs\Mercureact\Configuration;
|
||||
use NoccyLabs\React\WebSocket\WebSocketConnection;
|
||||
use NoccyLabs\React\WebSocket\WebSocketMiddleware;
|
||||
@ -59,13 +60,16 @@ class WebSocketHandler
|
||||
{
|
||||
$this->webSocketClients->attach($connection);
|
||||
|
||||
$connection->on('close', function () use ($connection) {
|
||||
$request = $connection->getServerRequest();
|
||||
$subscriber = new WsSubscriber($connection, $request, $this->topicManager);
|
||||
|
||||
$connection->on('close', function () use ($connection, $subscriber) {
|
||||
$this->webSocketClients->detach($connection);
|
||||
$this->topicManager->unsubscribe($subscriber);
|
||||
});
|
||||
|
||||
$request = $connection->getServerRequest();
|
||||
$topic = $request->getQueryParams()['topic'][0]??'';
|
||||
$connection->setGroup($topic);
|
||||
$this->topicManager->subscribe($subscriber, []);
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user