1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\LaravelWebSockets\Server; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use GuzzleHttp\Psr7\Response; |
7
|
|
|
use Psr\Http\Message\RequestInterface; |
8
|
|
|
use Ratchet\ConnectionInterface; |
9
|
|
|
use Ratchet\RFC6455\Messaging\MessageInterface; |
10
|
|
|
use Ratchet\WebSocket\MessageComponentInterface; |
11
|
|
|
|
12
|
|
|
class HealthHandler implements MessageComponentInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Handle the socket opening. |
16
|
|
|
* |
17
|
|
|
* @param \Ratchet\ConnectionInterface $connection |
18
|
|
|
* @return void |
19
|
|
|
*/ |
20
|
|
|
public function onOpen(ConnectionInterface $connection, RequestInterface $request = null) |
21
|
|
|
{ |
22
|
|
|
$response = new Response( |
23
|
|
|
200, |
24
|
|
|
['Content-Type' => 'application/json'], |
25
|
|
|
json_encode(['ok' => true]) |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
tap($connection)->send(\GuzzleHttp\Psr7\str($response))->close(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Handle the incoming message. |
33
|
|
|
* |
34
|
|
|
* @param \Ratchet\ConnectionInterface $connection |
35
|
|
|
* @param \Ratchet\RFC6455\Messaging\MessageInterface $message |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function onMessage(ConnectionInterface $connection, MessageInterface $message) |
39
|
|
|
{ |
40
|
|
|
// |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Handle the websocket close. |
45
|
|
|
* |
46
|
|
|
* @param \Ratchet\ConnectionInterface $connection |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function onClose(ConnectionInterface $connection) |
50
|
|
|
{ |
51
|
|
|
// |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Handle the websocket errors. |
56
|
|
|
* |
57
|
|
|
* @param \Ratchet\ConnectionInterface $connection |
58
|
|
|
* @param WebSocketException $exception |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function onError(ConnectionInterface $connection, Exception $exception) |
62
|
|
|
{ |
63
|
|
|
// |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|