@midwayjs/socketio 3.0.0-alpha.6 → 3.0.0-beta.11

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,109 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
7
+
8
+ **Note:** Version bump only for package @midwayjs/socketio
9
+
10
+
11
+
12
+
13
+
14
+ # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
15
+
16
+
17
+ ### Features
18
+
19
+ * implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
20
+
21
+
22
+
23
+
24
+
25
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
26
+
27
+ **Note:** Version bump only for package @midwayjs/socketio
28
+
29
+
30
+
31
+
32
+
33
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
39
+
40
+
41
+
42
+
43
+
44
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
45
+
46
+
47
+ ### Bug Fixes
48
+
49
+ * middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
50
+
51
+
52
+
53
+
54
+
55
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
56
+
57
+ **Note:** Version bump only for package @midwayjs/socketio
58
+
59
+
60
+
61
+
62
+
63
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
64
+
65
+ **Note:** Version bump only for package @midwayjs/socketio
66
+
67
+
68
+
69
+
70
+
71
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
72
+
73
+
74
+ ### Features
75
+
76
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
77
+
78
+
79
+
80
+
81
+
82
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
83
+
84
+
85
+ ### Features
86
+
87
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
88
+
89
+
90
+
91
+
92
+
93
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
94
+
95
+ **Note:** Version bump only for package @midwayjs/socketio
96
+
97
+
98
+
99
+
100
+
101
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
102
+
103
+ **Note:** Version bump only for package @midwayjs/socketio
104
+
105
+
106
+
107
+
108
+
6
109
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
110
 
8
111
  **Note:** Version bump only for package @midwayjs/socketio
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  this is a sub package for midway.
7
7
 
8
- Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
@@ -0,0 +1,3 @@
1
+ export declare class SocketIOConfiguration {
2
+ }
3
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SocketIOConfiguration = void 0;
10
+ const decorator_1 = require("@midwayjs/decorator");
11
+ let SocketIOConfiguration = class SocketIOConfiguration {
12
+ };
13
+ SocketIOConfiguration = __decorate([
14
+ (0, decorator_1.Configuration)({
15
+ namespace: 'socketIO',
16
+ })
17
+ ], SocketIOConfiguration);
18
+ exports.SocketIOConfiguration = SocketIOConfiguration;
19
+ //# sourceMappingURL=configuration.js.map
@@ -2,6 +2,7 @@ import { BaseFramework, IMidwayBootstrapOptions, MidwayFrameworkType } from '@mi
2
2
  import { IMidwaySocketIOApplication, IMidwaySocketIOConfigurationOptions, IMidwaySocketIOContext } from './interface';
