loop = $loop; $this->configuration = $configuration; } public function share(string $sharedUrl, array $subdomains = []) { foreach ($subdomains as $subdomain) { $this->connectToServer($sharedUrl, $subdomain); } } protected function connectToServer(string $sharedUrl, $subdomain) { connect("ws://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__", [], [ 'X-Expose-Control' => 'enabled', ], $this->loop) ->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain) { $connection = ControlConnection::create($clientConnection); $connection->authenticate($sharedUrl, $subdomain); $connection->on('authenticated', function ($data) { dump("Connected to http://$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}"); static::$subdomains[] = "$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}"; }); }, function ($e) { echo "Could not connect: {$e->getMessage()}\n"; }); } }