/** * Derives a remote for a given connection. * * @param \Phergie\Irc\ConnectionInterface $connection * @return string Remote usable to establish a socket connection */ protected function getRemote(ConnectionInterface $connection) { $hostname = $connection->getServerHostname(); $port = $connection->getServerPort(); $deferred = new Deferred(); $this->getResolver()->resolve($hostname)->then(function ($ip) use($deferred, $port) { $deferred->resolve('tcp://' . $ip . ':' . $port); }, function ($error) use($deferred) { $deferred->reject($error); }); return $deferred->promise(); }
/** * @param ConnectionInterface $connection */ public function create(ConnectionInterface $connection) { if ($this->stream) { $this->disconnect(); } $hostname = $connection->getServerHostname(); $port = $connection->getServerPort(); $this->getConnector()->create($hostname, $port)->then(function (Stream $stream) use($connection) { $this->setStream($stream); $this->setConnectionDetails($connection); $this->api->getEmitter()->emit('irc.connect', [$stream, $connection]); $this->write($this->api->getGenerator()->ircNick($connection->getNickname())); $this->write($this->api->getGenerator()->ircUser($connection->getNickname(), gethostname(), $connection->getNickname(), $connection->getUsername())); $stream->on('data', [$this, 'processData']); }); }