1 | <?php |
||
16 | class WebSocketServer extends StreamServer implements Countable, ReactiveInterface { |
||
17 | |||
18 | /** |
||
19 | * @var WebSocketClient[] |
||
20 | */ |
||
21 | protected $clients = []; |
||
22 | |||
23 | /** |
||
24 | * @var Reactor |
||
25 | */ |
||
26 | protected $reactor; |
||
27 | |||
28 | /** |
||
29 | * @param $resource |
||
30 | * @param Reactor $reactor |
||
31 | */ |
||
32 | public function __construct ($resource, Reactor $reactor) { |
||
37 | |||
38 | /** |
||
39 | * @return WebSocketClient |
||
40 | */ |
||
41 | public function accept () { |
||
48 | |||
49 | /** |
||
50 | * Sends a payload to all clients in the OK state. |
||
51 | * |
||
52 | * @param int $opCode |
||
53 | * @param string $payload |
||
54 | */ |
||
55 | public function broadcast (int $opCode, string $payload) { |
||
62 | |||
63 | /** |
||
64 | * @param string $payload |
||
65 | */ |
||
66 | public function broadcastBinary (string $payload) { |
||
69 | |||
70 | /** |
||
71 | * Sends a ping to all clients in the OK state. |
||
72 | * |
||
73 | * @param string $payload |
||
74 | */ |
||
75 | public function broadcastPing (string $payload = '') { |
||
78 | |||
79 | /** |
||
80 | * Sends a message to all clients in the OK state. |
||
81 | * |
||
82 | * @param string $text |
||
83 | */ |
||
84 | public function broadcastText (string $text) { |
||
87 | |||
88 | /** |
||
89 | * Closes and removes all clients. |
||
90 | * |
||
91 | * @param int $code |
||
92 | * @param string $reason |
||
93 | * @return StreamServer |
||
94 | */ |
||
95 | public function close (int $code = Frame::CLOSE_INTERRUPT, $reason = '') { |
||
107 | |||
108 | /** |
||
109 | * The number of clients attached. |
||
110 | * |
||
111 | * @return int |
||
112 | */ |
||
113 | public function count (): int { |
||
116 | |||
117 | /** |
||
118 | * @return WebSocketClient[] |
||
119 | */ |
||
120 | public function getClients () { |
||
123 | |||
124 | /** |
||
125 | * @param resource $resource |
||
126 | * @return WebSocketClient |
||
127 | */ |
||
128 | protected function newClient ($resource) { |
||
131 | |||
132 | /** |
||
133 | * Servers never get OOB data. |
||
134 | * |
||
135 | * @inheritDoc |
||
136 | */ |
||
137 | final public function onOutOfBand (): void { |
||
139 | |||
140 | /** |
||
141 | * @inheritDoc |
||
142 | */ |
||
143 | public function onReadable (): void { |
||
146 | |||
147 | /** |
||
148 | * Removes the client from the server and reactor. |
||
149 | * |
||
150 | * @param WebSocketClient $client |
||
151 | */ |
||
152 | public function remove (WebSocketClient $client) { |
||
156 | } |