Skip to content

Commit 94043fc

Browse files
committed
Send method on the client
1 parent a31e21b commit 94043fc

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/AsyncClient.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,24 @@ public function __construct(LoopInterface $loop, string $app, Transport $transpo
6060
public function subscribe(string $channel): ObservableInterface
6161
{
6262
$this->channels[$channel] = $channel;
63-
$this->socket->then(function (WebSocket $socket) use ($channel) {
64-
$socket->send(json_encode([
65-
'event' => 'pusher:subscribe',
66-
'data' => [
67-
'channel' => $channel,
68-
]
69-
]));
70-
});
63+
$this->send([
64+
'event' => 'pusher:subscribe',
65+
'data' => [
66+
'channel' => $channel,
67+
],
68+
]);
7169

7270
return $this->connection->filter(function (array $event) use ($channel) {
7371
return isset($event['channel']) && $event['channel'] == $channel;
7472
})->filter(function (array $event) use ($channel) {
7573
return $event['event'] !== 'pusher_internal:subscription_succeeded';
7674
});
7775
}
76+
77+
public function send(array $message)
78+
{
79+
$this->socket->then(function (WebSocket $socket) use ($message) {
80+
$socket->send(json_encode($message));
81+
});
82+
}
7883
}

0 commit comments

Comments
 (0)