@@ -58,15 +58,24 @@ public function onOpen(Server $server, $swooleRequest)
58
58
$ illuminateRequest = Request::make ($ swooleRequest )->toIlluminate ();
59
59
60
60
try {
61
+ $ this ->websocket ->reset (true )->setSender ($ swooleRequest ->fd );
62
+ // set currnt request to sandbox
63
+ $ this ->sandbox ->setRequest ($ illuminateRequest );
64
+ // enable sandbox
65
+ $ application = $ this ->sandbox ->getLaravelApp ();
66
+ $ this ->sandbox ->enable ();
61
67
// check if socket.io connection established
62
68
if (! $ this ->websocketHandler ->onOpen ($ swooleRequest ->fd , $ illuminateRequest )) {
63
69
return ;
64
70
}
65
- $ this ->websocket ->reset (true )->setSender ($ swooleRequest ->fd );
66
71
// trigger 'connect' websocket event
67
72
if ($ this ->websocket ->eventExists ('connect ' )) {
68
- $ this ->callOnConnect ($ illuminateRequest );
73
+ // set sandbox container to websocket pipeline
74
+ $ this ->websocket ->setContainer ($ application );
75
+ $ this ->websocket ->call ('connect ' , $ illuminateRequest );
69
76
}
77
+ // disable and recycle sandbox resource
78
+ $ this ->sandbox ->disable ();
70
79
} catch (Exception $ e ) {
71
80
$ this ->logServerError ($ e );
72
81
}
@@ -93,12 +102,18 @@ public function onMessage(Server $server, Frame $frame)
93
102
94
103
$ this ->websocket ->reset (true )->setSender ($ frame ->fd );
95
104
105
+ // enable sandbox
106
+ $ application = $ this ->sandbox ->getLaravelApp ();
107
+ $ this ->sandbox ->enable ();
108
+
96
109
// dispatch message to registered event callback
97
110
if ($ this ->websocket ->eventExists ($ payload ['event ' ])) {
98
111
$ this ->websocket ->call ($ payload ['event ' ], $ payload ['data ' ]);
99
112
} else {
100
113
$ this ->websocketHandler ->onMessage ($ frame );
101
114
}
115
+ // disable and recycle sandbox resource
116
+ $ this ->sandbox ->disable ();
102
117
} catch (Exception $ e ) {
103
118
$ this ->logServerError ($ e );
104
119
}
@@ -279,27 +294,4 @@ protected function normalizePushData(array $data)
279
294
280
295
return [$ opcode , $ sender , $ fds , $ broadcast , $ assigned , $ event , $ message ];
281
296
}
282
-
283
- /**
284
- * Call on connect event callback .
285
- */
286
- protected function callOnConnect ($ illuminateRequest )
287
- {
288
- // set currnt request to sandbox
289
- $ this ->sandbox ->setRequest ($ illuminateRequest );
290
-
291
- // get application from sandbox
292
- $ application = $ this ->sandbox ->getLaravelApp ();
293
-
294
- // reset session
295
- if (isset ($ application ['session ' ])) {
296
- $ application ['session ' ]->flush ();
297
- }
298
-
299
- // set sandbox container to websocket pipeline
300
- $ this ->websocket ->setContainer ($ application );
301
- $ this ->sandbox ->enable ();
302
- $ this ->websocket ->call ('connect ' , $ illuminateRequest );
303
- $ this ->sandbox ->disable ();
304
- }
305
297
}
0 commit comments