Skip to content

Commit 1f8edb0

Browse files
authored
Update WebSocketServer.php
1 parent 76fd073 commit 1f8edb0

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

WebSocketServer.php

+42-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
<?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+
211
namespace consik\yii2websocket;
312

413
use consik\yii2websocket\events\ExceptionEvent;
@@ -17,15 +26,42 @@
1726

1827
class WebSocketServer extends Component implements MessageComponentInterface
1928
{
29+
/**
30+
* @event yii\base\Event Triggered when binding is successfully completed
31+
*/
2032
const EVENT_WEBSOCKET_OPEN = 'ws_open';
33+
/**
34+
* @event yii\base\Event Triggered when socket listening is closed
35+
*/
2136
const EVENT_WEBSOCKET_CLOSE = 'ws_close';
37+
/**
38+
* @event ExceptionEvent Triggered when throwed Exception on binding socket
39+
*/
2240
const EVENT_WEBSOCKET_OPEN_ERROR = 'ws_open_error';
2341

42+
/**
43+
* @event WSClientEvent Triggered when client connected to the server
44+
*/
2445
const EVENT_CLIENT_CONNECTED = 'ws_client_connected';
46+
/**
47+
* @event WSClientErrorEvent Triggered when an error occurs on a Connection
48+
*/
2549
const EVENT_CLIENT_ERROR = 'ws_client_error';
50+
/**
51+
* @event WSClientEvent Triggered when client close connection with server
52+
*/
2653
const EVENT_CLIENT_DISCONNECTED = 'ws_client_disconnected';
54+
/**
55+
* @event WSClientMessageEvent Triggered when message recieved from client
56+
*/
2757
const EVENT_CLIENT_MESSAGE = 'ws_client_message';
58+
/**
59+
* @event WSClientCommandEvent Triggered when controller starts user's command
60+
*/
2861
const EVENT_CLIENT_RUN_COMMAND = 'ws_client_run_command';
62+
/**
63+
* @event WSClientCommandEvent Triggered when controller finished user's command
64+
*/
2965
const EVENT_CLIENT_END_COMMAND = 'ws_client_end_command';
3066

3167

@@ -56,6 +92,9 @@ class WebSocketServer extends Component implements MessageComponentInterface
5692

5793
/**
5894
* @return bool
95+
*
96+
* @event yii\base\Event EVENT_WEBSOCKET_OPEN
97+
* @event ExceptionEvent EVENT_WEBSOCKET_OPEN_ERROR
5998
*/
6099
public function start()
61100
{
@@ -85,6 +124,8 @@ public function start()
85124

86125
/**
87126
* @return void
127+
*
128+
* @event yii\base\Event EVENT_WEBSOCKET_CLOSE
88129
*/
89130
public function stop()
90131
{
@@ -180,15 +221,6 @@ function onMessage(ConnectionInterface $from, $msg)
180221
*/
181222
protected function getCommand(ConnectionInterface $from, $msg)
182223
{
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-
*/
192224
return null;
193225
}
194-
}
226+
}

0 commit comments

Comments
 (0)