public function onData($data)
 {
     try {
         $this->_lastChanged = time();
         if ($this->_connection) {
             $this->_connection->readFrame($data);
         } else {
             $this->establishConnection($data);
         }
     } catch (Exception $e) {
         $this->disconnect();
     }
 }
Example #2
0
 public function onMessage(IWebSocketConnection $connection, IWebSocketMessage $msg)
 {
     try {
         if ($connection->getAdminKey() == $this->getAdminKey()) {
             $this->dispatchAdminMessage($connection, $msg);
         } else {
             $this->dispatchMessage($connection, $msg);
         }
     } catch (Exception $e) {
         $this->say("Exception occurred while handling message:\r\n" . $e->getTraceAsString());
     }
 }
Example #3
0
 public function onConnect(IWebSocketConnection $user)
 {
     if ($user->getAdminKey() == self::$ADMIN_KEY) {
         $this->say("[ECHO] Admin user connected");
         return;
     }
     $h = $user->getHeaders();
     $c = WebSocketFunctions::cookie_parse($h["Cookie"]);
     $client = new HttpClient($this->host);
     $client->cookies = $c;
     $client->get("/{$this->path}/?get_action=ws_authenticate&key=" . self::$ADMIN_KEY);
     $registry = $client->getContent();
     //$this->say("[ECHO] Registry loaded".$registry);
     $xml = new DOMDocument();
     $xml->loadXML($registry);
     $xPath = new DOMXPath($xml);
     $err = $xPath->query("//message[@type='ERROR']");
     if ($err->length) {
         $this->say($err->item(0)->firstChild->nodeValue);
         $user->disconnect();
     } else {
         $userRepositories = array();
         $repos = $xPath->query("/tree/user/repositories/repo");
         foreach ($repos as $repo) {
             $repoId = $repo->attributes->getNamedItem("id")->nodeValue;
             $userRepositories[] = $repoId;
         }
         $user->ajxpRepositories = $userRepositories;
         $user->ajxpId = $xPath->query("/tree/user/@id")->item(0)->nodeValue;
         if ($xPath->query("/tree/user/@groupPath")->length) {
             $groupPath = $xPath->query("/tree/user/@groupPath")->item(0)->nodeValue;
             if (!empty($groupPath)) {
                 $user->ajxpGroupPath = $groupPath;
             }
         }
     }
     $this->say("[ECHO] User '" . $user->ajxpId . "' connected with " . count($user->ajxpRepositories) . " registered repositories ");
 }
Example #4
0
 public function onAdminMessage(IWebSocketConnection $user, IWebSocketMessage $msg)
 {
     $this->say("[DEMO] Admin Message received!");
     $frame = WebSocketFrame::create(WebSocketOpcode::PongFrame);
     $user->sendFrame($frame);
 }
 public function send(IWebSocketConnection $client, $str)
 {
     return $client->sendString($str);
 }