@midwayjs/socketio 3.5.3 → 3.6.0

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.
@@ -7,11 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SocketIOConfiguration = void 0;
10
- const decorator_1 = require("@midwayjs/decorator");
10
+ const core_1 = require("@midwayjs/core");
11
11
  let SocketIOConfiguration = class SocketIOConfiguration {
12
12
  };
13
13
  SocketIOConfiguration = __decorate([
14
- (0, decorator_1.Configuration)({
14
+ (0, core_1.Configuration)({
15
15
  namespace: 'socketIO',
16
16
  })
17
17
  ], SocketIOConfiguration);
package/dist/framework.js CHANGED
@@ -11,7 +11,7 @@ const core_1 = require("@midwayjs/core");
11
11
  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
- const decorator_1 = require("@midwayjs/decorator");
14
+ const core_2 = require("@midwayjs/core");
15
15
  let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseFramework {
16
16
  constructor() {
17
17
  super(...arguments);
@@ -62,14 +62,14 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
62
62
  }
63
63
  async loadMidwayController() {
64
64
  // create room
65
- const controllerModules = (0, decorator_1.listModule)(decorator_1.WS_CONTROLLER_KEY);
65
+ const controllerModules = (0, core_2.listModule)(core_2.WS_CONTROLLER_KEY);
66
66
  for (const module of controllerModules) {
67
67
  await this.addNamespace(module);
68
68
  }
69
69
  }
70
70
  async addNamespace(target) {
71
71
  var _a, _b;
72
- const controllerOption = (0, decorator_1.getClassMetadata)(decorator_1.WS_CONTROLLER_KEY, target);
72
+ const controllerOption = (0, core_2.getClassMetadata)(core_2.WS_CONTROLLER_KEY, target);
73
73
  const nsp = this.app.of(controllerOption.namespace);
74
74
  this.namespaceList.push(controllerOption.namespace);
75
75
  const controllerMiddleware = (_a = controllerOption.routerOptions.middleware) !== null && _a !== void 0 ? _a : [];
@@ -88,7 +88,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
88
88
  ...controllerConnectionMiddleware,
89
89
  ], this.app);
90
90
  await connectFn(socket);
91
- const wsEventInfos = (0, decorator_1.getClassMetadata)(decorator_1.WS_EVENT_KEY, target);
91
+ const wsEventInfos = (0, core_2.getClassMetadata)(core_2.WS_EVENT_KEY, target);
92
92
  // 存储方法对应的响应处理
93
93
  const methodMap = {};
94
94
  if (wsEventInfos.length) {
@@ -96,7 +96,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
96
96
  methodMap[wsEventInfo.propertyName] = methodMap[wsEventInfo.propertyName] || { responseEvents: [] };
97
97
  const controller = await socket.requestContext.getAsync(target);
98
98
  // on connection
99
- if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.ON_CONNECTION) {
99
+ if (wsEventInfo.eventType === core_2.WSEventTypeEnum.ON_CONNECTION) {
100
100
  try {
101
101
  const fn = await this.middlewareService.compose([
102
102
  ...(((_a = wsEventInfo === null || wsEventInfo === void 0 ? void 0 : wsEventInfo.eventOptions) === null || _a === void 0 ? void 0 : _a.middleware) || []),
@@ -112,7 +112,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
112
112
  this.logger.error(err);
113
113
  }
114
114
  }
115
- else if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.ON_MESSAGE) {
115
+ else if (wsEventInfo.eventType === core_2.WSEventTypeEnum.ON_MESSAGE) {
116
116
  // on user custom event
117
117
  socket.on(wsEventInfo.messageEventName, async (...args) => {
118
118
  debug('got message', wsEventInfo.messageEventName, args);
@@ -124,6 +124,12 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
124
124
  ...controllerMiddleware,
125
125
  ...(((_a = wsEventInfo === null || wsEventInfo === void 0 ? void 0 : wsEventInfo.eventOptions) === null || _a === void 0 ? void 0 : _a.middleware) || []),
126
126
  async (ctx, next) => {
127
+ const isPassed = await this.app
128
+ .getFramework()
129
+ .runGuard(ctx, target, wsEventInfo.propertyName);
130
+ if (!isPassed) {
131
+ throw new core_1.MidwayInvokeForbiddenError(wsEventInfo.propertyName, target);
132
+ }
127
133
  // eslint-disable-next-line prefer-spread
128
134
  return controller[wsEventInfo.propertyName].apply(controller, args);
129
135
  },
@@ -144,7 +150,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
144
150
  }
145
151
  });
146
152
  }
147
- else if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.ON_DISCONNECTION) {
153
+ else if (wsEventInfo.eventType === core_2.WSEventTypeEnum.ON_DISCONNECTION) {
148
154
  // on socket disconnect
149
155
  socket.on('disconnect', async (reason) => {
150
156
  try {
@@ -172,7 +178,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
172
178
  async bindSocketResponse(result, socket, propertyName, methodMap) {
173
179
  if (result && methodMap[propertyName]) {
174
180
  for (const wsEventInfo of methodMap[propertyName].responseEvents) {
175
- if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.EMIT) {
181
+ if (wsEventInfo.eventType === core_2.WSEventTypeEnum.EMIT) {
176
182
  if (wsEventInfo.roomName.length) {
177
183
  socket = wsEventInfo.roomName.reduce((socket, name) => {
178
184
  return socket.to(name);
@@ -181,7 +187,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
181
187
  // eslint-disable-next-line prefer-spread
182
188
  socket.emit.apply(socket, [wsEventInfo.messageEventName].concat(result));
183
189
  }
184
- else if (wsEventInfo.eventType === decorator_1.WSEventTypeEnum.BROADCAST) {
190
+ else if (wsEventInfo.eventType === core_2.WSEventTypeEnum.BROADCAST) {
185
191
  // eslint-disable-next-line prefer-spread
186
192
  socket.nsp.emit.apply(socket.nsp, [].concat(result));
187
193
  }
@@ -199,7 +205,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
199
205
  }
200
206
  };
201
207
  MidwaySocketIOFramework = __decorate([
202
- (0, decorator_1.Framework)()
208
+ (0, core_2.Framework)()
203
209
  ], MidwaySocketIOFramework);
204
210
  exports.MidwaySocketIOFramework = MidwaySocketIOFramework;
205
211
  //# sourceMappingURL=framework.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/socketio",
3
- "version": "3.5.3",
3
+ "version": "3.6.0",
4
4
  "description": "Midway Web Framework for socket.io",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
@@ -24,13 +24,12 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@midwayjs/decorator": "^3.4.11",
28
- "@midwayjs/mock": "^3.5.3",
27
+ "@midwayjs/mock": "^3.6.0",
29
28
  "fs-extra": "10.0.1",
30
29
  "socket.io-client": "4.5.2"
31
30
  },
32
31
  "dependencies": {
33
- "@midwayjs/core": "^3.5.3",
32
+ "@midwayjs/core": "^3.6.0",
34
33
  "@midwayjs/logger": "^2.15.0",
35
34
  "socket.io": "4.5.2",
36
35
  "socket.io-redis": "^6.1.0"
@@ -43,5 +42,5 @@
43
42
  "engines": {
44
43
  "node": ">=12"
45
44
  },
46
- "gitHead": "32356484664846984f6d3d65a3a75dea015e8dcc"
45
+ "gitHead": "22643b0e8519766bb7c68b975930199fc136336e"
47
46
  }