quantum-flow 1.7.0 → 1.8.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.
- package/dist/app/http/Application.d.ts +1 -0
- package/dist/app/http/Application.js +12 -3
- package/dist/app/http/decorators.js +0 -3
- package/dist/app/http/websocket/WebsocketServer.d.ts +3 -2
- package/dist/app/http/websocket/WebsocketServer.js +39 -27
- package/dist/constants.d.ts +1 -2
- package/dist/constants.js +2 -3
- package/dist/core/Controller.d.ts +12 -0
- package/dist/core/Controller.js +28 -0
- package/dist/core/utils/websocket.js +2 -2
- package/dist/examples/app.js +4 -55
- package/dist/examples/controllers/socket.d.ts +3 -4
- package/dist/examples/controllers/socket.js +14 -18
- package/dist/examples/controllers/userMetadata.d.ts +2 -1
- package/dist/examples/controllers/userMetadata.js +6 -5
- package/dist/utils/server.js +1 -2
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ export declare class HttpServer extends Socket {
|
|
|
8
8
|
constructor(configOrClass: new (...args: any[]) => any);
|
|
9
9
|
private logConfig;
|
|
10
10
|
listen(port?: number, host?: string): Promise<http.Server>;
|
|
11
|
+
private getAllControllers;
|
|
11
12
|
close(): Promise<void>;
|
|
12
13
|
status(): {
|
|
13
14
|
running: boolean;
|
|
@@ -19,9 +19,8 @@ class HttpServer extends Socket_1.Socket {
|
|
|
19
19
|
this.config = (0, _utils_1.resolveConfig)(configOrClass);
|
|
20
20
|
const app = http_1.default.createServer(this.requestHandler.bind(this));
|
|
21
21
|
if (this.config.websocket?.enabled) {
|
|
22
|
-
this.wss = new WebsocketServer_1.WebSocketServer(app, {
|
|
23
|
-
|
|
24
|
-
});
|
|
22
|
+
this.wss = new WebsocketServer_1.WebSocketServer(app, { path: this.config.websocket.path });
|
|
23
|
+
this.wss.registerControllers(this.getAllControllers(this.config.controllers));
|
|
25
24
|
WebsocketService_1.WebSocketService.getInstance().initialize(this.wss);
|
|
26
25
|
}
|
|
27
26
|
this.app = app;
|
|
@@ -73,6 +72,16 @@ class HttpServer extends Socket_1.Socket {
|
|
|
73
72
|
}
|
|
74
73
|
});
|
|
75
74
|
}
|
|
75
|
+
getAllControllers(controllers = []) {
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const ControllerClass of controllers || []) {
|
|
78
|
+
const instance = new ControllerClass();
|
|
79
|
+
result.push(instance);
|
|
80
|
+
const subControllers = Reflect.getMetadata(_constants_1.CONTROLLERS, ControllerClass.prototype) || [];
|
|
81
|
+
result.push(...this.getAllControllers(subControllers));
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
76
85
|
async close() {
|
|
77
86
|
return new Promise((resolve, reject) => {
|
|
78
87
|
if (!this.isRunning) {
|
|
@@ -16,9 +16,6 @@ function Server(config = {}) {
|
|
|
16
16
|
interceptors: existingConfig.interceptor ?? config.interceptor,
|
|
17
17
|
};
|
|
18
18
|
Reflect.defineMetadata(_constants_1.SERVER_CONFIG_KEY, mergedConfig, target);
|
|
19
|
-
if (config.controllers) {
|
|
20
|
-
Reflect.defineMetadata(_constants_1.SERVER_MODULES_KEY, config.controllers, target);
|
|
21
|
-
}
|
|
22
19
|
return target;
|
|
23
20
|
};
|
|
24
21
|
}
|
|
@@ -6,9 +6,10 @@ export declare class WebSocketServer {
|
|
|
6
6
|
private topics;
|
|
7
7
|
private controllers;
|
|
8
8
|
private options;
|
|
9
|
-
constructor(server: http.Server, options?:
|
|
9
|
+
constructor(server: http.Server, options?: {
|
|
10
|
+
path?: string;
|
|
11
|
+
});
|
|
10
12
|
private shouldHandleWebSocket;
|
|
11
|
-
private ensureServer;
|
|
12
13
|
private handleConnection;
|
|
13
14
|
private handleMessage;
|
|
14
15
|
private handleClose;
|
|
@@ -7,18 +7,28 @@ exports.WebSocketServer = void 0;
|
|
|
7
7
|
const uuid_1 = require("uuid");
|
|
8
8
|
const ws_1 = __importDefault(require("ws"));
|
|
9
9
|
class WebSocketServer {
|
|
10
|
-
wss
|
|
10
|
+
wss;
|
|
11
11
|
clients = new Map();
|
|
12
12
|
topics = new Map();
|
|
13
13
|
controllers = [];
|
|
14
14
|
options;
|
|
15
15
|
constructor(server, options) {
|
|
16
16
|
this.options = options;
|
|
17
|
+
this.wss = new ws_1.default.Server({
|
|
18
|
+
noServer: true,
|
|
19
|
+
path: this.options?.path || '/',
|
|
20
|
+
});
|
|
21
|
+
this.wss.on('connection', (socket, request) => {
|
|
22
|
+
this.handleConnection(socket);
|
|
23
|
+
});
|
|
17
24
|
server.on('upgrade', (request, socket, head) => {
|
|
25
|
+
if (socket.__wsHandled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
socket.__wsHandled = true;
|
|
18
29
|
if (this.shouldHandleWebSocket(request.url)) {
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
this.wss?.emit('connection', ws, request);
|
|
30
|
+
this.wss.handleUpgrade(request, socket, head, (ws) => {
|
|
31
|
+
this.wss.emit('connection', ws, request);
|
|
22
32
|
});
|
|
23
33
|
}
|
|
24
34
|
else {
|
|
@@ -30,19 +40,7 @@ class WebSocketServer {
|
|
|
30
40
|
const path = this.options?.path || '/ws';
|
|
31
41
|
return url.startsWith(path);
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
if (!this.wss) {
|
|
35
|
-
this.wss = new ws_1.default.Server({
|
|
36
|
-
server,
|
|
37
|
-
path: this.options?.path || '/ws',
|
|
38
|
-
noServer: true,
|
|
39
|
-
});
|
|
40
|
-
this.wss.on('connection', (socket, request) => {
|
|
41
|
-
this.handleConnection(socket, request);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async handleConnection(socket, request) {
|
|
43
|
+
async handleConnection(socket) {
|
|
46
44
|
const clientId = (0, uuid_1.v4)();
|
|
47
45
|
const client = {
|
|
48
46
|
id: clientId,
|
|
@@ -66,8 +64,9 @@ class WebSocketServer {
|
|
|
66
64
|
async handleMessage(client, data) {
|
|
67
65
|
try {
|
|
68
66
|
const message = JSON.parse(data.toString());
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const topic = message.topic ?? message.data?.topic;
|
|
68
|
+
if (message.type === 'subscribe' && topic) {
|
|
69
|
+
this.subscribeToTopic(client, topic);
|
|
71
70
|
return;
|
|
72
71
|
}
|
|
73
72
|
if (message.type === 'unsubscribe' && message.topic) {
|
|
@@ -121,22 +120,27 @@ class WebSocketServer {
|
|
|
121
120
|
}
|
|
122
121
|
async triggerHandlers(eventType, event, topic) {
|
|
123
122
|
for (const controller of this.controllers) {
|
|
124
|
-
const
|
|
125
|
-
const matchingHandlers =
|
|
123
|
+
const controllerHandlers = controller.handlers?.[eventType] ?? [];
|
|
124
|
+
const matchingHandlers = controllerHandlers.filter((h) => {
|
|
125
|
+
if (h.type !== eventType)
|
|
126
|
+
return false;
|
|
127
|
+
if (!topic)
|
|
128
|
+
return !h.topic;
|
|
129
|
+
return !h.topic || h.topic === topic;
|
|
130
|
+
});
|
|
126
131
|
for (const handler of matchingHandlers) {
|
|
127
132
|
try {
|
|
128
|
-
await
|
|
133
|
+
await handler.fn(event);
|
|
129
134
|
}
|
|
130
135
|
catch (error) {
|
|
131
136
|
console.error(`Error in WebSocket handler ${handler.method}:`, error);
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
|
-
const subscriptions = Reflect.getMetadata('websocket:topic', controller.constructor) || [];
|
|
135
139
|
if (eventType === 'message' && topic) {
|
|
136
|
-
const matchingSubs =
|
|
140
|
+
const matchingSubs = controller.topics.filter((s) => s.topic === topic);
|
|
137
141
|
for (const sub of matchingSubs) {
|
|
138
142
|
try {
|
|
139
|
-
await
|
|
143
|
+
await sub.fn(event);
|
|
140
144
|
}
|
|
141
145
|
catch (error) {
|
|
142
146
|
console.error(`Error in subscription ${sub.method}:`, error);
|
|
@@ -146,7 +150,12 @@ class WebSocketServer {
|
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
152
|
registerControllers(controllers) {
|
|
149
|
-
this.controllers = controllers
|
|
153
|
+
this.controllers = controllers.map((controller) => {
|
|
154
|
+
if (controller.getWebSocketController) {
|
|
155
|
+
return controller.getWebSocketController();
|
|
156
|
+
}
|
|
157
|
+
return controller;
|
|
158
|
+
});
|
|
150
159
|
}
|
|
151
160
|
subscribeToTopic(client, topic) {
|
|
152
161
|
if (!this.topics.has(topic)) {
|
|
@@ -186,8 +195,11 @@ class WebSocketServer {
|
|
|
186
195
|
timestamp: new Date().toISOString(),
|
|
187
196
|
});
|
|
188
197
|
topicClients.forEach((clientId) => {
|
|
198
|
+
if (exclude && exclude.includes(clientId)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
189
201
|
const client = this.clients.get(clientId);
|
|
190
|
-
if (client
|
|
202
|
+
if (client) {
|
|
191
203
|
client.socket.send(message);
|
|
192
204
|
}
|
|
193
205
|
});
|
package/dist/constants.d.ts
CHANGED
|
@@ -8,9 +8,8 @@ export declare const INTERCEPTOR = "app:interceptors";
|
|
|
8
8
|
export declare const ENDPOINT = "route:endpoints";
|
|
9
9
|
export declare const OK_METADATA_KEY = "custom:ok";
|
|
10
10
|
export declare const SERVER_CONFIG_KEY = "server:config";
|
|
11
|
-
export declare const SERVER_MODULES_KEY = "server:modules";
|
|
12
11
|
export declare const USE_MIDDLEWARE = "controller:usemiddleware";
|
|
13
|
-
export declare const
|
|
12
|
+
export declare const WS_HANDLER = "websocket:handler";
|
|
14
13
|
export declare const WS_TOPIC_KEY = "websocket:topic";
|
|
15
14
|
export declare const WS_SERVICE_KEY = "websocket:service";
|
|
16
15
|
export declare const INTECEPT = "server:intercept";
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CORS_METADATA = exports.INCREMENT_STATISTIC = exports.STATISTIC = exports.TO_VALIDATE = exports.OK_STATUSES = exports.STOPPED = exports.SANITIZE = exports.CATCH = exports.INTECEPT = exports.WS_SERVICE_KEY = exports.WS_TOPIC_KEY = exports.
|
|
3
|
+
exports.CORS_METADATA = exports.INCREMENT_STATISTIC = exports.STATISTIC = exports.TO_VALIDATE = exports.OK_STATUSES = exports.STOPPED = exports.SANITIZE = exports.CATCH = exports.INTECEPT = exports.WS_SERVICE_KEY = exports.WS_TOPIC_KEY = exports.WS_HANDLER = exports.USE_MIDDLEWARE = exports.SERVER_CONFIG_KEY = exports.OK_METADATA_KEY = exports.ENDPOINT = exports.INTERCEPTOR = exports.CONTROLLERS = exports.MIDDLEWARES = exports.ROUTE_MIDDLEWARES = exports.ROUTE_PREFIX = exports.APP_METADATA_KEY = exports.PARAM_METADATA_KEY = void 0;
|
|
4
4
|
exports.PARAM_METADATA_KEY = 'design:parameters';
|
|
5
5
|
exports.APP_METADATA_KEY = 'app:configuration';
|
|
6
6
|
exports.ROUTE_PREFIX = 'route:prefix';
|
|
@@ -11,9 +11,8 @@ exports.INTERCEPTOR = 'app:interceptors';
|
|
|
11
11
|
exports.ENDPOINT = 'route:endpoints';
|
|
12
12
|
exports.OK_METADATA_KEY = 'custom:ok';
|
|
13
13
|
exports.SERVER_CONFIG_KEY = 'server:config';
|
|
14
|
-
exports.SERVER_MODULES_KEY = 'server:modules';
|
|
15
14
|
exports.USE_MIDDLEWARE = 'controller:usemiddleware';
|
|
16
|
-
exports.
|
|
15
|
+
exports.WS_HANDLER = 'websocket:handler';
|
|
17
16
|
exports.WS_TOPIC_KEY = 'websocket:topic';
|
|
18
17
|
exports.WS_SERVICE_KEY = 'websocket:service';
|
|
19
18
|
exports.INTECEPT = 'server:intercept';
|
|
@@ -29,5 +29,17 @@ export declare function Controller(config: string | ControllerConfig, middleware
|
|
|
29
29
|
getControllerMethods: (controller: import("../types/index.js").ControllerInstance) => import("../types/index.js").ControllerMethods;
|
|
30
30
|
handleRequest: (request: AppRequest, response: ServerResponse) => Promise<any>;
|
|
31
31
|
routeWalker(context: RouteContext, request: AppRequest, response: ServerResponse): Promise<any>;
|
|
32
|
+
getWebSocketController(): {
|
|
33
|
+
instance: /*elided*/ any;
|
|
34
|
+
handlers: {
|
|
35
|
+
connection: any;
|
|
36
|
+
message: any;
|
|
37
|
+
close: any;
|
|
38
|
+
error: any;
|
|
39
|
+
};
|
|
40
|
+
topics: any;
|
|
41
|
+
};
|
|
42
|
+
getWSHandlers(type: string): any;
|
|
43
|
+
getWSTopics(): any;
|
|
32
44
|
};
|
|
33
45
|
} & T;
|
package/dist/core/Controller.js
CHANGED
|
@@ -200,6 +200,34 @@ function Controller(config, middlewares = []) {
|
|
|
200
200
|
}
|
|
201
201
|
return null;
|
|
202
202
|
}
|
|
203
|
+
getWebSocketController() {
|
|
204
|
+
return {
|
|
205
|
+
instance: this,
|
|
206
|
+
handlers: {
|
|
207
|
+
connection: this.getWSHandlers('connection'),
|
|
208
|
+
message: this.getWSHandlers('message'),
|
|
209
|
+
close: this.getWSHandlers('close'),
|
|
210
|
+
error: this.getWSHandlers('error'),
|
|
211
|
+
},
|
|
212
|
+
topics: this.getWSTopics(),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
getWSHandlers(type) {
|
|
216
|
+
const handlers = Reflect.getMetadata(_constants_1.WS_HANDLER, this.constructor) || [];
|
|
217
|
+
return handlers
|
|
218
|
+
.filter((h) => h.type === type)
|
|
219
|
+
.map((h) => ({
|
|
220
|
+
...h,
|
|
221
|
+
fn: this[h.method].bind(this),
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
getWSTopics() {
|
|
225
|
+
const topics = Reflect.getMetadata(_constants_1.WS_TOPIC_KEY, this.constructor) || [];
|
|
226
|
+
return topics.map((t) => ({
|
|
227
|
+
...t,
|
|
228
|
+
fn: this[t.method].bind(this),
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
203
231
|
};
|
|
204
232
|
};
|
|
205
233
|
}
|
|
@@ -15,9 +15,9 @@ const _constants_1 = require("../../constants.js");
|
|
|
15
15
|
*/
|
|
16
16
|
function OnWS(type, topic) {
|
|
17
17
|
return function (target, propertyKey, descriptor) {
|
|
18
|
-
const handlers = Reflect.getMetadata(_constants_1.
|
|
18
|
+
const handlers = Reflect.getMetadata(_constants_1.WS_HANDLER, target.constructor) || [];
|
|
19
19
|
handlers.push({ type, topic, method: propertyKey });
|
|
20
|
-
Reflect.defineMetadata(_constants_1.
|
|
20
|
+
Reflect.defineMetadata(_constants_1.WS_HANDLER, handlers, target.constructor);
|
|
21
21
|
return descriptor;
|
|
22
22
|
};
|
|
23
23
|
}
|
package/dist/examples/app.js
CHANGED
|
@@ -1,49 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
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;
|
|
22
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
9
|
exports.App = exports.Root = void 0;
|
|
43
|
-
const Joi = __importStar(require("joi"));
|
|
44
10
|
const core_1 = require("quantum-flow/core");
|
|
45
11
|
const http_1 = require("quantum-flow/http");
|
|
46
12
|
const middlewares_1 = require("quantum-flow/middlewares");
|
|
13
|
+
const socket_1 = require("./controllers/socket");
|
|
47
14
|
const user_1 = require("./controllers/user");
|
|
48
15
|
let Root = class Root {
|
|
49
16
|
};
|
|
@@ -51,7 +18,7 @@ exports.Root = Root;
|
|
|
51
18
|
exports.Root = Root = __decorate([
|
|
52
19
|
(0, core_1.Controller)({
|
|
53
20
|
prefix: 'api',
|
|
54
|
-
controllers: [user_1.User],
|
|
21
|
+
controllers: [user_1.User, socket_1.Socket],
|
|
55
22
|
middlewares: [function Global(req, res, next) { }],
|
|
56
23
|
}),
|
|
57
24
|
(0, middlewares_1.Cors)({ origin: '*' }),
|
|
@@ -60,15 +27,6 @@ exports.Root = Root = __decorate([
|
|
|
60
27
|
}),
|
|
61
28
|
(0, middlewares_1.Catch)(function GLOBALCATCH(err) {
|
|
62
29
|
return { status: 400 };
|
|
63
|
-
}),
|
|
64
|
-
(0, middlewares_1.Sanitize)({
|
|
65
|
-
schema: Joi.object({
|
|
66
|
-
name: Joi.string().trim().min(2).max(50).required(),
|
|
67
|
-
}),
|
|
68
|
-
action: 'both',
|
|
69
|
-
options: { abortEarly: false },
|
|
70
|
-
stripUnknown: true,
|
|
71
|
-
type: 'body',
|
|
72
30
|
})
|
|
73
31
|
], Root);
|
|
74
32
|
let App = class App {
|
|
@@ -77,7 +35,7 @@ exports.App = App;
|
|
|
77
35
|
exports.App = App = __decorate([
|
|
78
36
|
(0, http_1.Server)({
|
|
79
37
|
controllers: [Root],
|
|
80
|
-
websocket: { enabled: true },
|
|
38
|
+
websocket: { enabled: true, path: '/ws' },
|
|
81
39
|
interceptor: (data) => data,
|
|
82
40
|
errorHandler: (err) => err,
|
|
83
41
|
cors: { origin: '*' },
|
|
@@ -86,14 +44,5 @@ exports.App = App = __decorate([
|
|
|
86
44
|
(0, http_1.Port)(3000),
|
|
87
45
|
(0, middlewares_1.Use)(() => { }),
|
|
88
46
|
(0, middlewares_1.Use)([() => { }, () => { }]),
|
|
89
|
-
(0, middlewares_1.Catch)((err) => err)
|
|
90
|
-
(0, middlewares_1.Sanitize)({
|
|
91
|
-
schema: Joi.object({
|
|
92
|
-
name: Joi.string().trim().min(2).max(50).required(),
|
|
93
|
-
}),
|
|
94
|
-
action: 'both',
|
|
95
|
-
options: { abortEarly: false },
|
|
96
|
-
stripUnknown: true,
|
|
97
|
-
type: 'headers',
|
|
98
|
-
})
|
|
47
|
+
(0, middlewares_1.Catch)((err) => err)
|
|
99
48
|
], App);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { WebSocketEvent } from 'quantum-flow/core';
|
|
2
2
|
export declare class Socket {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
onNewsMessage(event: WebSocketEvent): void;
|
|
3
|
+
aaa(event: WebSocketEvent): void;
|
|
4
|
+
sunbcription(event: WebSocketEvent): void;
|
|
6
5
|
onPing(event: WebSocketEvent): void;
|
|
7
|
-
|
|
6
|
+
onChat(event: WebSocketEvent): void;
|
|
8
7
|
}
|
|
@@ -11,23 +11,25 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Socket = void 0;
|
|
13
13
|
const core_1 = require("quantum-flow/core");
|
|
14
|
+
const core_2 = require("quantum-flow/core");
|
|
14
15
|
let Socket = class Socket {
|
|
15
|
-
|
|
16
|
+
aaa(event) {
|
|
17
|
+
console.log('onConnection', event.message);
|
|
16
18
|
event.client.socket.send(JSON.stringify({ type: 'welcome', data: { message: 'welcome' } }));
|
|
17
19
|
}
|
|
18
|
-
|
|
20
|
+
sunbcription(event) {
|
|
19
21
|
const msg = event.message?.data;
|
|
20
22
|
if (msg?.text.includes('bad')) {
|
|
21
23
|
return;
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
|
-
onNewsMessage(event) { }
|
|
25
26
|
onPing(event) {
|
|
26
|
-
|
|
27
|
+
console.log('ping', event.message);
|
|
28
|
+
event.client.socket.send(JSON.stringify({ type: 'ping', data: { time: Date.now() } }));
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
event.client.socket.send(JSON.stringify({ type: '
|
|
30
|
+
onChat(event) {
|
|
31
|
+
console.log('chat', event.message);
|
|
32
|
+
event.client.socket.send(JSON.stringify({ type: 'onChat', data: { time: Date.now() } }));
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
35
|
exports.Socket = Socket;
|
|
@@ -36,19 +38,13 @@ __decorate([
|
|
|
36
38
|
__metadata("design:type", Function),
|
|
37
39
|
__metadata("design:paramtypes", [Object]),
|
|
38
40
|
__metadata("design:returntype", void 0)
|
|
39
|
-
], Socket.prototype, "
|
|
41
|
+
], Socket.prototype, "aaa", null);
|
|
40
42
|
__decorate([
|
|
41
|
-
(0,
|
|
43
|
+
(0, core_2.Subscribe)('chat'),
|
|
42
44
|
__metadata("design:type", Function),
|
|
43
45
|
__metadata("design:paramtypes", [Object]),
|
|
44
46
|
__metadata("design:returntype", void 0)
|
|
45
|
-
], Socket.prototype, "
|
|
46
|
-
__decorate([
|
|
47
|
-
(0, core_1.Subscribe)('news'),
|
|
48
|
-
__metadata("design:type", Function),
|
|
49
|
-
__metadata("design:paramtypes", [Object]),
|
|
50
|
-
__metadata("design:returntype", void 0)
|
|
51
|
-
], Socket.prototype, "onNewsMessage", null);
|
|
47
|
+
], Socket.prototype, "sunbcription", null);
|
|
52
48
|
__decorate([
|
|
53
49
|
(0, core_1.OnMessage)('ping'),
|
|
54
50
|
__metadata("design:type", Function),
|
|
@@ -56,11 +52,11 @@ __decorate([
|
|
|
56
52
|
__metadata("design:returntype", void 0)
|
|
57
53
|
], Socket.prototype, "onPing", null);
|
|
58
54
|
__decorate([
|
|
59
|
-
(0, core_1.OnMessage)('
|
|
55
|
+
(0, core_1.OnMessage)('chat'),
|
|
60
56
|
__metadata("design:type", Function),
|
|
61
57
|
__metadata("design:paramtypes", [Object]),
|
|
62
58
|
__metadata("design:returntype", void 0)
|
|
63
|
-
], Socket.prototype, "
|
|
59
|
+
], Socket.prototype, "onChat", null);
|
|
64
60
|
exports.Socket = Socket = __decorate([
|
|
65
61
|
(0, core_1.Controller)('socket')
|
|
66
62
|
], Socket);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { IWebSocketService } from 'quantum-flow/core';
|
|
1
2
|
export declare class UserMetadata {
|
|
2
3
|
getUserMetadata(params: any): Promise<any>;
|
|
3
|
-
createMeta(mult: any, body: any, params: any): Promise<{
|
|
4
|
+
createMeta(ws: IWebSocketService, mult: any, body: any, params: any): Promise<{
|
|
4
5
|
body: any;
|
|
5
6
|
params: any;
|
|
6
7
|
}>;
|
|
@@ -64,7 +64,7 @@ let UserMetadata = class UserMetadata {
|
|
|
64
64
|
async getUserMetadata(params) {
|
|
65
65
|
return params;
|
|
66
66
|
}
|
|
67
|
-
async createMeta(mult, body, params) {
|
|
67
|
+
async createMeta(ws, mult, body, params) {
|
|
68
68
|
return { body, params };
|
|
69
69
|
}
|
|
70
70
|
};
|
|
@@ -85,11 +85,12 @@ __decorate([
|
|
|
85
85
|
stripUnknown: true,
|
|
86
86
|
type: 'body',
|
|
87
87
|
}),
|
|
88
|
-
__param(0, (0, core_1.
|
|
89
|
-
__param(1, (0, core_1.
|
|
90
|
-
__param(2, (0, core_1.
|
|
88
|
+
__param(0, (0, core_1.InjectWS)()),
|
|
89
|
+
__param(1, (0, core_1.Multipart)()),
|
|
90
|
+
__param(2, (0, core_1.Body)(DTO)),
|
|
91
|
+
__param(3, (0, core_1.Params)('meta')),
|
|
91
92
|
__metadata("design:type", Function),
|
|
92
|
-
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
93
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
93
94
|
__metadata("design:returntype", Promise)
|
|
94
95
|
], UserMetadata.prototype, "createMeta", null);
|
|
95
96
|
exports.UserMetadata = UserMetadata = __decorate([
|
package/dist/utils/server.js
CHANGED
|
@@ -6,7 +6,6 @@ const resolveConfig = (configOrClass) => {
|
|
|
6
6
|
let config = {};
|
|
7
7
|
if (configOrClass && typeof configOrClass === 'function') {
|
|
8
8
|
const decoratorConfig = Reflect.getMetadata(_constants_1.SERVER_CONFIG_KEY, configOrClass) || {};
|
|
9
|
-
const controllers = Reflect.getMetadata(_constants_1.SERVER_MODULES_KEY, configOrClass) || [];
|
|
10
9
|
const errorHandler = Reflect.getMetadata(_constants_1.CATCH, configOrClass);
|
|
11
10
|
const interceptors = Reflect.getMetadata(_constants_1.INTECEPT, configOrClass);
|
|
12
11
|
const middlewares = Reflect.getMetadata(_constants_1.USE_MIDDLEWARE, configOrClass);
|
|
@@ -19,7 +18,7 @@ const resolveConfig = (configOrClass) => {
|
|
|
19
18
|
interceptors,
|
|
20
19
|
middlewares: decoratorConfig.middlewares.concat(middlewares),
|
|
21
20
|
cors: decoratorConfig.cors,
|
|
22
|
-
controllers:
|
|
21
|
+
controllers: decoratorConfig.controllers || [],
|
|
23
22
|
sanitizers,
|
|
24
23
|
};
|
|
25
24
|
}
|