@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $this->userAuthSocketMapper = []; |
| 48 | 48 | |
| 49 | 49 | $this->mainRoutes(); |
| 50 | - include base_path() . '/routes/websocket.php'; |
|
| 50 | + include base_path().'/routes/websocket.php'; |
|
| 51 | 51 | $this->routes = WsRoute::getRoutes(); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | $this->resetSession($msg->session); |
| 76 | 76 | |
| 77 | - $this->resetAuth($msg,$from); |
|
| 77 | + $this->resetAuth($msg, $from); |
|
| 78 | 78 | |
| 79 | 79 | $route = $this->routes[$msg->route]; |
| 80 | 80 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | if ($data = \Session::getHandler()->read($session_id)) { |
| 179 | 179 | $data = @unserialize($data); |
| 180 | 180 | |
| 181 | - if ($data !== false && ! is_null($data) && is_array($data)) { |
|
| 181 | + if ($data !== false && !is_null($data) && is_array($data)) { |
|
| 182 | 182 | return $data; |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -210,17 +210,17 @@ discard block |
||
| 210 | 210 | * @param ConnectionInterface $from |
| 211 | 211 | * @throws WebSocketException |
| 212 | 212 | */ |
| 213 | - function resetAuth($msg,$from) |
|
| 213 | + function resetAuth($msg, $from) |
|
| 214 | 214 | { |
| 215 | 215 | $data = $this->readFromHandler($msg->session); |
| 216 | 216 | |
| 217 | - if(!empty($data)) |
|
| 217 | + if (!empty($data)) |
|
| 218 | 218 | { |
| 219 | 219 | $user_id = $this->getUserId($data); |
| 220 | 220 | /** @var User $user_model */ |
| 221 | 221 | $user_model = $this->getUserModel(); |
| 222 | 222 | $user = $user_model::find($user_id); |
| 223 | - if(!$user) |
|
| 223 | + if (!$user) |
|
| 224 | 224 | { |
| 225 | 225 | $this->error($msg, $from, 'There is no such user.'); |
| 226 | 226 | } |
@@ -228,8 +228,7 @@ |
||
| 228 | 228 | |
| 229 | 229 | $this->clients[$from->resourceId]->id = \Auth::id(); |
| 230 | 230 | $this->userAuthSocketMapper[\Auth::id()] = $from->resourceId; |
| 231 | - } |
|
| 232 | - else |
|
| 231 | + } else |
|
| 233 | 232 | { |
| 234 | 233 | $this->error($msg, $from, 'Unauthenticated.'); |
| 235 | 234 | } |
@@ -20,15 +20,15 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | function sendMessageToUser() |
| 22 | 22 | { |
| 23 | - $this->validate($this->request,[ |
|
| 23 | + $this->validate($this->request, [ |
|
| 24 | 24 | 'user_id'=>'required', |
| 25 | 25 | 'message' => 'required' |
| 26 | 26 | ]); |
| 27 | 27 | |
| 28 | 28 | $user_id = $this->request->user_id; |
| 29 | - $data = ['message'=>$this->request->message,'event'=>'receivedMessage']; |
|
| 29 | + $data = ['message'=>$this->request->message, 'event'=>'receivedMessage']; |
|
| 30 | 30 | |
| 31 | - $this->sendToUser($user_id,$data); |
|
| 31 | + $this->sendToUser($user_id, $data); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | function sendMessageToRoom() |
| 38 | 38 | { |
| 39 | - $this->validate($this->request,[ |
|
| 39 | + $this->validate($this->request, [ |
|
| 40 | 40 | 'room_id'=>'required', |
| 41 | 41 | 'message' => 'required' |
| 42 | 42 | ]); |
| 43 | 43 | $room_id = $this->request->room_id; |
| 44 | - $data = ['message'=>$this->request->message,'event'=>'RoomMessage']; |
|
| 45 | - $this->sendToRoom($room_id,$data); |
|
| 44 | + $data = ['message'=>$this->request->message, 'event'=>'RoomMessage']; |
|
| 45 | + $this->sendToRoom($room_id, $data); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | * @param $error |
| 26 | 26 | * @throws WebSocketException |
| 27 | 27 | */ |
| 28 | - function error($request,ConnectionInterface $from, $error) |
|
| 28 | + function error($request, ConnectionInterface $from, $error) |
|
| 29 | 29 | { |
| 30 | - if(env('APP_DEBUG')) |
|
| 30 | + if (env('APP_DEBUG')) |
|
| 31 | 31 | { |
| 32 | 32 | echo 'User error: '; |
| 33 | 33 | echo $error."\n"; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | 'event'=>'error', |
| 40 | 40 | 'message'=>$error |
| 41 | 41 | ]; |
| 42 | - $this->sendToWebSocketUser($from,$data); |
|
| 42 | + $this->sendToWebSocketUser($from, $data); |
|
| 43 | 43 | throw new WebSocketException(); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -47,17 +47,17 @@ discard block |
||
| 47 | 47 | * @param ConnectionInterface $conn |
| 48 | 48 | * @param $data |
| 49 | 49 | */ |
| 50 | - function sendToWebSocketUser(ConnectionInterface $conn,$data) |
|
| 50 | + function sendToWebSocketUser(ConnectionInterface $conn, $data) |
|
| 51 | 51 | { |
| 52 | - if(!is_array($data)) |
|
| 53 | - $data = ['msg'=>$data,'event'=>'default']; |
|
| 52 | + if (!is_array($data)) |
|
| 53 | + $data = ['msg'=>$data, 'event'=>'default']; |
|
| 54 | 54 | |
| 55 | - if(!isset($data['event'])) |
|
| 55 | + if (!isset($data['event'])) |
|
| 56 | 56 | { |
| 57 | 57 | $data['event'] = 'default'; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if(isset($this->route) && !array_key_exists('sender',$data)) |
|
| 60 | + if (isset($this->route) && !array_key_exists('sender', $data)) |
|
| 61 | 61 | $data['sender'] = $this->getSenderData(); |
| 62 | 62 | |
| 63 | 63 | $conn->send(json_encode($data)); |
@@ -68,17 +68,17 @@ discard block |
||
| 68 | 68 | * @param array $data |
| 69 | 69 | * @throws WebSocketException |
| 70 | 70 | */ |
| 71 | - function sendToUser($user_id,$data) |
|
| 71 | + function sendToUser($user_id, $data) |
|
| 72 | 72 | { |
| 73 | - if(!array_key_exists($user_id,$this->userAuthSocketMapper)) |
|
| 73 | + if (!array_key_exists($user_id, $this->userAuthSocketMapper)) |
|
| 74 | 74 | { |
| 75 | - $this->error($this->request,$this->conn,'No such user !'); |
|
| 75 | + $this->error($this->request, $this->conn, 'No such user !'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $resourceId = $this->userAuthSocketMapper[$user_id]; |
| 79 | 79 | /** @var ConnectionInterface $conn */ |
| 80 | 80 | $conn = $this->clients[$resourceId]->conn; |
| 81 | - $this->sendToWebSocketUser($conn,$data); |
|
| 81 | + $this->sendToWebSocketUser($conn, $data); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function sendBack($data) |
| 88 | 88 | { |
| 89 | - $this->sendToWebSocketUser($this->conn,$data); |
|
| 89 | + $this->sendToWebSocketUser($this->conn, $data); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -49,16 +49,18 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | function sendToWebSocketUser(ConnectionInterface $conn,$data) |
| 51 | 51 | { |
| 52 | - if(!is_array($data)) |
|
| 53 | - $data = ['msg'=>$data,'event'=>'default']; |
|
| 52 | + if(!is_array($data)) { |
|
| 53 | + $data = ['msg'=>$data,'event'=>'default']; |
|
| 54 | + } |
|
| 54 | 55 | |
| 55 | 56 | if(!isset($data['event'])) |
| 56 | 57 | { |
| 57 | 58 | $data['event'] = 'default'; |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | - if(isset($this->route) && !array_key_exists('sender',$data)) |
|
| 61 | - $data['sender'] = $this->getSenderData(); |
|
| 61 | + if(isset($this->route) && !array_key_exists('sender',$data)) { |
|
| 62 | + $data['sender'] = $this->getSenderData(); |
|
| 63 | + } |
|
| 62 | 64 | |
| 63 | 65 | $conn->send(json_encode($data)); |
| 64 | 66 | } |