clients = new SplObjectStorage(); $this->api = new ApiAgente(); $this->atendimento = new Atendimento(); } public function onOpen(ConnectionInterface $conn) { try { $headers = $conn->httpRequest->getHeaders(); $conn->send($conn->resourceId); $this->clients->attach($conn); $this->connection[$conn->resourceId] = null; $this->shell[$conn->resourceId] = null; $this->conectado[$conn->resourceId] = null; $this->idConexion[$conn->resourceId] = null; $this->clientes[$conn->resourceId] = [ "matricula" => 'testwe', "conection" => $conn ]; } catch (\Exception $th) { logger('ws:onOpen')->debug(var_export($headers, true)); } } public function onMessage(ConnectionInterface $from, $msg) { try { $mensagem = json_decode($msg, true); if ($mensagem['matricula']) { $this->clientes[$from->resourceId]['matricula'] = $mensagem['matricula']; } else { foreach ($this->clientes as $key => $value) { if ($mensagem['event']['mensagem']['dst'] == $value['matricula']) { $value['conection']->send($msg); } } } } catch (\Exception $th) { logger('ws:onMessage')->debug($th->getMessage()); } } public function onClose(ConnectionInterface $conn) { try { $this->conectado[$conn->resourceId] = false; $this->clients->detach($conn); $this->api->logoff($this->clientes[$conn->resourceId], false); } catch (\Exception $th) { logger('ws:onClose')->debug($th->getMessage()); } } public function onError(ConnectionInterface $conn, \Exception $e) { $conn->close(); } }