This repository was archived by the owner on Mar 24, 2025. It is now read-only.
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 12
12
use SwooleTW \Http \Server \Facades \Server ;
13
13
use SwooleTW \Http \Websocket \HandlerContract ;
14
14
use Illuminate \Contracts \Container \Container ;
15
+ use Swoole \WebSocket \Server as WebsocketServer ;
15
16
use SwooleTW \Http \Websocket \Rooms \RoomContract ;
16
17
use SwooleTW \Http \Exceptions \WebsocketNotSetInConfigException ;
17
18
@@ -129,7 +130,7 @@ public function onMessage($server, $frame)
129
130
*/
130
131
public function onClose ($ server , $ fd , $ reactorId )
131
132
{
132
- if (! $ this ->isServerWebsocket ($ fd ) || ! $ server instanceof Websocket ) {
133
+ if (! $ this ->isServerWebsocket ($ fd ) || ! $ server instanceof WebsocketServer ) {
133
134
return ;
134
135
}
135
136
@@ -229,7 +230,7 @@ protected function prepareWebsocket()
229
230
*/
230
231
protected function isServerWebsocket (int $ fd ): bool
231
232
{
232
- return $ this ->container ->make (Server::class)
233
+ return ( bool ) $ this ->container ->make (Server::class)
233
234
->connection_info ($ fd )['websocket_status ' ] ?? false ;
234
235
}
235
236
Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ public function shouldBroadcast(): bool
221
221
*/
222
222
public function isServerWebsocket (int $ fd ): bool
223
223
{
224
- return $ this ->server ->connection_info ($ fd )['websocket_status ' ] ?? false ;
224
+ return ( bool ) $ this ->server ->connection_info ($ fd )['websocket_status ' ] ?? false ;
225
225
}
226
226
227
227
/**
@@ -245,8 +245,11 @@ protected function getWebsocketConnections(): array
245
245
*/
246
246
public function shouldPushToDescriptor (int $ fd ): bool
247
247
{
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 ) $ fd : true ;
250
253
}
251
254
252
255
/**
Original file line number Diff line number Diff line change @@ -115,7 +115,7 @@ public function testShouldPushToDescriptor()
115
115
$ server = m::mock (Server::class);
116
116
$ server ->shouldReceive ('exist ' )
117
117
->with ($ fd = 1 )
118
- ->twice ( )
118
+ ->times ( 3 )
119
119
->andReturn (true );
120
120
121
121
$ pusher = Pusher::make ([
@@ -141,5 +141,17 @@ public function testShouldPushToDescriptor()
141
141
], $ server );
142
142
143
143
$ this ->assertFalse ($ pusher ->shouldPushToDescriptor ($ fd ));
144
+
145
+ $ pusher = Pusher::make ([
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 ($ pusher ->shouldPushToDescriptor ($ fd ));
144
156
}
145
157
}
You can’t perform that action at this time.
0 commit comments