/**
  * @param ConnectionInterface $connection
  */
 public function remove(ConnectionInterface $connection)
 {
     Debug::line(__CLASS__ . ': Remove [');
     $this->storage->detach($connection);
     Debug::line('-- WebSocket connection removed');
     Debug::line(']');
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function process()
 {
     Debug::line(__CLASS__ . ': Process [');
     $totalData = $this->storage->getTotalStatusData();
     $json = json_encode(['_rid' => $this->getMessageValue('_rid', false), 'total-status' => ['count' => count($totalData), 'list' => $totalData, 'memory' => ['current' => memory_get_usage(true), 'peak' => memory_get_peak_usage(true)]]]);
     $this->connection->send($json);
     Debug::line('-- Response Json: ' . $json);
     Debug::line(']');
     $this->connection = null;
     $this->storage = null;
 }
 /**
  * @inheritdoc
  */
 public function process()
 {
     Debug::line(__CLASS__ . ': Process [');
     if ($this->storage->isRegisteredClient($this->connection)) {
         $clientId = $this->storage->getRegisteredClientId($this->connection);
         $clientStatus = $this->getMessageValue('change-status.status', 1);
         $this->storage->changeClientStatus($clientId, $clientStatus);
     }
     Debug::line(']');
     $this->connection = null;
     $this->storage = null;
 }
Пример #4
0
 /**
  * @inheritdoc
  */
 public function process()
 {
     Debug::line(__CLASS__ . ': Process [');
     $clientId = $this->getMessageValue('register.id', false);
     if ($clientId !== false) {
         $clientStatus = $this->getMessageValue('register.status', 1);
         $this->storage->registerClient($this->connection, $clientId, $clientStatus);
     }
     Debug::line(']');
     $this->connection = null;
     $this->storage = null;
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 public function process()
 {
     Debug::line(__CLASS__ . ': Process [');
     $clientId = $this->getMessageValue('get-status.id', false);
     list($status, $connections) = $this->storage->getClientStatusData($clientId);
     $json = json_encode(['_rid' => $this->getMessageValue('_rid', false), 'status' => ['id' => $clientId, 'status' => $status, 'connections' => $connections]]);
     $this->connection->send($json);
     Debug::line('-- Response Json: ' . $json);
     Debug::line(']');
     $this->connection = null;
     $this->storage = null;
 }
Пример #6
0
 /**
  * @return mixed[]
  */
 public function getTotalStatusData()
 {
     Debug::line(__CLASS__ . ': Get total status data [');
     $result = [];
     foreach ($this->clientList as $clientId => &$data) {
         $result[$clientId]['status'] = $data['status'];
         $result[$clientId]['connections'] = count($data['connections']);
     }
     Debug::line('-- All status data obtained');
     Debug::line(']');
     return $result;
 }
Пример #7
0
 /**
  * @param ConnectionInterface $connection
  * @param string              $json
  */
 public function onMessage(ConnectionInterface $connection, $json)
 {
     Debug::line(__CLASS__ . ': Received message [');
     Debug::line('-- Json: ' . $json);
     if ($command = $this->commandDispatcher->create($json, $connection)) {
         $command->process();
         $command = null;
         unset($command);
     }
     Debug::line(']');
 }
Пример #8
0
 /**
  * @return mixed[]
  */
 protected function getCommandList()
 {
     if ($this->commandList === null) {
         Debug::line(__CLASS__ . ': Load commands [');
         $this->commandList = [];
         if (is_dir($this->commandFolder) && ($handler = opendir($this->commandFolder))) {
             while (false !== ($filename = readdir($handler))) {
                 $filePath = $this->commandFolder . $filename;
                 if (!in_array($filename, ['.', '..']) && !is_dir($filePath)) {
                     $className = preg_replace('/\\.php$/i', '', $filename);
                     $classFull = $this->commandNamespace . $className;
                     if (class_exists($classFull) && method_exists($classFull, 'identity') && ($identity = $classFull::identity())) {
                         Debug::line('-- Load command: ' . $classFull);
                         $this->commandList[$classFull] = $identity;
                     }
                 }
             }
         }
         Debug::line(']');
     }
     return $this->commandList;
 }