@midwayjs/socketio 3.0.2 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,5 @@ export declare class MidwaySocketIOFramework extends BaseFramework<IMidwaySocket
13
13
  private addNamespace;
14
14
  private bindSocketResponse;
15
15
  getFrameworkName(): string;
16
- getDefaultContextLoggerClass(): any;
17
16
  }
18
17
  //# sourceMappingURL=framework.d.ts.map
package/dist/framework.js CHANGED
@@ -12,7 +12,6 @@ const util_1 = require("util");
12
12
  const debug = (0, util_1.debuglog)('midway:socket.io');
13
13
  const socket_io_1 = require("socket.io");
14
14
  const decorator_1 = require("@midwayjs/decorator");
15
- const logger_1 = require("./logger");
16
15
  let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseFramework {
17
16
  constructor() {
18
17
  super(...arguments);
@@ -159,9 +158,6 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
159
158
  getFrameworkName() {
160
159
  return 'midway:socketIO';
161
160
  }
162
- getDefaultContextLoggerClass() {
163
- return logger_1.MidwaySocketIOContextLogger;
164
- }
165
161
  };
166
162
  MidwaySocketIOFramework = __decorate([
167
163
  (0, decorator_1.Framework)()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/socketio",
3
- "version": "3.0.2",
3
+ "version": "3.0.6",
4
4
  "description": "Midway Web Framework for socket.io",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -19,20 +19,19 @@
19
19
  ],
20
20
  "files": [
21
21
  "dist/**/*.js",
22
- "dist/**/*.d.ts",
23
- "dist/**/*.js.map"
22
+ "dist/**/*.d.ts"
24
23
  ],
25
24
  "license": "MIT",
26
25
  "devDependencies": {
27
- "@midwayjs/decorator": "^3.0.2",
28
- "@midwayjs/mock": "^3.0.2",
26
+ "@midwayjs/decorator": "^3.0.6",
27
+ "@midwayjs/mock": "^3.0.6",
29
28
  "@types/socket.io-client": "1.4.36",
30
29
  "fs-extra": "10.0.0",
31
30
  "socket.io-client": "4.4.1"
32
31
  },
33
32
  "dependencies": {
34
- "@midwayjs/core": "^3.0.2",
35
- "@midwayjs/logger": "^2.14.0",
33
+ "@midwayjs/core": "^3.0.6",
34
+ "@midwayjs/logger": "^2.15.0",
36
35
  "socket.io": "4.4.1",
37
36
  "socket.io-redis": "^6.1.0"
38
37
  },
@@ -44,5 +43,5 @@
44
43
  "engines": {
45
44
  "node": ">=12"
46
45
  },
47
- "gitHead": "ca77247d229978a736e79bb208579c014ed226fc"
46
+ "gitHead": "afaa5b59a2be85e915233a9268c0e05965dd5c61"
48
47
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mDAAoD;AAKpD,IAAa,qBAAqB,GAAlC,MAAa,qBAAqB;CAAG,CAAA;AAAxB,qBAAqB;IAHjC,IAAA,yBAAa,EAAC;QACb,SAAS,EAAE,UAAU;KACtB,CAAC;GACW,qBAAqB,CAAG;AAAxB,sDAAqB","sourcesContent":["import { Configuration } from '@midwayjs/decorator';\n\n@Configuration({\n namespace: 'socketIO',\n})\nexport class SocketIOConfiguration {}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"framework.js","sourceRoot":"","sources":["../src/framework.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAKwB;AACxB,+BAAgC;AAChC,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,kBAAkB,CAAC,CAAC;AAO3C,yCAAmC;AACnC,mDAS6B;AAC7B,qCAAuD;AAGvD,IAAa,uBAAuB,GAApC,MAAa,uBAAwB,SAAQ,oBAI5C;IAJD;;QAKU,kBAAa,GAAG,EAAE,CAAC;IA0N7B,CAAC;IAxNC,SAAS;QACP,OAAO,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACzD,CAAC;IAED,qBAAq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CAAC;IAEO,KAAK,CAAC,kBAAkB,CAC9B,MAAW,EACX,MAA8B,EAC9B,YAAoB,EACpB,SAEC;QAED,IAAI,MAAM,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE;YACrC,KAAK,MAAM,WAAW,IAAI,SAAS,CAAC,YAAY,CAAC,CAAC,cAAc,EAAE;gBAChE,IAAI,WAAW,CAAC,SAAS,KAAK,2BAAe,CAAC,IAAI,EAAE;oBAClD,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE;wBAC/B,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;4BACpD,OAAO,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;wBACzB,CAAC,EAAE,MAAM,CAAC,CAAC;qBACZ;oBACD,yCAAyC;oBACzC,MAAM,CAAC,IAAI,CAAC,KAAK,CACf,MAAM,EACN,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAC9C,CAAC;iBACH;qBAAM,IAAI,WAAW,CAAC,SAAS,KAAK,2BAAe,CAAC,SAAS,EAAE;oBAC9D,yCAAyC;oBACzC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;iBACtD;aACF;SACF;IACH,CAAC;IAEM,gBAAgB;QACrB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAEM,4BAA4B;QACjC,OAAO,oCAA2B,CAAC;IACrC,CAAC;CACF,CAAA;AA/NY,uBAAuB;IADnC,IAAA,qBAAS,GAAE;GACC,uBAAuB,CA+NnC;AA/NY,0DAAuB","sourcesContent":["import {\n BaseFramework,\n HTTP_SERVER_KEY,\n IMidwayBootstrapOptions,\n MidwayFrameworkType,\n} from '@midwayjs/core';\nimport { debuglog } from 'util';\nconst debug = debuglog('midway:socket.io');\n\nimport {\n IMidwaySocketIOApplication,\n IMidwaySocketIOConfigurationOptions,\n IMidwaySocketIOContext,\n} from './interface';\nimport { Server } from 'socket.io';\nimport {\n WS_CONTROLLER_KEY,\n WS_EVENT_KEY,\n WSControllerOption,\n WSEventInfo,\n WSEventTypeEnum,\n getClassMetadata,\n listModule,\n Framework,\n} from '@midwayjs/decorator';\nimport { MidwaySocketIOContextLogger } from './logger';\n\n@Framework()\nexport class MidwaySocketIOFramework extends BaseFramework<\n IMidwaySocketIOApplication,\n IMidwaySocketIOContext,\n IMidwaySocketIOConfigurationOptions\n> {\n private namespaceList = [];\n\n configure(): IMidwaySocketIOConfigurationOptions {\n return this.configService.getConfiguration('socketIO');\n }\n\n applicationInitialize(options: IMidwayBootstrapOptions) {\n this.app = new Server(\n this.configurationOptions\n ) as IMidwaySocketIOApplication;\n }\n public app: IMidwaySocketIOApplication;\n\n protected async afterContainerReady(\n options: Partial<IMidwayBootstrapOptions>\n ): Promise<void> {\n await this.loadMidwayController();\n }\n\n public async run(): Promise<void> {\n if (this.configurationOptions.adapter) {\n this.app.adapter(this.configurationOptions.adapter);\n this.logger.debug('init socket.io-redis ready!');\n }\n\n // listen port when http server not exist\n if (this.configurationOptions.port) {\n this.app.listen(\n this.configurationOptions.port,\n this.configurationOptions\n );\n this.logger.info(\n `Socket.io server port = ${this.configurationOptions.port} start success`\n );\n } else if (this.applicationContext.hasObject(HTTP_SERVER_KEY)) {\n this.app.attach(\n this.applicationContext.get(HTTP_SERVER_KEY),\n this.configurationOptions\n );\n this.logger.info(\n 'Socket.io server start success and attach to web server'\n );\n }\n }\n\n protected async beforeStop(): Promise<void> {\n return new Promise<void>(resolve => {\n this.app.close(() => {\n setTimeout(() => {\n resolve();\n }, 1000);\n });\n });\n }\n\n public getFrameworkType(): MidwayFrameworkType {\n return MidwayFrameworkType.WS_IO;\n }\n\n private async loadMidwayController() {\n // create room\n const controllerModules = listModule(WS_CONTROLLER_KEY);\n for (const module of controllerModules) {\n await this.addNamespace(module);\n }\n }\n\n private async addNamespace(target: any) {\n const controllerOption: WSControllerOption = getClassMetadata(\n WS_CONTROLLER_KEY,\n target\n );\n\n const nsp = this.app.of(controllerOption.namespace);\n this.namespaceList.push(controllerOption.namespace);\n\n nsp.use((socket: any, next) => {\n this.app.createAnonymousContext(socket);\n socket.requestContext.registerObject('socket', socket);\n socket.app = this.app;\n next();\n });\n\n nsp.on('connect', async (socket: IMidwaySocketIOContext) => {\n const wsEventInfos: WSEventInfo[] = getClassMetadata(\n WS_EVENT_KEY,\n target\n );\n\n // 存储方法对应的响应处理\n const methodMap = {};\n\n if (wsEventInfos.length) {\n for (const wsEventInfo of wsEventInfos) {\n methodMap[wsEventInfo.propertyName] = methodMap[\n wsEventInfo.propertyName\n ] || { responseEvents: [] };\n const controller = await socket.requestContext.getAsync(target);\n // on connection\n if (wsEventInfo.eventType === WSEventTypeEnum.ON_CONNECTION) {\n try {\n const result = await controller[wsEventInfo.propertyName].apply(\n controller,\n [socket]\n );\n await this.bindSocketResponse(\n result,\n socket,\n wsEventInfo.propertyName,\n methodMap\n );\n } catch (err) {\n this.logger.error(err);\n }\n } else if (wsEventInfo.eventType === WSEventTypeEnum.ON_MESSAGE) {\n // on user custom event\n socket.on(wsEventInfo.messageEventName, async (...args) => {\n debug('got message', wsEventInfo.messageEventName, args);\n\n try {\n const result = await (\n await this.applyMiddleware(async (ctx, next) => {\n // eslint-disable-next-line prefer-spread\n return controller[wsEventInfo.propertyName].apply(\n controller,\n args\n );\n })\n )(socket);\n if (typeof args[args.length - 1] === 'function') {\n // ack\n args[args.length - 1](result);\n } else {\n // emit\n await this.bindSocketResponse(\n result,\n socket,\n wsEventInfo.propertyName,\n methodMap\n );\n }\n } catch (error) {\n this.logger.error(error);\n }\n });\n } else if (\n wsEventInfo.eventType === WSEventTypeEnum.ON_DISCONNECTION\n ) {\n // on socket disconnect\n socket.on('disconnect', async (reason: string) => {\n try {\n const result = await controller[wsEventInfo.propertyName].apply(\n controller,\n [reason]\n );\n await this.bindSocketResponse(\n result,\n socket,\n wsEventInfo.propertyName,\n methodMap\n );\n } catch (err) {\n this.logger.error(err);\n }\n });\n } else {\n // 存储每个方法对应的后置响应处理,供后续快速匹配\n methodMap[wsEventInfo.propertyName].responseEvents.push(\n wsEventInfo\n );\n }\n }\n }\n });\n\n if (nsp.adapter) {\n nsp.adapter.on('error', err => {\n this.logger.error(err);\n });\n }\n }\n\n private async bindSocketResponse(\n result: any,\n socket: IMidwaySocketIOContext,\n propertyName: string,\n methodMap: {\n responseEvents?: WSEventInfo[];\n }\n ) {\n if (result && methodMap[propertyName]) {\n for (const wsEventInfo of methodMap[propertyName].responseEvents) {\n if (wsEventInfo.eventType === WSEventTypeEnum.EMIT) {\n if (wsEventInfo.roomName.length) {\n socket = wsEventInfo.roomName.reduce((socket, name) => {\n return socket.to(name);\n }, socket);\n }\n // eslint-disable-next-line prefer-spread\n socket.emit.apply(\n socket,\n [wsEventInfo.messageEventName].concat(result)\n );\n } else if (wsEventInfo.eventType === WSEventTypeEnum.BROADCAST) {\n // eslint-disable-next-line prefer-spread\n socket.nsp.emit.apply(socket.nsp, [].concat(result));\n }\n }\n }\n }\n\n public getFrameworkName() {\n return 'midway:socketIO';\n }\n\n public getDefaultContextLoggerClass(): any {\n return MidwaySocketIOContextLogger;\n }\n}\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,yCAAmE;AAA1D,sGAAA,uBAAuB,OAAa;AAC7C,+BAA4C;AAAnC,0GAAA,kBAAkB,OAAA;AAC3B,8CAA4B;AAC5B,iDAAyE;AAAhE,8GAAA,qBAAqB,OAAiB","sourcesContent":["export { MidwaySocketIOFramework as Framework } from './framework';\nexport { createRedisAdapter } from './util';\nexport * from './interface';\nexport { SocketIOConfiguration as Configuration } from './configuration';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"","sourcesContent":["import * as SocketIO from 'socket.io';\nimport {\n IConfigurationOptions,\n IMidwayApplication,\n IMidwayContext,\n NextFunction as BaseNextFunction\n} from '@midwayjs/core';\n\nexport type IMidwaySocketIOApplication = IMidwayApplication<IMidwaySocketIOContext, {\n use(fn: (socket: IMidwaySocketIOContext, fn: (err?: any) => void) => void): SocketIO.Namespace;\n} & SocketIO.Server>;\n\nexport type IMidwaySocketIOConfigurationOptions = {\n port?: number;\n pubClient?: any;\n subClient?: any;\n} & Partial<SocketIO.ServerOptions> & IConfigurationOptions;\n\nexport type IMidwaySocketIOContext = IMidwayContext<SocketIO.Socket & {\n app: IMidwaySocketIOApplication\n}>;\n\nexport type Application = IMidwaySocketIOApplication;\n\nexport interface Context extends IMidwaySocketIOContext {}\nexport type NextFunction = BaseNextFunction;\n\ndeclare module '@midwayjs/core/dist/interface' {\n interface MidwayConfig {\n socketIO?: IMidwaySocketIOConfigurationOptions;\n }\n}\n"]}
package/dist/logger.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { MidwayContextLogger } from '@midwayjs/logger';
2
- import { IMidwaySocketIOContext } from './interface';
3
- export declare class MidwaySocketIOContextLogger extends MidwayContextLogger<IMidwaySocketIOContext> {
4
- formatContextLabel(): string;
5
- }
6
- //# sourceMappingURL=logger.d.ts.map
package/dist/logger.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwaySocketIOContextLogger = void 0;
4
- const logger_1 = require("@midwayjs/logger");
5
- class MidwaySocketIOContextLogger extends logger_1.MidwayContextLogger {
6
- formatContextLabel() {
7
- // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
8
- // const userId = req?.['session']?.['userId'] || '-';
9
- // const traceId = '-';
10
- // const use = Date.now() - this.ctx.startTime;
11
- // return (
12
- // userId +
13
- // '/' +
14
- // req.ip +
15
- // '/' +
16
- // traceId +
17
- // '/' +
18
- // use +
19
- // 'ms ' +
20
- // req.method +
21
- // ' ' +
22
- // req.url
23
- return '';
24
- }
25
- }
26
- exports.MidwaySocketIOContextLogger = MidwaySocketIOContextLogger;
27
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,6CAAuD;AAGvD,MAAa,2BAA4B,SAAQ,4BAA2C;IAC1F,kBAAkB;QAChB,wDAAwD;QACxD,sDAAsD;QACtD,uBAAuB;QACvB,+CAA+C;QAC/C,WAAW;QACX,aAAa;QACb,UAAU;QACV,aAAa;QACb,UAAU;QACV,cAAc;QACd,UAAU;QACV,UAAU;QACV,YAAY;QACZ,iBAAiB;QACjB,UAAU;QACV,YAAY;QACZ,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AApBD,kEAoBC","sourcesContent":["import { MidwayContextLogger } from '@midwayjs/logger';\nimport { IMidwaySocketIOContext } from './interface';\n\nexport class MidwaySocketIOContextLogger extends MidwayContextLogger<IMidwaySocketIOContext> {\n formatContextLabel() {\n // format: '[$userId/$ip/$traceId/$use_ms $method $url]'\n // const userId = req?.['session']?.['userId'] || '-';\n // const traceId = '-';\n // const use = Date.now() - this.ctx.startTime;\n // return (\n // userId +\n // '/' +\n // req.ip +\n // '/' +\n // traceId +\n // '/' +\n // use +\n // 'ms ' +\n // req.method +\n // ' ' +\n // req.url\n return '';\n }\n}\n"]}
package/dist/util.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA,qDAAqE;AAMrE,SAAgB,kBAAkB,CAAC,OAAY;IAC7C,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE;QAChC,OAAO,IAAA,+BAAa,EAClB,UAAU,GAAG,OAAO,CAAC,IAAI,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,EAC9C,OAAO,CACR,CAAC;KACH;IACD,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE;QAC1C,OAAO,IAAA,+BAAa,EAAC,OAAO,CAAC,CAAC;KAC/B;IACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;AAClD,CAAC;AAXD,gDAWC","sourcesContent":["import { createAdapter, RedisAdapterOptions } from 'socket.io-redis';\n\nexport function createRedisAdapter(\n options: { host: string; port: number } & Partial<RedisAdapterOptions>\n);\nexport function createRedisAdapter(options: Partial<RedisAdapterOptions>);\nexport function createRedisAdapter(options: any) {\n if (options.host && options.port) {\n return createAdapter(\n 'redis://' + options.host + ':' + options.port,\n options\n );\n }\n if (options.pubClient && options.subClient) {\n return createAdapter(options);\n }\n throw new Error('error socket adapter options');\n}\n"]}