Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -90,4 +92,9 @@ public function close(): bool
{
return $this->client->close();
}

public function isConnected(): bool
{
return $this->client->connected;
}
}
4 changes: 2 additions & 2 deletions src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down