public function onClose(ConnectionInterface $conn) { //Update Number of active users
$this->activeUserCount--;
//Update Memcached number of users $this->sharedCached->replace('userCount', $this->activeUserCount);
//Loop through all the rooms and unSubscribe them foreach ($conn->User->rooms as $topic => $one) { $this->onUnSubscribe($conn, $topic); } } function onUnSubscribe(ConnectionInterface $conn, $topic) { if(!$conn->User->verified){ $this->closeConnection($conn); return; } $topic = str_replace('"', '', $topic); $topic = strtolower($topic); //If room already is gone then return nothing if(!isset($this->roomLookup[$topic])){ return; } //get the Room id from the lookup array $roomID = $this->roomLookup[$topic]; unset($conn->User->rooms[$topic]); //See if the user exists in the room, if so remove it if($this->rooms[$roomID]->contains($conn)){ $this->rooms[$roomID]->detach($conn); } //Update Admin Console Room User Count $this->roomAdminConsole[$topic] = $this->rooms[$roomID]->count(); $this->sharedCached->replace("rooms", $this->roomAdminConsole);
//Check if the room is empty if so then delete it if ($this->rooms[$roomID]->count() == 0) { $this->closeRoom($roomID,$topic); }else{ //This is the Master user leaving the room. Destroy the entire room - We set the user type when we create the room if($conn->User->type == 1){ //Notify Everyone that the room has closed $this->broadcast($topic, array('type'=>self::TYPE_ROOMCLOSED, 'userID'=>$conn->WAMP->sessionId, 'userName'=>$conn->User->name), $conn); foreach ($this->rooms[$roomID] as $patron) { unset($patron->User->rooms[$roomID]); if($this->rooms[$roomID]->contains($patron)){ $this->rooms[$roomID]->detach($patron); } }
//This unsets the room variable's $this->closeRoom($roomID,$topic); return; } $this->broadcast($topic, array('type'=>self::TYPE_ROOMMEMBERLEFT, 'userID'=>$conn->WAMP->sessionId));
} } private function closeRoom($roomID,$roomName){ unset($this->rooms[$roomID]); unset($this->roomLookup[$roomName]); //Update Admin Console Room Count unset($this->roomAdminConsole[$roomName]); $this->sharedCached->replace("rooms", $this->roomAdminConsole); }Ratchet\Server\IoServer::factory(Object(Ratchet\WebSocket\WsServer), 443) #2 {main} thrown in /websocket/vendor/react/socket/React/Socket/Server.php on line 23 Errorexception 'Ratchet\Wamp\JsonException' with message 'Syntax error, malformed JSON' in /websocket/vendor/cboden/Ratchet/src/Ratchet/Wamp/ServerProtocol.php:89 Stack trace: #0 /websocket/vendor/cboden/Ratchet/src/Ratchet/WebSocket/Version/RFC6455.php(201): Ratchet\Wamp\ServerProtocol->onMessage(Object(Ratchet\WebSocket\Version\RFC6455\Connection), 'Rock it with HT...') #1 /websocket/vendor/cboden/Ratchet/src/Ratchet/WebSocket/WsServer.php(130): Ratchet\WebSocket\Version\RFC6455->onMessage(Object(Ratchet\WebSocket\Version\RFC6455\Connection), '???j/???L???[??...') #2 /websocket/vendor/cboden/Ratchet/src/Ratchet/Server/IoServer.php(103): Ratchet\WebSocket\WsServer->onMessage(Object(Ratchet\Server\IoConnection), '???j/???L???[??...') #3 [internal function]: Ratchet\Server\IoServer->handleData('???j/???L???[??...', Object(React\Socket\Connection)) #4 /websocket/vendor/evenement/evenement/src/Evenement/EventEmitter.php(70): call_user_func_array(Array, Array) #5 /websocket/vendor/react/socket/React/Socket/Connection.php(20): Evenement\EventEmitter->emit('data', Array) #6 [internal function]: React\Socket\Connection->handleData(Resource id #2315, Object(React\EventLoop\StreamSelectLoop)) #7 /websocket/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php(128): call_user_func(Array, Resource id #2315, Object(React\EventLoop\StreamSelectLoop)) #8 /websocket/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php(152): React\EventLoop\StreamSelectLoop->runStreamSelect() #9 /websocket/vendor/react/event-loop/React/EventLoop/StreamSelectLoop.php(162): React\EventLoop\StreamSelectLoop->tick() #10 /websocket/vendor/cboden/Ratchet/src/Ratchet/Server/IoServer.php(76): React\EventLoop\StreamSelectLoop->run() #11 /websocket/proConnect.php(556): Ratchet\Server\