Files
expose/app/Client/Client.php
Marcel Pociot 2778d5a489 wip
2020-04-16 15:30:53 +02:00

42 lines
1.3 KiB
PHP

<?php
namespace App\Client;
use React\EventLoop\LoopInterface;
use React\Socket\ConnectionInterface;
use React\Socket\Connector;
class Client
{
/** @var LoopInterface */
protected $loop;
protected $host;
protected $port;
public static $subdomains = [];
public function __construct(LoopInterface $loop, $host, $port)
{
$this->loop = $loop;
$this->host = $host;
$this->port = $port;
}
public function share($sharedUrl, array $subdomains = [])
{
foreach ($subdomains as $subdomain) {
$connector = new Connector($this->loop);
$connector->connect("{$this->host}:{$this->port}")
->then(function (ConnectionInterface $clientConnection) use ($sharedUrl, $subdomain) {
$connection = Connection::create($clientConnection, new ProxyManager($this->host, $this->port, $this->loop));
$connection->authenticate($sharedUrl, $subdomain);
$clientConnection->on('authenticated', function ($data) {
static::$subdomains[] = "$data->subdomain.{$this->host}:{$this->port}";
dump("Connected to http://$data->subdomain.{$this->host}:{$this->port}");
});
});
}
}
}