Skip to content

Commit

Permalink
Allow websocket URL to be defined during instantiation in WebsocketRe…
Browse files Browse the repository at this point in the history
…source
  • Loading branch information
matthiggins committed Nov 29, 2023
1 parent 577dfdf commit dd9b57c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Websockets/WebsocketResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@ class WebsocketResource
*/
protected $topic;

/**
* @var string
*/
protected $socketUrl;

/**
* WebsocketResource constructor.
*
* @param string $topic
* @param string $apiKey
*/
public function __construct(string $topic, string $apiKey)
public function __construct(string $topic, string $apiKey, string $socketUrl = self::SOCKET_URI)
{
$this->apiKey = $apiKey;
$this->topic = $topic;
$this->socketUrl = $socketUrl;
}

/**
* @param string $socketUrl
*/
public function setSocketUrl(string $socketUrl)
{
$this->socketUrl = $socketUrl;
}

/**
Expand All @@ -41,7 +55,7 @@ function () use ($onMessageCallback, $subscriptions) {
/**
* @var Websocket\Connection $connection
*/
$connection = yield Websocket\connect(self::SOCKET_URI . '/' . $this->topic);
$connection = yield Websocket\connect($this->socketUrl . '/' . $this->topic);
yield $connection->send('{"action":"auth", "params":"' . $this->apiKey . '"}');
yield $connection->send(
json_encode(
Expand Down

0 comments on commit dd9b57c

Please sign in to comment.