diff --git a/src/BrainSocket/BrainSocketEventListener.php b/src/BrainSocket/BrainSocketEventListener.php index 46c28b5..3b53ec1 100644 --- a/src/BrainSocket/BrainSocketEventListener.php +++ b/src/BrainSocket/BrainSocketEventListener.php @@ -17,6 +17,10 @@ public function __construct(BrainSocketResponseInterface $response) { public function onOpen(ConnectionInterface $conn) { echo "Connection Established! \n"; $this->clients->attach($conn); + + foreach ($this->clients as $client) { ++ $client->send($this->response->make('someone_connected')); ++ } } public function onMessage(ConnectionInterface $from, $msg) { @@ -33,10 +37,18 @@ public function onMessage(ConnectionInterface $from, $msg) { public function onClose(ConnectionInterface $conn) { $this->clients->detach($conn); echo "Connection {$conn->resourceId} has disconnected\n"; + ++ foreach ($this->clients as $client) { ++ $client->send($this->response->make('someone_disconnected')); ++ } ++ ++ $this->clients->detach($conn); + echo "Connection {$conn->resourceId} has disconnected\n"; + } } public function onError(ConnectionInterface $conn, \Exception $e) { echo "An error has occurred: {$e->getMessage()}\n"; $conn->close(); } -} \ No newline at end of file +}