Skip to content

Commit 58f16fc

Browse files
authored
Merge pull request #124 from hhxsv5/master
subscribe channel without loop restart
2 parents dc5ed3a + e0b4af1 commit 58f16fc

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ $channels = [
122122
$api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
123123
var_dump($message);
124124

125+
// Subscribe another channel
126+
// $ws->send(json_encode($api->createSubscribeMessage('/market/ticker:LTC-BTC')));
127+
125128
// Unsubscribe the channel
126129
// $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC')));
127130

examples/WebSocketFeed.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
$api->subscribePublicChannels($query, $channels, function (array $message, WebSocket $ws, LoopInterface $loop) use ($api) {
3333
var_dump($message);
3434

35+
// Subscribe another channel
36+
// $ws->send(json_encode($api->createSubscribeMessage('/market/ticker:LTC-BTC')));
37+
3538
// Unsubscribe the channel
3639
// $ws->send(json_encode($api->createUnsubscribeMessage('/market/ticker:ETH-BTC')));
3740

src/Api.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ abstract class Api
1616
/**
1717
* @var string SDK Version
1818
*/
19-
const VERSION = '1.1.26';
19+
const VERSION = '1.1.27';
2020

2121
/**
2222
* @var string SDK update date
2323
*/
24-
const UPDATE_DATE = '2022.02.27';
24+
const UPDATE_DATE = '2022.03.25';
2525

2626
/**
2727
* @var string

src/PrivateApi/WebSocketFeed.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function subscribePrivateChannel(array $query, array $channel, callable $
287287
}
288288

289289
/**
290-
* Create message for ping
290+
* Create a ping message
291291
* @param string $id
292292
* @return array
293293
*/
@@ -297,7 +297,20 @@ public function createPingMessage($id = null)
297297
}
298298

299299
/**
300-
* Create message for unsubscribe
300+
* Create a subscription message
301+
* @param string $topic
302+
* @param bool $privateChannel
303+
* @param bool $response
304+
* @param string $id
305+
* @return array
306+
*/
307+
public function createSubscribeMessage($topic, $privateChannel = false, $response = true, $id = null)
308+
{
309+
return ['id' => $id ?: uniqid('', true), 'type' => 'subscribe', 'topic' => $topic, 'privateChannel' => $privateChannel, 'response' => $response];
310+
}
311+
312+
/**
313+
* Create an unsubscribe message
301314
* @param string $topic
302315
* @param bool $privateChannel
303316
* @param bool $response

0 commit comments

Comments
 (0)