From ae082606c315bc664e68f65027a89778bdb825d6 Mon Sep 17 00:00:00 2001 From: ap <951984189@qq.com> Date: Fri, 7 May 2021 13:23:23 +0800 Subject: [PATCH] =?UTF-8?q?socket=E6=94=AF=E6=8C=81=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=A9=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/app/modules/demo/socket/handler.ts | 19 +++++++++++++++++++ src/configuration.ts | 4 ++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/app/modules/demo/socket/handler.ts diff --git a/package.json b/package.json index 582a13e..b1fbab3 100755 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "midwayjs-cool-oss": "^1.0.12", "midwayjs-cool-queue": "^1.0.8", "midwayjs-cool-redis": "^1.1.6", + "midwayjs-cool-socket": "^1.0.7", "midwayjs-cool-wxpay": "^1.0.12", "mysql2": "^2.2.5", "svg-captcha": "^1.4.0", diff --git a/src/app/modules/demo/socket/handler.ts b/src/app/modules/demo/socket/handler.ts new file mode 100644 index 0000000..6c3ac75 --- /dev/null +++ b/src/app/modules/demo/socket/handler.ts @@ -0,0 +1,19 @@ +import { Provide } from '@midwayjs/decorator'; +import { CoolSocket, SocketEnvent } from 'midwayjs-cool-socket'; +import { Socket } from 'socket.io'; + +/** + * socket的事件 + */ +@Provide() +@CoolSocket('/') +export class SocketHandler { + /** + * 连接成功 + * @param data + */ + @SocketEnvent() + async connection(socket: Socket) { + console.log('socket事件', socket.id, socket.handshake.query); + } +} diff --git a/src/configuration.ts b/src/configuration.ts index c10f83f..64f9a74 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -8,7 +8,7 @@ import * as oss from 'midwayjs-cool-oss'; import * as redis from 'midwayjs-cool-redis'; import * as queue from 'midwayjs-cool-queue'; import * as alipay from 'midwayjs-cool-alipay'; -//import * as socket from 'midwayjs-cool-socket'; +import * as socket from 'midwayjs-cool-socket'; @Configuration({ // 注意组件顺序 cool 有依赖orm组件, 所以必须放在,orm组件之后 cool的其他组件必须放在cool 核心组件之后 @@ -28,7 +28,7 @@ import * as alipay from 'midwayjs-cool-alipay'; // 支付宝支付 alipay, // socket - //socket + socket, ], }) export class ContainerLifeCycle implements ILifeCycle {