This commit is contained in:
Marcel Pociot
2020-04-24 16:10:38 +02:00
19 changed files with 1873 additions and 1562 deletions

View File

@@ -39,7 +39,9 @@ class Client
protected function connectToServer(string $sharedUrl, $subdomain)
{
connect("ws://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__?authToken={$this->configuration->authToken()}", [], [
$token = config('expose.auth_token');
connect("ws://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__?authToken={$token}", [], [
'X-Expose-Control' => 'enabled',
], $this->loop)
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain) {
@@ -47,6 +49,11 @@ class Client
$connection->authenticate($sharedUrl, $subdomain);
$clientConnection->on('close', function() {
$this->logger->error('Connection to server closed.');
exit(1);
});
$connection->on('authenticationFailed', function ($data) {
$this->logger->error("Authentication failed. Please check your authentication token and try again.");
exit(1);

View File

@@ -13,18 +13,13 @@ class Configuration
/** @var string|null */
protected $auth;
/** @var string|null */
protected $authToken;
public function __construct(string $host, int $port, ?string $auth = null, string $authToken = null)
public function __construct(string $host, int $port, ?string $auth = null)
{
$this->host = $host;
$this->port = $port;
$this->auth = $auth;
$this->authToken = $authToken;
}
public function host(): string
@@ -41,9 +36,4 @@ class Configuration
{
return $this->port;
}
public function authToken()
{
return $this->authToken;
}
}

View File

@@ -27,9 +27,6 @@ class Factory
/** @var string */
protected $auth = '';
/** @var string */
protected $authToken = '';
/** @var \React\EventLoop\LoopInterface */
protected $loop;
@@ -62,13 +59,6 @@ class Factory
return $this;
}
public function setAuthToken(?string $authToken)
{
$this->authToken = $authToken;
return $this;
}
public function setLoop(LoopInterface $loop)
{
$this->loop = $loop;
@@ -79,7 +69,7 @@ class Factory
protected function bindConfiguration()
{
app()->singleton(Configuration::class, function ($app) {
return new Configuration($this->host, $this->port, $this->auth, $this->authToken);
return new Configuration($this->host, $this->port, $this->auth);
});
}