Skip to content

Commit

Permalink
Merge pull request #124 from hhxsv5/master
Browse files Browse the repository at this point in the history
subscribe channel without loop restart
  • Loading branch information
hhxsv5 authored Mar 25, 2022
2 parents dc5ed3a + e0b4af1 commit 58f16fc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ $channels = [
$api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
var_dump($message);

// Subscribe another channel
// $ws->send(json_encode($api->createSubscribeMessage('/market/ticker:LTC-BTC')));

// Unsubscribe the channel
// $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC')));

Expand Down
3 changes: 3 additions & 0 deletions examples/WebSocketFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
$api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
var_dump($message);

// Subscribe another channel
// $ws->send(json_encode($api->createSubscribeMessage('/market/ticker:LTC-BTC')));

// Unsubscribe the channel
// $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC')));

Expand Down
4 changes: 2 additions & 2 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ abstract class Api
/**
* @var string SDK Version
*/
const VERSION = '1.1.26';
const VERSION = '1.1.27';

/**
* @var string SDK update date
*/
const UPDATE_DATE = '2022.02.27';
const UPDATE_DATE = '2022.03.25';

/**
* @var string
Expand Down
17 changes: 15 additions & 2 deletions src/PrivateApi/WebSocketFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function subscribePrivateChannel(array $query, array $channel, callable $
}

/**
* Create message for ping
* Create a ping message
* @param string $id
* @return array
*/
Expand All @@ -297,7 +297,20 @@ public function createPingMessage($id = null)
}

/**
* Create message for unsubscribe
* Create a subscription message
* @param string $topic
* @param bool $privateChannel
* @param bool $response
* @param string $id
* @return array
*/
public function createSubscribeMessage($topic, $privateChannel = false, $response = true, $id = null)
{
return ['id' => $id ?: uniqid('', true), 'type' => 'subscribe', 'topic' => $topic, 'privateChannel' => $privateChannel, 'response' => $response];
}

/**
* Create an unsubscribe message
* @param string $topic
* @param bool $privateChannel
* @param bool $response
Expand Down

0 comments on commit 58f16fc

Please sign in to comment.