From 95d1ec4cf9aff28ee053b7fc90b631617e28b85a Mon Sep 17 00:00:00 2001 From: COOL Date: Sun, 27 Mar 2022 10:01:13 +0800 Subject: [PATCH] 5.x --- package.json | 35 ++++++++++++----------- src/configuration.ts | 3 ++ src/modules/base/controller/admin/open.ts | 10 +------ src/modules/demo/socket/hello.ts | 26 +++++++++++++++++ 4 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 src/modules/demo/socket/hello.ts diff --git a/package.json b/package.json index d5193df..9a42f9b 100755 --- a/package.json +++ b/package.json @@ -5,40 +5,41 @@ "private": true, "dependencies": { "@cool-midway/core": "^5.0.6", - "@cool-midway/es": "^5.0.1", - "@cool-midway/file": "^5.0.1", + "@cool-midway/es": "^5.0.2", + "@cool-midway/file": "^5.0.2", "@cool-midway/pay": "^5.0.0", "@cool-midway/rpc": "^5.0.1", "@cool-midway/task": "^5.0.1", - "@midwayjs/bootstrap": "^3.1.1", - "@midwayjs/core": "^3.1.1", - "@midwayjs/decorator": "^3.0.0", - "@midwayjs/info": "^3.1.1", - "@midwayjs/koa": "^3.1.1", + "@midwayjs/bootstrap": "^3.2.0", + "@midwayjs/core": "^3.2.0", + "@midwayjs/decorator": "^3.1.6", + "@midwayjs/info": "^3.2.0", + "@midwayjs/koa": "^3.2.0", "@midwayjs/logger": "^2.16.3", - "@midwayjs/orm": "^3.1.1", - "@midwayjs/static-file": "^3.1.1", - "@midwayjs/validate": "^3.1.1", - "@midwayjs/view-ejs": "^3.1.1", + "@midwayjs/orm": "^3.2.0", + "@midwayjs/socketio": "^3.2.0", + "@midwayjs/static-file": "^3.2.0", + "@midwayjs/validate": "^3.2.0", + "@midwayjs/view-ejs": "^3.2.0", "ipip-ipdb": "^0.6.0", "jsonwebtoken": "^8.5.1", "mini-svg-data-uri": "^1.4.4", "mysql2": "^2.3.3", "svg-captcha": "^1.4.0", - "typeorm": "^0.2.45" + "typeorm": "^0.3.3" }, "devDependencies": { - "@midwayjs/cli": "^1.3.0", - "@midwayjs/mock": "^3.1.1", + "@midwayjs/cli": "^1.3.1", + "@midwayjs/mock": "^3.2.0", "@types/jest": "^27.4.1", "@types/koa": "^2.13.4", "@types/node": "17", "cross-env": "^7.0.3", "jest": "^27.5.1", "mwts": "^1.3.0", - "swagger-ui-dist": "^4.6.1", - "ts-jest": "^27.1.3", - "typescript": "^4.6.2" + "swagger-ui-dist": "^4.9.1", + "ts-jest": "^27.1.4", + "typescript": "^4.6.3" }, "engines": { "node": ">=12.0.0" diff --git a/src/configuration.ts b/src/configuration.ts index 5fee341..92ac67c 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -8,6 +8,7 @@ import * as view from '@midwayjs/view-ejs'; import * as orm from '@midwayjs/orm'; import * as cool from '@cool-midway/core'; import * as file from '@cool-midway/file'; +// import * as socketio from '@midwayjs/socketio'; // import * as task from '@cool-midway/task'; // import * as pay from '@cool-midway/pay'; // import * as es from '@cool-midway/es'; @@ -25,6 +26,8 @@ import * as file from '@cool-midway/file'; staticFile, // typeorm https://typeorm.io 打不开? https://typeorm.biunav.com/zh/ orm, + // socketio http://www.midwayjs.org/docs/extensions/socketio + // socketio, // cool-admin 官方组件 https://www.cool-js.com cool, // 文件上传 阿里云存储 腾讯云存储 七牛云存储 diff --git a/src/modules/base/controller/admin/open.ts b/src/modules/base/controller/admin/open.ts index 46e1b00..46e69a8 100644 --- a/src/modules/base/controller/admin/open.ts +++ b/src/modules/base/controller/admin/open.ts @@ -1,12 +1,4 @@ -import { - Provide, - Body, - ALL, - Inject, - Post, - Get, - Query, -} from '@midwayjs/decorator'; +import { Provide, Body, Inject, Post, Get, Query } from '@midwayjs/decorator'; import { CoolController, BaseController, CoolEps } from '@cool-midway/core'; import { LoginDTO } from '../../dto/login'; import { BaseSysLoginService } from '../../service/sys/login'; diff --git a/src/modules/demo/socket/hello.ts b/src/modules/demo/socket/hello.ts new file mode 100644 index 0000000..a0385a0 --- /dev/null +++ b/src/modules/demo/socket/hello.ts @@ -0,0 +1,26 @@ +import { + WSController, + OnWSConnection, + Inject, + OnWSMessage, +} from '@midwayjs/decorator'; +import { Context } from '@midwayjs/socketio'; +/** + * 测试 + */ +@WSController('/') +export class HelloController { + @Inject() + ctx: Context; + + @OnWSConnection() + async onConnectionMethod() { + console.log('on client connect', this.ctx.id); + this.ctx.emit('data', '连接成功'); + } + + @OnWSMessage('myEvent') + async gotMessage(data) { + console.log('on data got', this.ctx.id, data); + } +}