66use Illuminate \Pipeline \Pipeline ;
77use Illuminate \Support \Arr ;
88use SwooleTW \Http \Exceptions \WebsocketNotSetInConfigException ;
9- use SwooleTW \Http \Helpers \Service ;
9+ use SwooleTW \Http \Helpers \Alias ;
10+ use SwooleTW \Http \Server \Facades \Server ;
11+ use SwooleTW \Http \Server \Sandbox ;
1012use SwooleTW \Http \Transformers \Request ;
1113use SwooleTW \Http \Websocket \HandlerContract ;
1214use SwooleTW \Http \Websocket \Parser ;
@@ -54,8 +56,8 @@ trait InteractsWithWebsocket
5456 public function onOpen ($ swooleRequest )
5557 {
5658 $ illuminateRequest = Request::make ($ swooleRequest )->toIlluminate ();
57- $ websocket = $ this ->app ->make (Service:: WEBSOCKET_ALIAS );
58- $ sandbox = $ this ->app ->make (Service:: SANDBOX_ALIAS );
59+ $ websocket = $ this ->app ->make (Websocket::class );
60+ $ sandbox = $ this ->app ->make (Sandbox::class );
5961
6062 try {
6163 $ websocket ->reset (true )->setSender ($ swooleRequest ->fd );
@@ -94,8 +96,8 @@ public function onMessage($server, $frame)
9496 return ;
9597 }
9698
97- $ websocket = $ this ->app ->make (Service:: WEBSOCKET_ALIAS );
98- $ sandbox = $ this ->app ->make (Service:: SANDBOX_ALIAS );
99+ $ websocket = $ this ->app ->make (Websocket::class );
100+ $ sandbox = $ this ->app ->make (Sandbox::class );
99101
100102 try {
101103 // decode raw message via parser
@@ -132,7 +134,7 @@ public function onClose($server, $fd, $reactorId)
132134 return ;
133135 }
134136
135- $ websocket = $ this ->app ->make (Service:: WEBSOCKET_ALIAS );
137+ $ websocket = $ this ->app ->make (Websocket::class );
136138
137139 try {
138140 $ websocket ->reset (true )->setSender ($ fd );
@@ -172,7 +174,7 @@ public function pushMessage($server, array $data)
172174
173175 // push message to designated fds
174176 foreach ($ push ->getDescriptors () as $ descriptor ) {
175- if ($ server ->exist ($ descriptor ) || ! $ push ->isBroadcastToDescriptor ((int )$ descriptor )) {
177+ if ($ server ->exist ($ descriptor ) || ! $ push ->isBroadcastToDescriptor ((int ) $ descriptor )) {
176178 $ server ->push ($ descriptor , $ payload , $ push ->getOpcode ());
177179 }
178180 }
@@ -205,7 +207,7 @@ public function getPayloadParser()
205207 */
206208 protected function prepareWebsocket ()
207209 {
208- $ config = $ this ->container ->make (Service:: CONFIG_ALIAS );
210+ $ config = $ this ->container ->make (Alias:: CONFIG );
209211 $ isWebsocket = $ config ->get ('swoole_http.websocket.enabled ' );
210212 $ parser = $ config ->get ('swoole_websocket.parser ' );
211213
@@ -225,7 +227,7 @@ protected function prepareWebsocket()
225227 */
226228 protected function isServerWebsocket (int $ fd ): bool
227229 {
228- $ info = $ this ->container ->make (Service:: SERVER_ALIAS )->connection_info ($ fd );
230+ $ info = $ this ->container ->make (Server::class )->connection_info ($ fd );
229231
230232 return Arr::has ($ info , 'websocket_status ' ) && Arr::get ($ info , 'websocket_status ' );
231233 }
@@ -253,7 +255,7 @@ protected function filterWebsocket(array $descriptors): array
253255 */
254256 protected function prepareWebsocketHandler ()
255257 {
256- $ handlerClass = $ this ->container ->make (Service:: CONFIG_ALIAS )->get ('swoole_websocket.handler ' );
258+ $ handlerClass = $ this ->container ->make (Alias:: CONFIG )->get ('swoole_websocket.handler ' );
257259
258260 if (! $ handlerClass ) {
259261 throw new WebsocketNotSetInConfigException ;
@@ -303,15 +305,15 @@ protected function createRoom(string $class, array $settings): RoomContract
303305 protected function bindRoom (): void
304306 {
305307 $ this ->app ->singleton (RoomContract::class, function (Container $ container ) {
306- $ config = $ container ->make (Service:: CONFIG_ALIAS );
308+ $ config = $ container ->make (Alias:: CONFIG );
307309 $ driver = $ config ->get ('swoole_websocket.default ' );
308310 $ settings = $ config ->get ("swoole_websocket.settings. {$ driver }" );
309311 $ className = $ config ->get ("swoole_websocket.drivers. {$ driver }" );
310312
311313 return $ this ->createRoom ($ className , $ settings );
312314 });
313315
314- $ this ->app ->alias (RoomContract::class, ' swoole.room ' );
316+ $ this ->app ->alias (RoomContract::class, Alias:: ROOM );
315317 }
316318
317319 /**
@@ -320,21 +322,21 @@ protected function bindRoom(): void
320322 protected function bindWebsocket ()
321323 {
322324 $ this ->app ->singleton (Websocket::class, function (Container $ app ) {
323- return new Websocket ($ app ->make (Service:: ROOM_ALIAS ), new Pipeline ($ app ));
325+ return new Websocket ($ app ->make (RoomContract::class ), new Pipeline ($ app ));
324326 });
325327
326- $ this ->app ->alias (Websocket::class, Service:: WEBSOCKET_ALIAS );
328+ $ this ->app ->alias (Websocket::class, ' swoole.websocket ' );
327329 }
328330
329331 /**
330332 * Load websocket routes file.
331333 */
332334 protected function loadWebsocketRoutes ()
333335 {
334- $ routePath = $ this ->container ->make (Service:: CONFIG_ALIAS )->get ('swoole_websocket.route_file ' );
336+ $ routePath = $ this ->container ->make (Alias:: CONFIG )->get ('swoole_websocket.route_file ' );
335337
336338 if (! file_exists ($ routePath )) {
337- $ routePath = __DIR__ . '/../../routes/websocket.php ' ;
339+ $ routePath = __DIR__ . '/../../routes/websocket.php ' ;
338340 }
339341
340342 return require $ routePath ;
0 commit comments