Exemple #1
0
 protected function _onConnectPeer(&$connection)
 {
     while (isset($this->connections[$this->connections_dsc])) {
         $this->connections_dsc++;
     }
     if ($peer = new Peer($connection, $this->connections_dsc)) {
         $peer->setNonBlock();
         $this->connections[$this->connections_dsc] =& $peer;
         if (is_callable($this->event_accept)) {
             call_user_func_array($this->event_accept, [$peer]);
         }
         $peer->onDisconnect(function () use($peer) {
             error_log('Отсоединился пир ' . $peer->getDsc());
             unset($this->connections[$peer->getDsc()]);
             $this->_onDisconnectPeer($peer);
         });
         return true;
     } else {
         trigger_error('Peer connection error');
         return false;
     }
 }