This commit is contained in:
2020-08-31 22:33:50 +08:00
parent 32913fa3e1
commit 8b583f2a4d
14 changed files with 450 additions and 102 deletions
+11 -5
View File
@@ -93,10 +93,9 @@ return [
],
'events' => [
Event::SERVER_WORKER_START => function () {
$path = APP_PATH . 'app/Websocket';
$websocket = Snowflake::get()->annotation->websocket;
// $websocket->path = $this->socketControllers;
$websocket->namespace = 'App\\Sockets\\';
$websocket->registration_notes();
$websocket->registration_notes($path, 'App\\Sockets\\');
},
Event::SERVER_HANDSHAKE => function (Request $request, Response $response) {
$this->error($request->fd . ' connect.');
@@ -105,8 +104,15 @@ return [
},
Event::SERVER_MESSAGE => function (\Swoole\WebSocket\Server $server, Frame $frame) {
$this->error('websocket SERVER_MESSAGE.');
return $server->push($frame->fd, 'hello word~');
if (is_null($json = json_decode($frame->data, true))) {
return $server->push($frame->fd, 'format error~');
}
$websocket = Snowflake::get()->annotation->websocket;
if ($websocket->has($json['path'])) {
return $websocket->runWith($json['path'], [$frame->fd, $json]);
} else {
return $server->push($frame->fd, 'hello word~');
}
},
Event::SERVER_CLOSE => function (int $fd) {
$this->error($fd . ' disconnect.');