File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 1212use  SwooleTW \Http \Server \Facades \Server ;
1313use  SwooleTW \Http \Websocket \HandlerContract ;
1414use  Illuminate \Contracts \Container \Container ;
15+ use  Swoole \WebSocket \Server  as  WebsocketServer ;
1516use  SwooleTW \Http \Websocket \Rooms \RoomContract ;
1617use  SwooleTW \Http \Exceptions \WebsocketNotSetInConfigException ;
1718
@@ -129,7 +130,7 @@ public function onMessage($server, $frame)
129130     */ 
130131    public  function  onClose ($ server$ fd$ reactorId
131132    {
132-         if  (! $ this isServerWebsocket ($ fd$ serverinstanceof  Websocket ) {
133+         if  (! $ this isServerWebsocket ($ fd$ serverinstanceof  WebsocketServer ) {
133134            return ;
134135        }
135136
@@ -229,7 +230,7 @@ protected function prepareWebsocket()
229230     */ 
230231    protected  function  isServerWebsocket (int  $ fdbool 
231232    {
232-         return  $ this container ->make (Server::class)
233+         return  ( bool )  $ this container ->make (Server::class)
233234            ->connection_info ($ fd'websocket_status ' ] ?? false ;
234235    }
235236
Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ public function shouldBroadcast(): bool
221221     */ 
222222    public  function  isServerWebsocket (int  $ fdbool 
223223    {
224-         return  $ this server ->connection_info ($ fd'websocket_status ' ] ?? false ;
224+         return  ( bool )  $ this server ->connection_info ($ fd'websocket_status ' ] ?? false ;
225225    }
226226
227227    /** 
@@ -245,8 +245,11 @@ protected function getWebsocketConnections(): array
245245     */ 
246246    public  function  shouldPushToDescriptor (int  $ fdbool 
247247    {
248-         return  $ this server ->exist ($ fd
249-             && ($ this broadcast  && $ this sender  !== (int ) $ fd
248+         if  (! $ this server ->exist ($ fd
249+             return  false ;
250+         }
251+ 
252+         return  $ this broadcast  ? $ this sender  !== (int ) $ fdtrue ;
250253    }
251254
252255    /** 
Original file line number Diff line number Diff line change @@ -115,7 +115,7 @@ public function testShouldPushToDescriptor()
115115        $ servermock (Server::class);
116116        $ servershouldReceive ('exist ' )
117117            ->with ($ fd1 )
118-             ->twice ( )
118+             ->times ( 3 )
119119            ->andReturn (true );
120120
121121        $ pushermake ([
@@ -141,5 +141,17 @@ public function testShouldPushToDescriptor()
141141        ], $ server
142142
143143        $ this assertFalse ($ pushershouldPushToDescriptor ($ fd
144+ 
145+         $ pushermake ([
146+             'opcode '  => 1 ,
147+             'sender '  => 1 ,
148+             'fds '  => [],
149+             'broadcast '  => false ,
150+             'assigned '  => false ,
151+             'event '  => 'event ' ,
152+             'message '  => 'message ' 
153+         ], $ server
154+ 
155+         $ this assertTrue ($ pushershouldPushToDescriptor ($ fd
144156    }
145157}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments