mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
wip
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Client;
|
||||
|
||||
use App\Client\Connections\ControlConnection;
|
||||
use App\Logger\CliRequestLogger;
|
||||
use Ratchet\Client\WebSocket;
|
||||
use React\EventLoop\LoopInterface;
|
||||
use function Ratchet\Client\connect;
|
||||
@@ -15,16 +16,22 @@ class Client
|
||||
/** @var Configuration */
|
||||
protected $configuration;
|
||||
|
||||
/** @var CliRequestLogger */
|
||||
protected $logger;
|
||||
|
||||
public static $subdomains = [];
|
||||
|
||||
public function __construct(LoopInterface $loop, Configuration $configuration)
|
||||
public function __construct(LoopInterface $loop, Configuration $configuration, CliRequestLogger $logger)
|
||||
{
|
||||
$this->loop = $loop;
|
||||
$this->configuration = $configuration;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function share(string $sharedUrl, array $subdomains = [])
|
||||
{
|
||||
$this->logger->info("Sharing http://{$sharedUrl}");
|
||||
|
||||
foreach ($subdomains as $subdomain) {
|
||||
$this->connectToServer($sharedUrl, $subdomain);
|
||||
}
|
||||
@@ -32,7 +39,7 @@ class Client
|
||||
|
||||
protected function connectToServer(string $sharedUrl, $subdomain)
|
||||
{
|
||||
connect("ws://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__", [], [
|
||||
connect("ws://{$this->configuration->host()}:{$this->configuration->port()}/__expose_control__?authToken={$this->configuration->authToken()}", [], [
|
||||
'X-Expose-Control' => 'enabled',
|
||||
], $this->loop)
|
||||
->then(function (WebSocket $clientConnection) use ($sharedUrl, $subdomain) {
|
||||
@@ -40,8 +47,14 @@ class Client
|
||||
|
||||
$connection->authenticate($sharedUrl, $subdomain);
|
||||
|
||||
$connection->on('authenticationFailed', function ($data) {
|
||||
$this->logger->error("Authentication failed. Please check your authentication token and try again.");
|
||||
exit(1);
|
||||
});
|
||||
|
||||
$connection->on('authenticated', function ($data) {
|
||||
dump("Connected to http://$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}");
|
||||
$this->logger->info("Connected to http://$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}");
|
||||
|
||||
static::$subdomains[] = "$data->subdomain.{$this->configuration->host()}:{$this->configuration->port()}";
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user