3
3
  export declare class MidwaySocketIOFramework extends BaseFramework<IMidwaySocketIOApplication, IMidwaySocketIOContext, IMidwaySocketIOConfigurationOptions> {
4
4
  private namespaceList;
5
+ configure(): IMidwaySocketIOConfigurationOptions;
5
6
  applicationInitialize(options: IMidwayBootstrapOptions): void;
6
7
  app: IMidwaySocketIOApplication;
7
8
  protected afterContainerReady(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
package/dist/framework.js CHANGED
@@ -1,17 +1,26 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.MidwaySocketIOFramework = void 0;
4
10
  const core_1 = require("@midwayjs/core");
5
11
  const util_1 = require("util");
6
- const debug = util_1.debuglog('midway:socket.io');
12
+ const debug = (0, util_1.debuglog)('midway:socket.io');
7
13
  const socket_io_1 = require("socket.io");
8
14
  const decorator_1 = require("@midwayjs/decorator");
9
15
  const logger_1 = require("./logger");
10
- class MidwaySocketIOFramework extends core_1.BaseFramework {
16
+ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseFramework {
11
17
  constructor() {
12
18
  super(...arguments);
13
19
  this.namespaceList = [];
14
20
  }
21
+ configure() {
22
+ return this.configService.getConfiguration('socketIO');
23
+ }
15
24
  applicationInitialize(options) {
16
25
  this.app = new socket_io_1.Server(this.configurationOptions);
17
26
  }
@@ -28,7 +37,7 @@ class MidwaySocketIOFramework extends core_1.BaseFramework {
28
37
  this.app.listen(this.configurationOptions.port, this.configurationOptions);
29
38
  this.logger.info(`Socket.io server port = ${this.configurationOptions.port} start success`);
30
39
  }
31
- else if (this.applicationContext.registry.hasObject(core_1.HTTP_SERVER_KEY)) {
40
+ else if (this.applicationContext.hasObject(core_1.HTTP_SERVER_KEY)) {
32
41
  this.app.attach(this.applicationContext.get(core_1.HTTP_SERVER_KEY), this.configurationOptions);
33
42
  this.logger.info('Socket.io server start success and attach to web server');
34
43
  }
@@ -47,16 +56,13 @@ class MidwaySocketIOFramework extends core_1.BaseFramework {
47
56
  }
48
57
  async loadMidwayController() {
49
58
  // create room
50
- const controllerModules = core_1.listModule(decorator_1.WS_CONTROLLER_KEY);
59
+ const controllerModules = (0, decorator_1.listModule)(decorator_1.WS_CONTROLLER_KEY);
51
60
  for (const module of controllerModules) {
52
- const providerId = core_1.getProviderId(module);
53
- if (providerId) {
54
- await this.addNamespace(module, providerId);
55
- }
61
+ await this.addNamespace(module);
56
62
  }
57
63
  }
58
- async addNamespace(target, controllerId) {
59
- const controllerOption = core_1.getClassMetadata(decorator_1.WS_CONTROLLER_KEY, target);
64
+ async addNamespace(target) {
65
+ const controllerOption = (0, decorator_1.getClassMetadata)(decorator_1.WS_CONTROLLER_KEY, target);
60
66
  const nsp = this.app.of(controllerOption.namespace);
61
67
  this.namespaceList.push(controllerOption.namespace);
62
68
  nsp.use((socket, next) => {
@@ -66,13 +72,13 @@ class MidwaySocketIOFramework extends core_1.BaseFramework {
66
72
  next();
67
73
  });
68
74
  nsp.on('connect', async (socket) => {
69
- const wsEventInfos = core_1.getClassMetadata(decorator_1.WS_EVENT_KEY, target);
75
+ const wsEventInfos = (0, decorator_1.getClassMetadata)(decorator_1.WS_EVENT_KEY, target);
70
76
  // 存储方法对应的响应处理
71
77
  const methodMap = {};
72
78
  if (wsEventInfos.length) {
73
79
  for (const wsEventInfo of wsEventInfos) {
74
80
  methodMap[wsEventInfo.propertyName] = methodMap[wsEventInfo.propertyName] || { responseEvents: [] };
75
- const controller = await socket.requestContext.getAsync(controllerId);
81
+ const controller = await socket.requestContext.getAsync(target);
76
82
  // on connection
77
83
  if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.ON_CONNECTION) {
78
84
  try {
@@ -88,8 +94,10 @@ class MidwaySocketIOFramework extends core_1.BaseFramework {
88
94
  socket.on(wsEventInfo.messageEventName, async (...args) => {
89
95
  debug('got message', wsEventInfo.messageEventName, args);
90
96
  try {
91
- // eslint-disable-next-line prefer-spread
92
- const result = await controller[wsEventInfo.propertyName].apply(controller, args);
97
+ const result = await (await this.applyMiddleware(async (ctx, next) => {
98
+ // eslint-disable-next-line prefer-spread
99
+ return controller[wsEventInfo.propertyName].apply(controller, args);
100
+ }))(socket);
93
101
  if (typeof args[args.length - 1] === 'function') {
94
102
  // ack
95
103
  args[args.length - 1](result);
@@ -99,8 +107,8 @@ class MidwaySocketIOFramework extends core_1.BaseFramework {
99
107
  await this.bindSocketResponse(result, socket, wsEventInfo.propertyName, methodMap);
100
108
  }
101
109
  }
102
- catch (err) {
103
- this.logger.error(err);
110
+ catch (error) {
111
+ this.logger.error(error);
104
112
  }
105
113
  });
106
114
  }
@@ -154,6 +162,9 @@ class MidwaySocketIOFramework extends core_1.BaseFramework {
154
162
  getDefaultContextLoggerClass() {
155
163
  return logger_1.MidwaySocketIOContextLogger;
156
164
  }
157
- }
165
+ };
166
+ MidwaySocketIOFramework = __decorate([
167
+ (0, decorator_1.Framework)()
168
+ ], MidwaySocketIOFramework);
158
169
  exports.MidwaySocketIOFramework = MidwaySocketIOFramework;
159
170
  //# sourceMappingURL=framework.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { MidwaySocketIOFramework as Framework } from './framework';
2
2
  export { createRedisAdapter } from './util';
3
3
  export * from './interface';
4
+ export { SocketIOConfiguration as Configuration } from './configuration';
4
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -10,10 +10,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.createRedisAdapter = exports.Framework = void 0;
13
+ exports.Configuration = exports.createRedisAdapter = exports.Framework = void 0;
14
14
  var framework_1 = require("./framework");
15
15
  Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwaySocketIOFramework; } });
16
16
  var util_1 = require("./util");
17
17
  Object.defineProperty(exports, "createRedisAdapter", { enumerable: true, get: function () { return util_1.createRedisAdapter; } });
18
18
  __exportStar(require("./interface"), exports);
19
+ var configuration_1 = require("./configuration");
20
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.SocketIOConfiguration; } });
19
21
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import * as SocketIO from 'socket.io';
2
- import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
2
+ import { IConfigurationOptions, IMidwayApplication, IMidwayContext, NextFunction as BaseNextFunction } from '@midwayjs/core';
3
3
  export declare type IMidwaySocketIOApplication = IMidwayApplication<IMidwaySocketIOContext, {
4
4
  use(fn: (socket: IMidwaySocketIOContext, fn: (err?: any) => void) => void): SocketIO.Namespace;
5
5
  } & SocketIO.Server>;
@@ -14,4 +14,10 @@ export declare type IMidwaySocketIOContext = IMidwayContext<SocketIO.Socket & {
14
14
  export declare type Application = IMidwaySocketIOApplication;
15
15
  export interface Context extends IMidwaySocketIOContext {
16
16
  }
17
+ export declare type NextFunction = BaseNextFunction;
18
+ declare module '@midwayjs/core/dist/interface' {
19
+ interface MidwayConfig {
20
+ socketIO?: IMidwaySocketIOConfigurationOptions;
21
+ }
22
+ }
17
23
  //# sourceMappingURL=interface.d.ts.map
package/dist/util.js CHANGED
@@ -4,10 +4,10 @@ exports.createRedisAdapter = void 0;
4
4
  const socket_io_redis_1 = require("socket.io-redis");
5
5
  function createRedisAdapter(options) {
6
6
  if (options.host && options.port) {
7
- return socket_io_redis_1.createAdapter('redis://' + options.host + ':' + options.port, options);
7
+ return (0, socket_io_redis_1.createAdapter)('redis://' + options.host + ':' + options.port, options);
8
8
  }
9
9
  if (options.pubClient && options.subClient) {
10
- return socket_io_redis_1.createAdapter(options);
10
+ return (0, socket_io_redis_1.createAdapter)(options);
11
11
  }
12
12
  throw new Error('error socket adapter options');
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/socketio",
3
- "version": "3.0.0-alpha.6+6c8b724b",
3
+ "version": "3.0.0-beta.11",
4
4
  "description": "Midway Web Framework for socket.io",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -23,15 +23,15 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@midwayjs/decorator": "^3.0.0-alpha.6+6c8b724b",
27
- "@midwayjs/mock": "^3.0.0-alpha.6+6c8b724b",
26
+ "@midwayjs/decorator": "^3.0.0-beta.11",
27
+ "@midwayjs/mock": "^3.0.0-beta.11",
28
28
  "@types/socket.io-client": "^1.4.36",
29
29
  "fs-extra": "^8.0.1",
30
30
  "socket.io-client": "^4.0.0"
31
31
  },
32
32
  "dependencies": {
33
- "@midwayjs/core": "^3.0.0-alpha.6+6c8b724b",
34
- "@midwayjs/logger": "^3.0.0-alpha.6+6c8b724b",
33
+ "@midwayjs/core": "^3.0.0-beta.11",
34
+ "@midwayjs/logger": "^3.0.0-beta.11",
35
35
  "socket.io": "^4.0.0",
36
36
  "socket.io-redis": "^6.1.0"
37
37
  },
@@ -40,5 +40,8 @@
40
40
  "type": "git",
41
41
  "url": "http://github.com/midwayjs/midway.git"
42
42
  },
43
- "gitHead": "6c8b724b08cf395287636b80387653f9540768e5"
43
+ "engines": {
44
+ "node": ">=12"
45
+ },
46
+ "gitHead": "a2b066fd500e815e799e7f421cd216f12e0e9f8e"
44
47
  }