taon 21.0.53 → 21.0.55
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/bin/taon +5 -5
- package/bin/taon-debug +5 -5
- package/bin/taon-debug-brk +4 -4
- package/browser/package.json +1 -1
- package/browser-prod/package.json +1 -1
- package/icon-menu-taon.svg +15 -15
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib-prod/base-classes/base-abstract-entity.js +17 -31
- package/lib-prod/base-classes/base-angular-service.js +83 -55
- package/lib-prod/base-classes/base-class.js +33 -35
- package/lib-prod/base-classes/base-context.js +17 -19
- package/lib-prod/base-classes/base-controller.js +146 -154
- package/lib-prod/base-classes/base-crud-controller.js +250 -221
- package/lib-prod/base-classes/base-custom-repository.js +7 -18
- package/lib-prod/base-classes/base-electron-service.js +49 -0
- package/lib-prod/base-classes/base-entity.js +20 -30
- package/lib-prod/base-classes/base-file-upload.middleware.js +72 -75
- package/lib-prod/base-classes/base-injector.js +176 -194
- package/lib-prod/base-classes/base-middleware.js +8 -5
- package/lib-prod/base-classes/base-migration.js +19 -22
- package/lib-prod/base-classes/base-provider.js +7 -5
- package/lib-prod/base-classes/base-repository.js +601 -573
- package/lib-prod/base-classes/base-subscriber-for-entity.js +143 -152
- package/lib-prod/base-classes/base.js +18 -0
- package/lib-prod/build-info._auto-generated_.js +26 -14
- package/lib-prod/config/controller-config.js +24 -24
- package/lib-prod/config/controller-options.js +2 -5
- package/lib-prod/config/method-config.js +6 -8
- package/lib-prod/config/param-config.js +2 -8
- package/lib-prod/constants.js +29 -25
- package/lib-prod/context-db-migrations.js +328 -324
- package/lib-prod/create-context.js +211 -146
- package/lib-prod/decorators/classes/controller-decorator.js +16 -20
- package/lib-prod/decorators/classes/entity-decorator.js +26 -47
- package/lib-prod/decorators/classes/middleware-decorator.js +14 -24
- package/lib-prod/decorators/classes/migration-decorator.js +13 -22
- package/lib-prod/decorators/classes/provider-decorator.js +13 -23
- package/lib-prod/decorators/classes/repository-decorator.js +13 -22
- package/lib-prod/decorators/classes/subscriber-decorator.js +13 -23
- package/lib-prod/decorators/decorator-abstract-opt.js +1 -4
- package/lib-prod/decorators/http/http-decorators.js +20 -5
- package/lib-prod/decorators/http/http-methods-decorators.js +91 -133
- package/lib-prod/decorators/http/http-params-decorators.js +36 -62
- package/lib-prod/dependency-injection/di-container.js +28 -29
- package/lib-prod/endpoint-context-storage.js +27 -32
- package/lib-prod/endpoint-context.js +2294 -1930
- package/lib-prod/entity-process.js +209 -198
- package/lib-prod/env/env.angular-node-app.js +66 -130
- package/lib-prod/env/env.docs-webapp.js +66 -130
- package/lib-prod/env/env.electron-app.js +66 -130
- package/lib-prod/env/env.mobile-app.js +66 -130
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +66 -130
- package/lib-prod/env/env.vscode-plugin.js +66 -130
- package/lib-prod/env/index.js +6 -6
- package/lib-prod/express-types.js +1 -0
- package/lib-prod/formly/formly.models.js +1 -0
- package/lib-prod/formly/fromly.js +196 -175
- package/lib-prod/formly/type-from-entity.js +45 -52
- package/lib-prod/get-response-value.js +21 -18
- package/lib-prod/global-state/taon-global-state/index.js +6 -5
- package/lib-prod/global-state/taon-global-state/taon-global-state.abstract.context.js +18 -19
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.js +6 -9
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.js +40 -46
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.js +33 -46
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.js +10 -20
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.js +43 -33
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.js +10 -20
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.js +43 -44
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.js +20 -27
- package/lib-prod/global-state/taon-global-state/taon-global-state.utils.js +10 -10
- package/lib-prod/global-state/taon-transaction-registry/index.js +11 -10
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.abstract.context.js +20 -21
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.js +4 -7
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.js +34 -39
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.js +34 -54
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.js +10 -20
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.js +7 -10
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.js +10 -20
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.js +29 -34
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.js +20 -27
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.js +4 -5
- package/lib-prod/helpers/class-helpers.js +210 -177
- package/lib-prod/helpers/clone-obj.js +16 -20
- package/lib-prod/helpers/taon-helpers.js +132 -114
- package/lib-prod/index._auto-generated_.js +5 -0
- package/lib-prod/index.js +248 -227
- package/lib-prod/inject.js +88 -33
- package/lib-prod/migrations/index.js +2 -1
- package/lib-prod/migrations/migrations_index._auto-generated_.js +3 -0
- package/lib-prod/models.js +72 -103
- package/lib-prod/orm/columns.js +58 -118
- package/lib-prod/orm/index.js +56 -1
- package/lib-prod/package.json +1 -1
- package/lib-prod/realtime/realtime-client.js +188 -186
- package/lib-prod/realtime/realtime-core.js +77 -78
- package/lib-prod/realtime/realtime-server.js +225 -240
- package/lib-prod/realtime/realtime-strategy/index.js +4 -4
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.js +273 -219
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.js +267 -240
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.js +26 -20
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.js +10 -13
- package/lib-prod/realtime/realtime-subs-manager.js +82 -90
- package/lib-prod/realtime/realtime.models.js +2 -0
- package/lib-prod/symbols.js +104 -105
- package/lib-prod/ui/index.js +1 -5
- package/lib-prod/ui/taon-admin-mode-configuration/index.js +1 -5
- package/lib-prod/validators.js +43 -37
- package/lib-prod.split-namespaces.json +32 -86
- package/package.json +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
|
@@ -1,262 +1,289 @@
|
|
|
1
|
-
import { RealtimeStrategy } from
|
|
2
|
-
import { Symbols__NS__REALTIME } from
|
|
1
|
+
import { RealtimeStrategy } from './realtime-strategy';
|
|
2
|
+
import { Symbols__NS__REALTIME } from '../../symbols';
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region mock server
|
|
3
5
|
class MockServer {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
static { this.serverByUrl = new Map(); }
|
|
7
|
+
static from(url) {
|
|
8
|
+
if (!MockServer.serverByUrl.has(url)) {
|
|
9
|
+
MockServer.serverByUrl.set(url, new MockServer(url));
|
|
10
|
+
}
|
|
11
|
+
return MockServer.serverByUrl.get(url);
|
|
12
|
+
}
|
|
13
|
+
get allServers() {
|
|
14
|
+
return Array.from(MockServer.serverByUrl.values());
|
|
15
|
+
}
|
|
16
|
+
//#region constructor
|
|
17
|
+
constructor(url) {
|
|
18
|
+
this.url = url;
|
|
19
|
+
this.namespacesByName = new Map();
|
|
20
|
+
MockServer.serverByUrl.set(url, this);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region of
|
|
24
|
+
of(namespace) {
|
|
25
|
+
if (!this.namespacesByName.has(namespace)) {
|
|
26
|
+
this.namespacesByName.set(namespace, new MockNamespace(namespace, this));
|
|
27
|
+
}
|
|
28
|
+
return this.namespacesByName.get(namespace);
|
|
13
29
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
namespacesByName = /* @__PURE__ */ new Map();
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region of
|
|
22
|
-
of(namespace) {
|
|
23
|
-
if (!this.namespacesByName.has(namespace)) {
|
|
24
|
-
this.namespacesByName.set(namespace, new MockNamespace(namespace, this));
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region path
|
|
32
|
+
path() {
|
|
33
|
+
return this.url;
|
|
25
34
|
}
|
|
26
|
-
return this.namespacesByName.get(namespace);
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region path
|
|
30
|
-
path() {
|
|
31
|
-
return this.url;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
35
|
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region mock namespace
|
|
35
38
|
class MockNamespace {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
39
|
+
//#region constructor
|
|
40
|
+
constructor(
|
|
41
|
+
/**
|
|
42
|
+
* unique namespace name
|
|
43
|
+
*/
|
|
44
|
+
name, server) {
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.server = server;
|
|
47
|
+
/**
|
|
48
|
+
* All sockets connected to this namespace
|
|
49
|
+
*/
|
|
50
|
+
this.allSocketsForNamespace = new Set();
|
|
51
|
+
/**
|
|
52
|
+
* Rooms and their sockets
|
|
53
|
+
*/
|
|
54
|
+
this.socketByRoomName = {};
|
|
55
|
+
/**
|
|
56
|
+
* Event handlers for this namespace
|
|
57
|
+
*/
|
|
58
|
+
this.namespaceEventHandlers = {};
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region on
|
|
62
|
+
on(eventName, handler) {
|
|
63
|
+
// console.log(`ON EVNET event "${eventName}"`);
|
|
64
|
+
if (!this.namespaceEventHandlers[eventName]) {
|
|
65
|
+
this.namespaceEventHandlers[eventName] =
|
|
66
|
+
new Set();
|
|
67
|
+
}
|
|
68
|
+
if (!this.namespaceEventHandlers[eventName].has(handler)) {
|
|
69
|
+
this.namespaceEventHandlers[eventName].add(handler);
|
|
70
|
+
}
|
|
71
|
+
// QUICK_FIX Emit connection event for backend
|
|
72
|
+
// TODO make it in emit
|
|
73
|
+
if (eventName === 'connection') {
|
|
74
|
+
setTimeout(() => {
|
|
75
|
+
this.emit('connection', this);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region emit
|
|
81
|
+
emit(event, ...args) {
|
|
82
|
+
this.allSocketsForNamespace?.forEach(socket => {
|
|
83
|
+
socket.emit(event, ...args);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region connect
|
|
88
|
+
connect(socket) {
|
|
89
|
+
this.allSocketsForNamespace.add(socket);
|
|
90
|
+
socket.namespaceInstance = this;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region to
|
|
94
|
+
to(roomName) {
|
|
95
|
+
const socketsInRoom = this.socketByRoomName[roomName];
|
|
96
|
+
return new RoomEmitter(socketsInRoom, true);
|
|
58
97
|
}
|
|
59
|
-
|
|
60
|
-
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region to room
|
|
100
|
+
in(roomName) {
|
|
101
|
+
const socketsInRoom = this.socketByRoomName[roomName];
|
|
102
|
+
return new RoomEmitter(socketsInRoom, false);
|
|
61
103
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region join room
|
|
106
|
+
joinRoom(roomName, socket) {
|
|
107
|
+
if (!this.socketByRoomName[roomName]) {
|
|
108
|
+
this.socketByRoomName[roomName] = new Set();
|
|
109
|
+
}
|
|
110
|
+
this.socketByRoomName[roomName].add(socket);
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region leave room
|
|
114
|
+
leaveRoom(roomName, socket) {
|
|
115
|
+
const roomSockets = this.socketByRoomName[roomName];
|
|
116
|
+
if (roomSockets) {
|
|
117
|
+
this.socketByRoomName[roomName].delete(socket);
|
|
118
|
+
}
|
|
66
119
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//#region connect
|
|
77
|
-
connect(socket) {
|
|
78
|
-
this.allSocketsForNamespace.add(socket);
|
|
79
|
-
socket.namespaceInstance = this;
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region to
|
|
83
|
-
to(roomName) {
|
|
84
|
-
const socketsInRoom = this.socketByRoomName[roomName];
|
|
85
|
-
return new RoomEmitter(socketsInRoom, true);
|
|
86
|
-
}
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region to room
|
|
89
|
-
in(roomName) {
|
|
90
|
-
const socketsInRoom = this.socketByRoomName[roomName];
|
|
91
|
-
return new RoomEmitter(socketsInRoom, false);
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region join room
|
|
95
|
-
joinRoom(roomName, socket) {
|
|
96
|
-
if (!this.socketByRoomName[roomName]) {
|
|
97
|
-
this.socketByRoomName[roomName] = /* @__PURE__ */ new Set();
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region nsp + name
|
|
122
|
+
get nsp() {
|
|
123
|
+
const self = this;
|
|
124
|
+
return {
|
|
125
|
+
get name() {
|
|
126
|
+
return self.name;
|
|
127
|
+
},
|
|
128
|
+
};
|
|
98
129
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//#region leave room
|
|
103
|
-
leaveRoom(roomName, socket) {
|
|
104
|
-
const roomSockets = this.socketByRoomName[roomName];
|
|
105
|
-
if (roomSockets) {
|
|
106
|
-
this.socketByRoomName[roomName].delete(socket);
|
|
130
|
+
//#endregion
|
|
131
|
+
path() {
|
|
132
|
+
return this.name;
|
|
107
133
|
}
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region nsp + name
|
|
111
|
-
get nsp() {
|
|
112
|
-
const self = this;
|
|
113
|
-
return {
|
|
114
|
-
get name() {
|
|
115
|
-
return self.name;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
//#endregion
|
|
120
|
-
path() {
|
|
121
|
-
return this.name;
|
|
122
|
-
}
|
|
123
134
|
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region room emitter
|
|
124
137
|
class RoomEmitter {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
//#region constructor
|
|
139
|
+
constructor(sockets, includeSender = false, sender = null) {
|
|
140
|
+
this.sockets = sockets;
|
|
141
|
+
this.includeSender = includeSender;
|
|
142
|
+
this.sender = sender;
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region emit in room
|
|
146
|
+
emit(event, ...args) {
|
|
147
|
+
// console.log(
|
|
148
|
+
// `emit room emiter ${event} , this.sockets ${this.sockets.length}`,
|
|
149
|
+
// );
|
|
150
|
+
this.sockets?.forEach(socket => {
|
|
151
|
+
// console.log(`emit event ${event} to socket ${socket.id}`);
|
|
152
|
+
if (this.includeSender || socket !== this.sender) {
|
|
153
|
+
socket.emit(event, ...args);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
141
157
|
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region mock socket
|
|
142
160
|
class MockSocket {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
//#region path
|
|
169
|
-
path() {
|
|
170
|
-
return this.namespaceInstance?.name;
|
|
171
|
-
}
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region on
|
|
174
|
-
on(eventName, handler) {
|
|
175
|
-
if (!this.socketEventHandlers[eventName]) {
|
|
176
|
-
this.socketEventHandlers[eventName] = /* @__PURE__ */ new Set();
|
|
161
|
+
get id() {
|
|
162
|
+
return this.nsp.name;
|
|
163
|
+
}
|
|
164
|
+
//#region constructor
|
|
165
|
+
constructor(url, opts) {
|
|
166
|
+
this.url = url;
|
|
167
|
+
this.socketEventHandlers = {};
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
const [baseUrl, namespace] = [url, opts.path || '/'];
|
|
170
|
+
// console.log({ url, baseUrl, namespace });
|
|
171
|
+
const namespaceName = namespace || '/';
|
|
172
|
+
// Look up the server instance from the registry
|
|
173
|
+
const server = MockServer.from(url);
|
|
174
|
+
const ns = server.of(namespaceName);
|
|
175
|
+
ns.connect(this);
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region nsp + name
|
|
179
|
+
get nsp() {
|
|
180
|
+
const self = this;
|
|
181
|
+
return {
|
|
182
|
+
get name() {
|
|
183
|
+
return self.namespaceInstance?.name;
|
|
184
|
+
},
|
|
185
|
+
};
|
|
177
186
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.
|
|
182
|
-
});
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region path
|
|
189
|
+
path() {
|
|
190
|
+
return this.namespaceInstance?.name;
|
|
183
191
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const room = args[0];
|
|
191
|
-
this.join(room);
|
|
192
|
-
} else if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomUnsubscribe}`)) {
|
|
193
|
-
const room = args[0];
|
|
194
|
-
this.leave(room);
|
|
195
|
-
} else {
|
|
196
|
-
if (this.namespaceInstance) {
|
|
197
|
-
const namespaceEventHandlers = this.namespaceInstance.namespaceEventHandlers[eventName] || [];
|
|
198
|
-
for (const namespaceEventHandler of namespaceEventHandlers) {
|
|
199
|
-
if (namespaceEventHandler) {
|
|
200
|
-
namespaceEventHandler(...args);
|
|
201
|
-
}
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region on
|
|
194
|
+
on(eventName, handler) {
|
|
195
|
+
if (!this.socketEventHandlers[eventName]) {
|
|
196
|
+
this.socketEventHandlers[eventName] =
|
|
197
|
+
new Set();
|
|
202
198
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
199
|
+
this.socketEventHandlers[eventName].add(handler);
|
|
200
|
+
// QUICK_FIX client initing itself
|
|
201
|
+
if (eventName === 'connect') {
|
|
202
|
+
setTimeout(() => {
|
|
203
|
+
this.emit('connect');
|
|
204
|
+
// this.namespaceInstance.emit('connection', this); @UNCOMMNENT
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region emit
|
|
210
|
+
emit(eventName, ...args) {
|
|
211
|
+
eventName = eventName || '';
|
|
212
|
+
if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomSubscribe}`)) {
|
|
213
|
+
const room = args[0];
|
|
214
|
+
this.join(room);
|
|
213
215
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
clientHandler(...args);
|
|
218
|
-
}
|
|
216
|
+
else if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomUnsubscribe}`)) {
|
|
217
|
+
const room = args[0];
|
|
218
|
+
this.leave(room);
|
|
219
219
|
}
|
|
220
|
-
|
|
220
|
+
else {
|
|
221
|
+
// console.log('try to emit event (to server)', event);
|
|
222
|
+
if (this.namespaceInstance) {
|
|
223
|
+
const namespaceEventHandlers = this.namespaceInstance.namespaceEventHandlers[eventName] || [];
|
|
224
|
+
// emit to namespace events
|
|
225
|
+
for (const namespaceEventHandler of namespaceEventHandlers) {
|
|
226
|
+
if (namespaceEventHandler) {
|
|
227
|
+
namespaceEventHandler(...args);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const allSocketsForNamespaceExceptCurrent = Array.from(this.namespaceInstance.allSocketsForNamespace.values()).filter(socket => socket !== this);
|
|
231
|
+
// emit to all sockets in namespace
|
|
232
|
+
for (const socket of allSocketsForNamespaceExceptCurrent) {
|
|
233
|
+
const socketEventHandlers = socket.socketEventHandlers[eventName];
|
|
234
|
+
for (const socketEventHandler of socketEventHandlers) {
|
|
235
|
+
if (socketEventHandler) {
|
|
236
|
+
socketEventHandler(...args);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Emit to current socket
|
|
241
|
+
const socketEventHandlers = this.socketEventHandlers[eventName] || [];
|
|
242
|
+
for (const clientHandler of socketEventHandlers) {
|
|
243
|
+
if (clientHandler) {
|
|
244
|
+
clientHandler(...args);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region join room
|
|
252
|
+
join(roomName) {
|
|
253
|
+
this.namespaceInstance.joinRoom(roomName, this);
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region leave room
|
|
257
|
+
leave(roomName) {
|
|
258
|
+
this.namespaceInstance.leaveRoom(roomName, this);
|
|
221
259
|
}
|
|
222
|
-
}
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region join room
|
|
225
|
-
join(roomName) {
|
|
226
|
-
this.namespaceInstance.joinRoom(roomName, this);
|
|
227
|
-
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region leave room
|
|
230
|
-
leave(roomName) {
|
|
231
|
-
this.namespaceInstance.leaveRoom(roomName, this);
|
|
232
|
-
}
|
|
233
|
-
//#endregion
|
|
234
260
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
261
|
+
//#endregion
|
|
262
|
+
/**
|
|
263
|
+
* Purpose:
|
|
264
|
+
* - browser-browser communication mock (in websql mode)
|
|
265
|
+
*/
|
|
266
|
+
export class RealtimeStrategyMock extends RealtimeStrategy {
|
|
267
|
+
//#region toString
|
|
268
|
+
toString() {
|
|
269
|
+
return 'mock';
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region constructor
|
|
273
|
+
constructor(ctx) {
|
|
274
|
+
super(ctx);
|
|
275
|
+
this.ctx = ctx;
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region server & io
|
|
279
|
+
ioServer(url, opt) {
|
|
280
|
+
const server = MockServer.from(url || this.ctx.uriOrigin);
|
|
281
|
+
return server.of(opt?.path || '/');
|
|
282
|
+
}
|
|
283
|
+
get ioClient() {
|
|
284
|
+
const clientIo = (uri, opts) => {
|
|
285
|
+
return new MockSocket(uri || this.ctx.uriOrigin, opts);
|
|
286
|
+
};
|
|
287
|
+
return clientIo;
|
|
288
|
+
}
|
|
259
289
|
}
|
|
260
|
-
export {
|
|
261
|
-
RealtimeStrategyMock
|
|
262
|
-
};
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import { RealtimeStrategy } from
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { RealtimeStrategy } from './realtime-strategy';
|
|
2
|
+
//#region @backend
|
|
3
|
+
import { Server } from 'socket.io';
|
|
4
|
+
//#endregion
|
|
5
|
+
import { io } from 'socket.io-client';
|
|
6
|
+
/**
|
|
7
|
+
* Purpose:
|
|
8
|
+
* - backend-browser communication
|
|
9
|
+
* - backend-backend communication
|
|
10
|
+
*/
|
|
11
|
+
export class RealtimeStrategySocketIO extends RealtimeStrategy {
|
|
12
|
+
toString() {
|
|
13
|
+
return 'socket-io';
|
|
14
|
+
}
|
|
15
|
+
constructor(ctx) {
|
|
16
|
+
super(ctx);
|
|
17
|
+
this.ctx = ctx;
|
|
18
|
+
}
|
|
19
|
+
ioServer(...args) {
|
|
20
|
+
//#region @backendFunc
|
|
21
|
+
return new Server(...args);
|
|
22
|
+
//#endregion
|
|
23
|
+
}
|
|
24
|
+
get ioClient() {
|
|
25
|
+
return io;
|
|
26
|
+
}
|
|
18
27
|
}
|
|
19
|
-
export {
|
|
20
|
-
RealtimeStrategySocketIO
|
|
21
|
-
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
class RealtimeStrategy {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
export class RealtimeStrategy {
|
|
2
|
+
constructor(ctx) {
|
|
3
|
+
this.ctx = ctx;
|
|
4
|
+
}
|
|
5
|
+
get ioClient() {
|
|
6
|
+
throw new Error('Not implemented');
|
|
7
|
+
}
|
|
8
|
+
ioServer(url, opt) {
|
|
9
|
+
throw new Error('Not implemented');
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
|
-
export {
|
|
13
|
-
RealtimeStrategy
|
|
14
|
-
};
|