@midwayjs/socketio 3.19.2 → 4.0.0-alpha.1
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/dist/configuration.js +2 -2
- package/dist/framework.d.ts +2 -3
- package/dist/framework.js +11 -17
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/interface.d.ts +0 -5
- package/package.json +6 -8
- package/dist/util.d.ts +0 -7
- package/dist/util.js +0 -15
package/dist/configuration.js
CHANGED
|
@@ -10,10 +10,10 @@ exports.SocketIOConfiguration = void 0;
|
|
|
10
10
|
const core_1 = require("@midwayjs/core");
|
|
11
11
|
let SocketIOConfiguration = class SocketIOConfiguration {
|
|
12
12
|
};
|
|
13
|
-
SocketIOConfiguration =
|
|
13
|
+
exports.SocketIOConfiguration = SocketIOConfiguration;
|
|
14
|
+
exports.SocketIOConfiguration = SocketIOConfiguration = __decorate([
|
|
14
15
|
(0, core_1.Configuration)({
|
|
15
16
|
namespace: 'socketIO',
|
|
16
17
|
})
|
|
17
18
|
], SocketIOConfiguration);
|
|
18
|
-
exports.SocketIOConfiguration = SocketIOConfiguration;
|
|
19
19
|
//# sourceMappingURL=configuration.js.map
|
package/dist/framework.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { BaseFramework, CommonMiddlewareUnion, ContextMiddlewareManager
|
|
1
|
+
import { BaseFramework, CommonMiddlewareUnion, ContextMiddlewareManager } from '@midwayjs/core';
|
|
2
2
|
import { Application, IMidwaySocketIOOptions, Context, NextFunction } from './interface';
|
|
3
3
|
export declare class MidwaySocketIOFramework extends BaseFramework<Application, Context, IMidwaySocketIOOptions> {
|
|
4
4
|
private namespaceList;
|
|
5
5
|
app: Application;
|
|
6
6
|
protected connectionMiddlewareManager: ContextMiddlewareManager<Context, unknown, unknown>;
|
|
7
7
|
configure(): IMidwaySocketIOOptions;
|
|
8
|
-
applicationInitialize(): void
|
|
8
|
+
applicationInitialize(): Promise<void>;
|
|
9
9
|
run(): Promise<void>;
|
|
10
10
|
protected beforeStop(): Promise<void>;
|
|
11
|
-
getFrameworkType(): MidwayFrameworkType;
|
|
12
11
|
private loadMidwayController;
|
|
13
12
|
private addNamespace;
|
|
14
13
|
private bindSocketResponse;
|
package/dist/framework.js
CHANGED
|
@@ -21,7 +21,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
|
|
|
21
21
|
configure() {
|
|
22
22
|
return this.configService.getConfiguration('socketIO');
|
|
23
23
|
}
|
|
24
|
-
applicationInitialize() {
|
|
24
|
+
async applicationInitialize() {
|
|
25
25
|
this.app = new socket_io_1.Server(this.configurationOptions);
|
|
26
26
|
this.defineApplicationProperties({
|
|
27
27
|
useConnectionMiddleware: (middleware) => {
|
|
@@ -57,23 +57,19 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
|
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
getFrameworkType() {
|
|
61
|
-
return core_1.MidwayFrameworkType.WS_IO;
|
|
62
|
-
}
|
|
63
60
|
async loadMidwayController() {
|
|
64
61
|
// create room
|
|
65
|
-
const controllerModules =
|
|
62
|
+
const controllerModules = core_1.DecoratorManager.listModule(core_2.WS_CONTROLLER_KEY);
|
|
66
63
|
for (const module of controllerModules) {
|
|
67
64
|
await this.addNamespace(module);
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
async addNamespace(target) {
|
|
71
|
-
|
|
72
|
-
const controllerOption = (0, core_2.getClassMetadata)(core_2.WS_CONTROLLER_KEY, target);
|
|
68
|
+
const controllerOption = core_1.MetadataManager.getOwnMetadata(core_2.WS_CONTROLLER_KEY, target);
|
|
73
69
|
const nsp = this.app.of(controllerOption.namespace);
|
|
74
70
|
this.namespaceList.push(controllerOption.namespace);
|
|
75
|
-
const controllerMiddleware =
|
|
76
|
-
const controllerConnectionMiddleware =
|
|
71
|
+
const controllerMiddleware = controllerOption.routerOptions.middleware ?? [];
|
|
72
|
+
const controllerConnectionMiddleware = controllerOption.routerOptions.connectionMiddleware ?? [];
|
|
77
73
|
nsp.use((socket, next) => {
|
|
78
74
|
this.app.createAnonymousContext(socket);
|
|
79
75
|
socket.requestContext.registerObject('socket', socket);
|
|
@@ -89,7 +85,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
|
|
|
89
85
|
...controllerConnectionMiddleware,
|
|
90
86
|
], this.app)
|
|
91
87
|
.then(connectFn => connectFn(socket));
|
|
92
|
-
const wsEventInfos =
|
|
88
|
+
const wsEventInfos = core_1.MetadataManager.getMetadata(core_2.WS_EVENT_KEY, target);
|
|
93
89
|
// 存储方法对应的响应处理
|
|
94
90
|
const methodMap = {};
|
|
95
91
|
// 优先处理`@OnWSConnection`
|
|
@@ -99,12 +95,11 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
|
|
|
99
95
|
connMiddlewarePromise = connMiddlewarePromise.then(() =>
|
|
100
96
|
// 可能存在多个`@OnWSConnection`,这时不保障它们的执行顺序
|
|
101
97
|
Promise.all(wsOnConnectionEventInfos.map(async (wsEventInfo) => {
|
|
102
|
-
var _a;
|
|
103
98
|
methodMap[wsEventInfo.propertyName] = methodMap[wsEventInfo.propertyName] || { responseEvents: [] };
|
|
104
99
|
const controller = await socket.requestContext.getAsync(target);
|
|
105
100
|
try {
|
|
106
101
|
const fn = await this.middlewareService.compose([
|
|
107
|
-
...(
|
|
102
|
+
...(wsEventInfo?.eventOptions?.middleware || []),
|
|
108
103
|
async (ctx, next) => {
|
|
109
104
|
// eslint-disable-next-line prefer-spread
|
|
110
105
|
return controller[wsEventInfo.propertyName].apply(controller, [socket]);
|
|
@@ -132,11 +127,10 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
|
|
|
132
127
|
debug('got message', wsEventInfo.messageEventName, args);
|
|
133
128
|
try {
|
|
134
129
|
const result = await (await this.applyMiddleware(async (ctx, next) => {
|
|
135
|
-
var _a;
|
|
136
130
|
// add controller middleware
|
|
137
131
|
const fn = await this.middlewareService.compose([
|
|
138
132
|
...controllerMiddleware,
|
|
139
|
-
...(
|
|
133
|
+
...(wsEventInfo?.eventOptions?.middleware || []),
|
|
140
134
|
async (ctx, next) => {
|
|
141
135
|
const isPassed = await this.app
|
|
142
136
|
.getFramework()
|
|
@@ -213,7 +207,7 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
|
|
|
213
207
|
}
|
|
214
208
|
}
|
|
215
209
|
getFrameworkName() {
|
|
216
|
-
return '
|
|
210
|
+
return 'socketIO';
|
|
217
211
|
}
|
|
218
212
|
useConnectionMiddleware(middleware) {
|
|
219
213
|
this.connectionMiddlewareManager.insertLast(middleware);
|
|
@@ -222,8 +216,8 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
|
|
|
222
216
|
return this.connectionMiddlewareManager;
|
|
223
217
|
}
|
|
224
218
|
};
|
|
225
|
-
MidwaySocketIOFramework =
|
|
219
|
+
exports.MidwaySocketIOFramework = MidwaySocketIOFramework;
|
|
220
|
+
exports.MidwaySocketIOFramework = MidwaySocketIOFramework = __decorate([
|
|
226
221
|
(0, core_2.Framework)()
|
|
227
222
|
], MidwaySocketIOFramework);
|
|
228
|
-
exports.MidwaySocketIOFramework = MidwaySocketIOFramework;
|
|
229
223
|
//# sourceMappingURL=framework.js.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,11 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Configuration = exports.
|
|
17
|
+
exports.Configuration = exports.Framework = void 0;
|
|
18
18
|
var framework_1 = require("./framework");
|
|
19
19
|
Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwaySocketIOFramework; } });
|
|
20
|
-
var util_1 = require("./util");
|
|
21
|
-
Object.defineProperty(exports, "createRedisAdapter", { enumerable: true, get: function () { return util_1.createRedisAdapter; } });
|
|
22
20
|
__exportStar(require("./interface"), exports);
|
|
23
21
|
var configuration_1 = require("./configuration");
|
|
24
22
|
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.SocketIOConfiguration; } });
|
package/dist/interface.d.ts
CHANGED
|
@@ -14,9 +14,4 @@ export type Context = IMidwayContext<SocketIO.Socket & {
|
|
|
14
14
|
app: Application;
|
|
15
15
|
}>;
|
|
16
16
|
export type NextFunction = BaseNextFunction;
|
|
17
|
-
declare module '@midwayjs/core/dist/interface' {
|
|
18
|
-
interface MidwayConfig {
|
|
19
|
-
socketIO?: IMidwaySocketIOOptions;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
17
|
//# sourceMappingURL=interface.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/socketio",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Midway Web Framework for socket.io",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node
|
|
10
|
-
"cov": "node
|
|
9
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
10
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
11
11
|
"ci": "npm run test"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -24,14 +24,12 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/
|
|
27
|
+
"@midwayjs/core": "^4.0.0-alpha.1",
|
|
28
28
|
"fs-extra": "11.2.0",
|
|
29
29
|
"socket.io-client": "4.8.1"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"socket.io": "4.8.1",
|
|
34
|
-
"socket.io-redis": "^6.1.0"
|
|
32
|
+
"socket.io": "4.8.1"
|
|
35
33
|
},
|
|
36
34
|
"author": "Harry Chen <czy88840616@gmail.com>",
|
|
37
35
|
"repository": {
|
|
@@ -41,5 +39,5 @@
|
|
|
41
39
|
"engines": {
|
|
42
40
|
"node": ">=12"
|
|
43
41
|
},
|
|
44
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
|
|
45
43
|
}
|
package/dist/util.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { RedisAdapterOptions } from 'socket.io-redis';
|
|
2
|
-
export declare function createRedisAdapter(options: {
|
|
3
|
-
host: string;
|
|
4
|
-
port: number;
|
|
5
|
-
} & Partial<RedisAdapterOptions>): any;
|
|
6
|
-
export declare function createRedisAdapter(options: Partial<RedisAdapterOptions>): any;
|
|
7
|
-
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRedisAdapter = void 0;
|
|
4
|
-
const socket_io_redis_1 = require("socket.io-redis");
|
|
5
|
-
function createRedisAdapter(options) {
|
|
6
|
-
if (options.host && options.port) {
|
|
7
|
-
return (0, socket_io_redis_1.createAdapter)('redis://' + options.host + ':' + options.port, options);
|
|
8
|
-
}
|
|
9
|
-
if (options.pubClient && options.subClient) {
|
|
10
|
-
return (0, socket_io_redis_1.createAdapter)(options);
|
|
11
|
-
}
|
|
12
|
-
throw new Error('error socket adapter options');
|
|
13
|
-
}
|
|
14
|
-
exports.createRedisAdapter = createRedisAdapter;
|
|
15
|
-
//# sourceMappingURL=util.js.map
|