@@ -22,7 +22,7 @@ |
||
| 22 | 22 | /** |
| 23 | 23 | * @param $request |
| 24 | 24 | * @param ConnectionInterface $from |
| 25 | - * @param $error |
|
| 25 | + * @param string $error |
|
| 26 | 26 | * @throws WebSocketException |
| 27 | 27 | */ |
| 28 | 28 | function error($request,ConnectionInterface $from, $error) |
@@ -25,7 +25,7 @@ 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 | 30 | echo 'Error: '; |
| 31 | 31 | echo $error."\n"; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | 'type'=>'error', |
| 37 | 37 | 'message'=>$error |
| 38 | 38 | ]; |
| 39 | - $this->sendToWebSocketUser($from,$data); |
|
| 39 | + $this->sendToWebSocketUser($from, $data); |
|
| 40 | 40 | throw new WebSocketException(); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -44,12 +44,12 @@ discard block |
||
| 44 | 44 | * @param ConnectionInterface $conn |
| 45 | 45 | * @param $data |
| 46 | 46 | */ |
| 47 | - function sendToWebSocketUser(ConnectionInterface $conn,$data) |
|
| 47 | + function sendToWebSocketUser(ConnectionInterface $conn, $data) |
|
| 48 | 48 | { |
| 49 | - if(!is_array($data)) |
|
| 49 | + if (!is_array($data)) |
|
| 50 | 50 | $data = ['msg'=>$data]; |
| 51 | 51 | |
| 52 | - if(isset($this->route) && $this->route->auth && !array_key_exists('sender',$data)) |
|
| 52 | + if (isset($this->route) && $this->route->auth && !array_key_exists('sender', $data)) |
|
| 53 | 53 | $data['sender'] = $this->getSenderData(); |
| 54 | 54 | |
| 55 | 55 | $conn->send(json_encode($data)); |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | * @param int $user_id |
| 60 | 60 | * @param array $data |
| 61 | 61 | */ |
| 62 | - function sendToUser($user_id,$data) |
|
| 62 | + function sendToUser($user_id, $data) |
|
| 63 | 63 | { |
| 64 | 64 | $resourceId = $this->userAuthSocketMapper[$user_id]; |
| 65 | 65 | /** @var ConnectionInterface $conn */ |
| 66 | 66 | $conn = $this->clients[$resourceId]->conn; |
| 67 | - $this->sendToWebSocketUser($conn,$data); |
|
| 67 | + $this->sendToWebSocketUser($conn, $data); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function sendBack($data) |
| 74 | 74 | { |
| 75 | - $this->sendToWebSocketUser($this->conn,$data); |
|
| 75 | + $this->sendToWebSocketUser($this->conn, $data); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | |
| 45 | 45 | function hasMember($client) |
| 46 | 46 | { |
| 47 | - if(array_key_exists($client->id,$this->members)) |
|
| 47 | + if (array_key_exists($client->id, $this->members)) |
|
| 48 | 48 | return true; |
| 49 | 49 | |
| 50 | 50 | return false; |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * @param $method |
| 25 | 25 | * @param bool $authenticated |
| 26 | 26 | */ |
| 27 | - function make($routeName, $controller, $method,$authenticated = true) |
|
| 27 | + function make($routeName, $controller, $method, $authenticated = true) |
|
| 28 | 28 | { |
| 29 | 29 | $this->routes[$routeName] = (object) [ |
| 30 | 30 | 'controller'=>$controller, |
@@ -19,9 +19,9 @@ |
||
| 19 | 19 | { |
| 20 | 20 | foreach ($required as $input) |
| 21 | 21 | { |
| 22 | - if(!in_array($input,(array)$this->request)) |
|
| 22 | + if (!in_array($input, (array) $this->request)) |
|
| 23 | 23 | { |
| 24 | - $this->error($this->request,$this->conn,$this->requireErrorMessage($input)); |
|
| 24 | + $this->error($this->request, $this->conn, $this->requireErrorMessage($input)); |
|
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $client = $this->clients[$this->userAuthSocketMapper[\Auth::id()]]; |
| 32 | 32 | $room->removeMember($client); |
| 33 | 33 | |
| 34 | - if(count($room->members) == 0) |
|
| 34 | + if (count($room->members) == 0) |
|
| 35 | 35 | { |
| 36 | 36 | unset($this->receiver->rooms[$room_id]); |
| 37 | 37 | } |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | * @param bool $createIfNotExist |
| 56 | 56 | * @return Room |
| 57 | 57 | */ |
| 58 | - function validateRoom($room_id,$createIfNotExist = false) |
|
| 58 | + function validateRoom($room_id, $createIfNotExist = false) |
|
| 59 | 59 | { |
| 60 | - if(!array_key_exists($room_id,$this->receiver->rooms)) |
|
| 60 | + if (!array_key_exists($room_id, $this->receiver->rooms)) |
|
| 61 | 61 | { |
| 62 | - if($createIfNotExist) |
|
| 62 | + if ($createIfNotExist) |
|
| 63 | 63 | { |
| 64 | 64 | $room = $this->receiver->rooms[$room_id] = new Room($room_id); |
| 65 | 65 | return $room; |
| 66 | 66 | } |
| 67 | - $this->error($this->request,$this->conn,'Room is not exist'); |
|
| 67 | + $this->error($this->request, $this->conn, 'Room is not exist'); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | /** @var Room $room */ |
| 79 | 79 | $room = $this->rooms[$room_id]; |
| 80 | 80 | $client = $this->clients[$this->userAuthSocketMapper[\Auth::id()]]; |
| 81 | - if(!$this->hasMember($client)) |
|
| 82 | - $this->error($this->request,$this->conn,'You can\'t send a message to room which you are not in !'); |
|
| 81 | + if (!$this->hasMember($client)) |
|
| 82 | + $this->error($this->request, $this->conn, 'You can\'t send a message to room which you are not in !'); |
|
| 83 | 83 | |
| 84 | 84 | foreach ($room->members as $member) |
| 85 | 85 | { |
| 86 | - $this->sendToUser($member->id,$message); |
|
| 86 | + $this->sendToUser($member->id, $message); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | \ No newline at end of file |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | function enterRoom($room_id) |
| 22 | 22 | { |
| 23 | - $this->validateRoom($room_id,true); |
|
| 23 | + $this->validateRoom($room_id, true); |
|
| 24 | 24 | |
| 25 | 25 | $this->addMember($room_id); |
| 26 | 26 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class WebSocketController |
| 24 | 24 | { |
| 25 | - use WebSocketMessagesManager,Validation; |
|
| 25 | + use WebSocketMessagesManager, Validation; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @var Client[] |
@@ -20,14 +20,14 @@ 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 | $user_id = $this->request->user_id; |
| 28 | 28 | $message = $this->request->message; |
| 29 | 29 | |
| 30 | - $this->sendToUser($user_id,$message); |
|
| 30 | + $this->sendToUser($user_id, $message); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function sendMessageToRoom() |
| 37 | 37 | { |
| 38 | - $this->validate($this->request,[ |
|
| 38 | + $this->validate($this->request, [ |
|
| 39 | 39 | 'room_id'=>'required', |
| 40 | 40 | 'message' => 'required' |
| 41 | 41 | ]); |
| 42 | 42 | $room_id = $this->request->room_id; |
| 43 | 43 | $message = $this->request->message; |
| 44 | 44 | |
| 45 | - $this->sendToRoom($room_id,$message); |
|
| 45 | + $this->sendToRoom($room_id, $message); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $msg = json_decode($msg); |
| 74 | 74 | |
| 75 | - $this->checkForRequiredInMessage($msg,$from); |
|
| 75 | + $this->checkForRequiredInMessage($msg, $from); |
|
| 76 | 76 | |
| 77 | 77 | \Session::setId($msg->session); |
| 78 | 78 | |
| 79 | 79 | \Session::start(); |
| 80 | 80 | |
| 81 | 81 | $route = $this->routes[$msg->route]; |
| 82 | - if($route->auth && !\Auth::check()) |
|
| 83 | - $this->error($msg,$from,'Unauthenticated.'); |
|
| 82 | + if ($route->auth && !\Auth::check()) |
|
| 83 | + $this->error($msg, $from, 'Unauthenticated.'); |
|
| 84 | 84 | else |
| 85 | 85 | $this->userAuthSocketMapper[\Auth::id()] = $from->resourceId; |
| 86 | 86 | |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | $method = $route->method; |
| 89 | 89 | $controller = new $class; |
| 90 | 90 | |
| 91 | - $this->cloneProperties($this,$controller); |
|
| 91 | + $this->cloneProperties($this, $controller); |
|
| 92 | 92 | |
| 93 | 93 | $controller->conn = $from; |
| 94 | 94 | $controller->receiver = $this; |
| 95 | 95 | $controller->request = $msg; |
| 96 | 96 | $controller->route = $route; |
| 97 | 97 | |
| 98 | - if(!method_exists($controller,$method)) |
|
| 98 | + if (!method_exists($controller, $method)) |
|
| 99 | 99 | { |
| 100 | - $this->error($msg,$from,'Method doesnt\'t exist !'); |
|
| 100 | + $this->error($msg, $from, 'Method doesnt\'t exist !'); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $controller->$method(); |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | { |
| 107 | 107 | |
| 108 | 108 | } |
| 109 | - catch(ValidationException $exception) |
|
| 109 | + catch (ValidationException $exception) |
|
| 110 | 110 | { |
| 111 | - $this->sendToWebSocketUser($from,[ |
|
| 111 | + $this->sendToWebSocketUser($from, [ |
|
| 112 | 112 | 'message'=>$exception->getMessage(), |
| 113 | 113 | 'errors'=> $exception->errors() |
| 114 | 114 | ]); |
@@ -143,15 +143,15 @@ discard block |
||
| 143 | 143 | * @param $from |
| 144 | 144 | * @throws WebSocketException |
| 145 | 145 | */ |
| 146 | - function checkForRequiredInMessage($msg,$from) |
|
| 146 | + function checkForRequiredInMessage($msg, $from) |
|
| 147 | 147 | { |
| 148 | - if(!isset($msg->route) || !isset($msg->session)) |
|
| 148 | + if (!isset($msg->route) || !isset($msg->session)) |
|
| 149 | 149 | { |
| 150 | - $this->error($msg,$from,'You can\'t send a request without the route and the session id !'); |
|
| 150 | + $this->error($msg, $from, 'You can\'t send a request without the route and the session id !'); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if(!isset($this->routes[$msg->route])) |
|
| 154 | - $this->error($msg,$from,'No such route !'); |
|
| 153 | + if (!isset($this->routes[$msg->route])) |
|
| 154 | + $this->error($msg, $from, 'No such route !'); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | function mainRoutes() |
| 169 | 169 | { |
| 170 | - WsRoute::make('initializeWebsocket','Shamaseen\Laravel\Ratchet\Controllers\InitializeController','index'); |
|
| 171 | - WsRoute::make('room-enter','Shamaseen\Laravel\Ratchet\Controllers\RoomController','enterRoom'); |
|
| 172 | - WsRoute::make('room-exit','Shamaseen\Laravel\Ratchet\Controllers\RoomController','exitRoom'); |
|
| 173 | - WsRoute::make('send-to-user','Shamaseen\Laravel\Ratchet\Controllers\ChatController','sendMessageToUser'); |
|
| 174 | - WsRoute::make('send-to-room','Shamaseen\Laravel\Ratchet\Controllers\ChatController','sendMessageToRoom'); |
|
| 170 | + WsRoute::make('initializeWebsocket', 'Shamaseen\Laravel\Ratchet\Controllers\InitializeController', 'index'); |
|
| 171 | + WsRoute::make('room-enter', 'Shamaseen\Laravel\Ratchet\Controllers\RoomController', 'enterRoom'); |
|
| 172 | + WsRoute::make('room-exit', 'Shamaseen\Laravel\Ratchet\Controllers\RoomController', 'exitRoom'); |
|
| 173 | + WsRoute::make('send-to-user', 'Shamaseen\Laravel\Ratchet\Controllers\ChatController', 'sendMessageToUser'); |
|
| 174 | + WsRoute::make('send-to-room', 'Shamaseen\Laravel\Ratchet\Controllers\ChatController', 'sendMessageToRoom'); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | \ No newline at end of file |