1
1
<?php
2
+ /**
3
+ * @link https://github.com/consik/yii2-websocket
4
+ * @category yii2-extension
5
+ * @package consik\yii2websocket
6
+ *
7
+ * @author Sergey Poltaranin <consigliere.kz@gmail.com>
8
+ * @copyright Copyright (c) 2016
9
+ */
10
+
2
11
namespace consik \yii2websocket ;
3
12
4
13
use consik \yii2websocket \events \ExceptionEvent ;
17
26
18
27
class WebSocketServer extends Component implements MessageComponentInterface
19
28
{
29
+ /**
30
+ * @event yii\base\Event Triggered when binding is successfully completed
31
+ */
20
32
const EVENT_WEBSOCKET_OPEN = 'ws_open ' ;
33
+ /**
34
+ * @event yii\base\Event Triggered when socket listening is closed
35
+ */
21
36
const EVENT_WEBSOCKET_CLOSE = 'ws_close ' ;
37
+ /**
38
+ * @event ExceptionEvent Triggered when throwed Exception on binding socket
39
+ */
22
40
const EVENT_WEBSOCKET_OPEN_ERROR = 'ws_open_error ' ;
23
41
42
+ /**
43
+ * @event WSClientEvent Triggered when client connected to the server
44
+ */
24
45
const EVENT_CLIENT_CONNECTED = 'ws_client_connected ' ;
46
+ /**
47
+ * @event WSClientErrorEvent Triggered when an error occurs on a Connection
48
+ */
25
49
const EVENT_CLIENT_ERROR = 'ws_client_error ' ;
50
+ /**
51
+ * @event WSClientEvent Triggered when client close connection with server
52
+ */
26
53
const EVENT_CLIENT_DISCONNECTED = 'ws_client_disconnected ' ;
54
+ /**
55
+ * @event WSClientMessageEvent Triggered when message recieved from client
56
+ */
27
57
const EVENT_CLIENT_MESSAGE = 'ws_client_message ' ;
58
+ /**
59
+ * @event WSClientCommandEvent Triggered when controller starts user's command
60
+ */
28
61
const EVENT_CLIENT_RUN_COMMAND = 'ws_client_run_command ' ;
62
+ /**
63
+ * @event WSClientCommandEvent Triggered when controller finished user's command
64
+ */
29
65
const EVENT_CLIENT_END_COMMAND = 'ws_client_end_command ' ;
30
66
31
67
@@ -56,6 +92,9 @@ class WebSocketServer extends Component implements MessageComponentInterface
56
92
57
93
/**
58
94
* @return bool
95
+ *
96
+ * @event yii\base\Event EVENT_WEBSOCKET_OPEN
97
+ * @event ExceptionEvent EVENT_WEBSOCKET_OPEN_ERROR
59
98
*/
60
99
public function start ()
61
100
{
@@ -85,6 +124,8 @@ public function start()
85
124
86
125
/**
87
126
* @return void
127
+ *
128
+ * @event yii\base\Event EVENT_WEBSOCKET_CLOSE
88
129
*/
89
130
public function stop ()
90
131
{
@@ -180,15 +221,6 @@ function onMessage(ConnectionInterface $from, $msg)
180
221
*/
181
222
protected function getCommand (ConnectionInterface $ from , $ msg )
182
223
{
183
- /**
184
- * There u can parse message, check client rights, etc...
185
- *
186
- * Example:
187
- * Client sends json message like {"action":"chat", "text":"test message"}
188
- * if ($json = json_decode($msg)) { return $json['action'] }
189
- * If runMessageCommands == true && class method commandChat implemented,
190
- * Than will run $this->commandChat($client, $msg); $msg - source message string, $client - ConnectionInterface
191
- */
192
224
return null ;
193
225
}
194
- }
226
+ }
0 commit comments