diff --git a/src/Client.php b/src/Client.php index 39cfaa3..f9db70a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -29,7 +29,7 @@ class Client */ protected $client; - public function __construct(UriInterface $uri) + public function __construct(UriInterface $uri, array $options = []) { $this->uri = $uri; $host = $uri->getHost(); @@ -42,6 +42,8 @@ public function __construct(UriInterface $uri) $this->client = new Coroutine\Http\Client($host, $port, $ssl); + $this->client->set($options); + parse_str($this->uri->getQuery(), $query); $query = http_build_query($query); @@ -90,4 +92,9 @@ public function close(): bool { return $this->client->close(); } + + public function isConnected(): bool + { + return $this->client->connected; + } } diff --git a/src/ClientFactory.php b/src/ClientFactory.php index 02271ac..5345894 100644 --- a/src/ClientFactory.php +++ b/src/ClientFactory.php @@ -16,12 +16,12 @@ class ClientFactory { - public function create(string $uri, bool $autoClose = true): Client + public function create(string $uri, bool $autoClose = true, array $options = []): Client { if (! Str::startsWith($uri, ['ws://', 'wss://'])) { $uri = 'ws://' . $uri; } - $client = make(Client::class, ['uri' => new Uri($uri)]); + $client = make(Client::class, ['uri' => new Uri($uri), 'options' => $options]); if ($autoClose) { defer(function () use ($client) { $client->close();