@ejfdelgado/ejflab-back 1.1.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/LICENSE +201 -0
- package/README.md +2 -0
- package/package.json +57 -0
- package/srv/AudIASrv.mjs +218 -0
- package/srv/AuthorizationSrv.mjs +213 -0
- package/srv/ComputeEngineSrv.mjs +289 -0
- package/srv/EmailHandler.mjs +54 -0
- package/srv/Image2MeshSrv.mjs +101 -0
- package/srv/ImagiationSrv.mjs +408 -0
- package/srv/KeysSrv.mjs +104 -0
- package/srv/MainHandler.mjs +140 -0
- package/srv/MainReplacer.mjs +77 -0
- package/srv/MfaSrv.mjs +266 -0
- package/srv/MilvusSrv.mjs +152 -0
- package/srv/MinioSrv.mjs +154 -0
- package/srv/MongoSrv.mjs +320 -0
- package/srv/MyError.mjs +48 -0
- package/srv/MyFileService.mjs +392 -0
- package/srv/MyFileServiceLocal.mjs +177 -0
- package/srv/MyPdf.mjs +37 -0
- package/srv/MyShell.mjs +205 -0
- package/srv/MySqlSrv.mjs +43 -0
- package/srv/Network.mjs +111 -0
- package/srv/OpenCVSrv.mjs +27 -0
- package/srv/PageSrv.mjs +234 -0
- package/srv/PayUSrv.mjs +186 -0
- package/srv/PayUSrvConstants.mjs +46 -0
- package/srv/PostgresSrv.mjs +109 -0
- package/srv/SecretsSrv.mjs +126 -0
- package/srv/SocketIOCall.mjs +494 -0
- package/srv/TupleSrv.mjs +141 -0
- package/srv/UtilesSrv.mjs +8 -0
- package/srv/callprocessors/AskIceServersProcessor.mjs +14 -0
- package/srv/callprocessors/AskRoomProcessor.mjs +15 -0
- package/srv/callprocessors/CallUserProcessor.mjs +17 -0
- package/srv/callprocessors/ChatSetSawProcessor.mjs +42 -0
- package/srv/callprocessors/CheckSrcResponseProcessor.mjs +28 -0
- package/srv/callprocessors/ClientChangeProcessor.mjs +19 -0
- package/srv/callprocessors/CloseVideoChatProcessor.mjs +16 -0
- package/srv/callprocessors/DestroyModelProcessor.mjs +16 -0
- package/srv/callprocessors/DisconnectProcessor.mjs +53 -0
- package/srv/callprocessors/GenericProcessor.mjs +7 -0
- package/srv/callprocessors/GetModelProcessor.mjs +11 -0
- package/srv/callprocessors/IncludeOtherPeersProcessor.mjs +12 -0
- package/srv/callprocessors/LoadFlowChartProcessor.mjs +103 -0
- package/srv/callprocessors/MakeAnswerProcessor.mjs +17 -0
- package/srv/callprocessors/OnIceCandidateProcessor.mjs +13 -0
- package/srv/callprocessors/OpenVideoChatProcessor.mjs +17 -0
- package/srv/callprocessors/PauseFlowChartProcessor.mjs +16 -0
- package/srv/callprocessors/ProcessResponseProcessor.mjs +123 -0
- package/srv/callprocessors/ReadSrcResponseProcessor.mjs +30 -0
- package/srv/callprocessors/RegisterProcessorProcessor.mjs +23 -0
- package/srv/callprocessors/RegisterSourceProcessor.mjs +22 -0
- package/srv/callprocessors/SendChatProcessor.mjs +71 -0
- package/srv/callprocessors/StartFlowChartProcessor.mjs +48 -0
- package/srv/callprocessors/StopFlowChartProcessor.mjs +16 -0
- package/srv/callprocessors/SubscribemeProcessor.mjs +13 -0
- package/srv/callprocessors/UpdateMyInformationProcessor.mjs +30 -0
- package/srv/common/FirebasConfig.mjs +160 -0
- package/srv/common/General.mjs +69 -0
- package/srv/common/MimeTypeMap.mjs +142 -0
- package/srv/common/MyStore.mjs +169 -0
- package/srv/common/Usuario.mjs +101 -0
- package/srv/common/Utilidades.mjs +43 -0
@@ -0,0 +1,494 @@
|
|
1
|
+
import { CallUserProcessor } from "./callprocessors/CallUserProcessor.mjs";
|
2
|
+
import { MakeAnswerProcessor } from "./callprocessors/MakeAnswerProcessor.mjs";
|
3
|
+
import { Mutex } from 'async-mutex';
|
4
|
+
import { AskRoomProcessor } from "./callprocessors/AskRoomProcessor.mjs";
|
5
|
+
import { ClientChangeProcessor } from "./callprocessors/ClientChangeProcessor.mjs";
|
6
|
+
import { MyTuples } from "@ejfdelgado/ejflab-common/src/MyTuples.js";
|
7
|
+
import { SimpleObj } from "@ejfdelgado/ejflab-common/src/SimpleObj.js";
|
8
|
+
import { IdGen } from "@ejfdelgado/ejflab-common/src/IdGen.js";
|
9
|
+
import { GetModelProcessor } from "./callprocessors/GetModelProcessor.mjs";
|
10
|
+
import { LoadFlowChartProcessor } from "./callprocessors/LoadFlowChartProcessor.mjs";
|
11
|
+
import { DestroyModelProcessor } from "./callprocessors/DestroyModelProcessor.mjs";
|
12
|
+
import { OnIceCandidateProcessor } from "./callprocessors/OnIceCandidateProcessor.mjs";
|
13
|
+
import { AskIceServersProcessor } from "./callprocessors/AskIceServersProcessor.mjs";
|
14
|
+
import EventEmitter from 'node:events';
|
15
|
+
import { StartFlowChartProcessor } from "./callprocessors/StartFlowChartProcessor.mjs";
|
16
|
+
import { StopFlowChartProcessor } from "./callprocessors/StopFlowChartProcessor.mjs";
|
17
|
+
import { RegisterSourceProcessor } from "./callprocessors/RegisterSourceProcessor.mjs";
|
18
|
+
import { DisconnectProcessor } from "./callprocessors/DisconnectProcessor.mjs";
|
19
|
+
import { CheckSrcResponseProcessor } from "./callprocessors/CheckSrcResponseProcessor.mjs";
|
20
|
+
import { PauseFlowChartProcessor } from "./callprocessors/PauseFlowChartProcessor.mjs";
|
21
|
+
import { ReadSrcResponseProcessor } from "./callprocessors/ReadSrcResponseProcessor.mjs";
|
22
|
+
import { RegisterProcessorProcessor } from "./callprocessors/RegisterProcessorProcessor.mjs";
|
23
|
+
import { ProcessResponseProcessor } from "./callprocessors/ProcessResponseProcessor.mjs";
|
24
|
+
import { SubscribemeProcessor } from "./callprocessors/SubscribemeProcessor.mjs";
|
25
|
+
import { SendChatProcessor } from "./callprocessors/SendChatProcessor.mjs";
|
26
|
+
import { UpdateMyInformationProcessor } from "./callprocessors/UpdateMyInformationProcessor.mjs";
|
27
|
+
import axios from "axios";
|
28
|
+
import { encode, decode } from "@msgpack/msgpack";
|
29
|
+
import { ChatSetSawProcessor } from "./callprocessors/ChatSetSawProcessor.mjs";
|
30
|
+
import { MilvusSrv } from "./MilvusSrv.mjs";
|
31
|
+
import { MongoSrv } from "./MongoSrv.mjs";
|
32
|
+
import { MinioSrv } from "./MinioSrv.mjs";
|
33
|
+
import { OpenVideoChatProcessor } from "./callprocessors/OpenVideoChatProcessor.mjs";
|
34
|
+
import { CloseVideoChatProcessor } from "./callprocessors/CloseVideoChatProcessor.mjs";
|
35
|
+
import { IncludeOtherPeersProcessor } from "./callprocessors/IncludeOtherPeersProcessor.mjs";
|
36
|
+
|
37
|
+
export class SocketIOCall {
|
38
|
+
static io;
|
39
|
+
static mutex = new Mutex();
|
40
|
+
|
41
|
+
static mapSockets = {};
|
42
|
+
static socketToRoom = {};
|
43
|
+
static roomLiveTupleModel = {};
|
44
|
+
static mapFlowChartExec = {};
|
45
|
+
static socketIdToSocket = {};
|
46
|
+
static socketRoomUUIDMap = {};
|
47
|
+
|
48
|
+
static echoLog(message) {
|
49
|
+
console.log(message);
|
50
|
+
SocketIOCall.io.emit('echoLog', { message });
|
51
|
+
}
|
52
|
+
|
53
|
+
static setFlowChartExec(room, instance) {
|
54
|
+
this.mapFlowChartExec[room] = instance;
|
55
|
+
instance.setSuperContext(this);
|
56
|
+
}
|
57
|
+
|
58
|
+
static getAxios() {
|
59
|
+
return axios;
|
60
|
+
}
|
61
|
+
|
62
|
+
static getMilvusClient() {
|
63
|
+
return MilvusSrv;
|
64
|
+
}
|
65
|
+
|
66
|
+
static getMongoClient() {
|
67
|
+
return MongoSrv;
|
68
|
+
}
|
69
|
+
|
70
|
+
static getMinioClient() {
|
71
|
+
return MinioSrv;
|
72
|
+
}
|
73
|
+
|
74
|
+
static async autoCreateRoomFlowChart(room) {
|
75
|
+
console.log(`autoCreateRoomFlowChart ${room}`);
|
76
|
+
const root_folder = process.env.WORKSPACE;
|
77
|
+
const payload = {
|
78
|
+
names: {},
|
79
|
+
conf: {
|
80
|
+
debug: false,
|
81
|
+
sleep: 100
|
82
|
+
},
|
83
|
+
dataPath: {
|
84
|
+
"state.processors": `${root_folder}/flowcharts/processors/processors.json`,
|
85
|
+
},
|
86
|
+
skipValidation: true,
|
87
|
+
room,
|
88
|
+
};
|
89
|
+
const socket = null;
|
90
|
+
await new LoadFlowChartProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
91
|
+
return this.mapFlowChartExec[room];
|
92
|
+
}
|
93
|
+
|
94
|
+
static async getFlowChartExec(room) {
|
95
|
+
let created = this.mapFlowChartExec[room];
|
96
|
+
const AUTO_ROOMS = ["processors"];
|
97
|
+
if (!created && AUTO_ROOMS.indexOf(room) >= 0) {
|
98
|
+
created = await SocketIOCall.autoCreateRoomFlowChart(room);
|
99
|
+
}
|
100
|
+
return created;
|
101
|
+
}
|
102
|
+
|
103
|
+
static getRoomLiveTupleModel(room, rebuild = false) {
|
104
|
+
const builderConfig = {
|
105
|
+
MAX_SEND_SIZE: 10000,
|
106
|
+
LOW_PRESSURE_MS: 0,
|
107
|
+
// No tiene sentido porque como la actualización es asincrona, nunca se sabe si falló
|
108
|
+
BACK_OFF_MULTIPLIER: 100,
|
109
|
+
};
|
110
|
+
let actual = SocketIOCall.roomLiveTupleModel[room];
|
111
|
+
if (!actual || rebuild) {
|
112
|
+
//console.log(`Creating room model builder... ${room}`);
|
113
|
+
actual = {
|
114
|
+
model: {},
|
115
|
+
};
|
116
|
+
const builder = MyTuples.getBuilder(builderConfig);
|
117
|
+
builder.setProcesor((changes) => {
|
118
|
+
changes.orig = "server";
|
119
|
+
SocketIOCall.io.to(room).emit("clientChange", changes);
|
120
|
+
});
|
121
|
+
builder.build(actual.model);
|
122
|
+
builder.end();
|
123
|
+
actual.statusEmitter = new EventEmitter();
|
124
|
+
builder.addActivityListener((status) => {
|
125
|
+
actual.statusEmitter.emit("status", status);
|
126
|
+
});
|
127
|
+
actual.builder = builder;
|
128
|
+
SocketIOCall.roomLiveTupleModel[room] = actual;
|
129
|
+
}
|
130
|
+
return actual;
|
131
|
+
}
|
132
|
+
|
133
|
+
static async registerSocket(socket) {
|
134
|
+
console.log("registerSocket...");
|
135
|
+
SocketIOCall.socketIdToSocket[socket.id] = socket;
|
136
|
+
const headers = SocketIOCall.getCustomHeaders(socket);
|
137
|
+
const room = headers.room;
|
138
|
+
const release = await SocketIOCall.mutex.acquire();
|
139
|
+
let currentList = SocketIOCall.mapSockets[room];
|
140
|
+
SocketIOCall.socketToRoom[socket.id] = room;
|
141
|
+
if (!currentList) {
|
142
|
+
currentList = [socket.id];
|
143
|
+
SocketIOCall.mapSockets[room] = currentList;
|
144
|
+
} else {
|
145
|
+
if (currentList.indexOf(socket.id) < 0) {
|
146
|
+
currentList.push(socket.id);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
// Assure room existence
|
150
|
+
if (!(room in SocketIOCall.socketRoomUUIDMap)) {
|
151
|
+
SocketIOCall.socketRoomUUIDMap[room] = {};
|
152
|
+
}
|
153
|
+
const myUUID = headers.uuid;
|
154
|
+
if (typeof myUUID == "string" && myUUID !== "null") {
|
155
|
+
SocketIOCall.socketRoomUUIDMap[room][myUUID] = socket.id;
|
156
|
+
}
|
157
|
+
console.log(JSON.stringify(SocketIOCall.socketRoomUUIDMap, null, 4));
|
158
|
+
release();
|
159
|
+
console.log(`${socket.id} joins ${headers.room}`);
|
160
|
+
socket.join(headers.room);
|
161
|
+
SocketIOCall.getRoomLiveTupleModel(room);
|
162
|
+
}
|
163
|
+
|
164
|
+
static getSocketIdFromRoomAndUUID(room, uuid) {
|
165
|
+
const roomMap = SocketIOCall.socketRoomUUIDMap[room];
|
166
|
+
if (!roomMap) {
|
167
|
+
return null;
|
168
|
+
}
|
169
|
+
return roomMap[uuid];
|
170
|
+
}
|
171
|
+
|
172
|
+
static async unregisterSocket(socket) {
|
173
|
+
delete SocketIOCall.socketIdToSocket[socket.id];
|
174
|
+
const headers = SocketIOCall.getCustomHeaders(socket);
|
175
|
+
const room = headers.room;
|
176
|
+
const release = await SocketIOCall.mutex.acquire();
|
177
|
+
let currentList = SocketIOCall.mapSockets[room];
|
178
|
+
if (currentList) {
|
179
|
+
currentList = currentList.filter((elem) => {
|
180
|
+
return elem != socket.id;
|
181
|
+
});
|
182
|
+
SocketIOCall.mapSockets[room] = currentList;
|
183
|
+
}
|
184
|
+
if (room in SocketIOCall.socketRoomUUIDMap) {
|
185
|
+
if (headers.uuid in SocketIOCall.socketRoomUUIDMap[room]) {
|
186
|
+
delete SocketIOCall.socketRoomUUIDMap[room][headers.uuid];
|
187
|
+
}
|
188
|
+
if (Object.keys(SocketIOCall.socketRoomUUIDMap[room]).length == 0) {
|
189
|
+
delete SocketIOCall.socketRoomUUIDMap[room];
|
190
|
+
}
|
191
|
+
console.log(JSON.stringify(SocketIOCall.socketRoomUUIDMap, null, 4));
|
192
|
+
}
|
193
|
+
release();
|
194
|
+
}
|
195
|
+
|
196
|
+
static getCustomHeaders(socket) {
|
197
|
+
const headersKey = ["room", "uuid"];
|
198
|
+
const headers = socket.handshake.headers;
|
199
|
+
const response = {};
|
200
|
+
headersKey.forEach((key) => {
|
201
|
+
response[key] = headers[key];
|
202
|
+
});
|
203
|
+
return response;
|
204
|
+
}
|
205
|
+
|
206
|
+
static async checkAndNotifyRoomPeers(socket) {
|
207
|
+
await SocketIOCall.registerSocket(socket);
|
208
|
+
// Le digo a los que están en el room quién llegó
|
209
|
+
const headers = SocketIOCall.getCustomHeaders(socket);
|
210
|
+
SocketIOCall.io.to(headers.room).emit("updateUserList", {
|
211
|
+
socketIds: SocketIOCall.mapSockets[headers.room]
|
212
|
+
});
|
213
|
+
}
|
214
|
+
|
215
|
+
static async sendCurrentModel(socket) {
|
216
|
+
//console.log(`Emmit to ${socket.id} model!`);
|
217
|
+
const headers = SocketIOCall.getCustomHeaders(socket);
|
218
|
+
const room = headers.room;
|
219
|
+
const dataRoom = SocketIOCall.getRoomLiveTupleModel(room);
|
220
|
+
// Le notifico el modelo actual
|
221
|
+
SocketIOCall.io.to(socket.id).emit("setModel", {
|
222
|
+
model: dataRoom.model
|
223
|
+
});
|
224
|
+
}
|
225
|
+
|
226
|
+
static getRoomFromSocket(socket) {
|
227
|
+
return SocketIOCall.socketToRoom[socket.id]
|
228
|
+
}
|
229
|
+
|
230
|
+
static async connect(socket) {
|
231
|
+
SocketIOCall.echoLog(`connect... ${socket.id}`);
|
232
|
+
|
233
|
+
await SocketIOCall.checkAndNotifyRoomPeers(socket);
|
234
|
+
|
235
|
+
socket.on("callUser", (payload) => {
|
236
|
+
SocketIOCall.echoLog(`${socket.id} sends callUser`);
|
237
|
+
new CallUserProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
238
|
+
});
|
239
|
+
socket.on("makeAnswer", (payload) => {
|
240
|
+
SocketIOCall.echoLog(`${socket.id} sends makeAnswer`);
|
241
|
+
new MakeAnswerProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
242
|
+
});
|
243
|
+
socket.on("onicecandidate", (payload) => {
|
244
|
+
SocketIOCall.echoLog(`${socket.id} sends onicecandidate`);
|
245
|
+
new OnIceCandidateProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
246
|
+
});
|
247
|
+
socket.on("disconnect", (payload) => {
|
248
|
+
SocketIOCall.echoLog(`${socket.id} sends disconnect with ${JSON.stringify(payload)}`);
|
249
|
+
new DisconnectProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
250
|
+
SocketIOCall.disconnect(socket);
|
251
|
+
});
|
252
|
+
/*
|
253
|
+
socket.on("reconnect", (payload) => {
|
254
|
+
SocketIOCall.echoLog(`${socket.id} sends reconnect with ${JSON.stringify(payload)}`);
|
255
|
+
SocketIOCall.sendCurrentModel();
|
256
|
+
});*/
|
257
|
+
socket.on("askRoom", (payload) => {
|
258
|
+
SocketIOCall.echoLog(`${socket.id} sends askRoom with ${JSON.stringify(payload)}`);
|
259
|
+
new AskRoomProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
260
|
+
});
|
261
|
+
socket.on("clientChange", (payload) => {
|
262
|
+
new ClientChangeProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
263
|
+
});
|
264
|
+
socket.on("getModel", (payload) => {
|
265
|
+
new GetModelProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
266
|
+
});
|
267
|
+
socket.on("loadFlowchart", (payload) => {
|
268
|
+
SocketIOCall.echoLog(`${socket.id} sends loadFlowchart with ${JSON.stringify(payload)}`);
|
269
|
+
new LoadFlowChartProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
270
|
+
});
|
271
|
+
socket.on("startFlowChart", (payload) => {
|
272
|
+
SocketIOCall.echoLog(`${socket.id} sends startFlowChart with ${JSON.stringify(payload)}`);
|
273
|
+
new StartFlowChartProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
274
|
+
});
|
275
|
+
socket.on("stopFlowChart", (payload) => {
|
276
|
+
SocketIOCall.echoLog(`${socket.id} sends stopFlowChart with ${JSON.stringify(payload)}`);
|
277
|
+
new StopFlowChartProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
278
|
+
});
|
279
|
+
socket.on("pauseFlowChart", (payload) => {
|
280
|
+
SocketIOCall.echoLog(`${socket.id} sends pauseFlowChart with ${JSON.stringify(payload)}`);
|
281
|
+
new PauseFlowChartProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
282
|
+
});
|
283
|
+
socket.on("destroyModel", (payload) => {
|
284
|
+
SocketIOCall.echoLog(`${socket.id} sends destroyModel with ${JSON.stringify(payload)}`);
|
285
|
+
new DestroyModelProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
286
|
+
});
|
287
|
+
socket.on("askiceservers", (payload) => {
|
288
|
+
SocketIOCall.echoLog(`${socket.id} sends askiceservers with ${JSON.stringify(payload)}`);
|
289
|
+
new AskIceServersProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
290
|
+
});
|
291
|
+
socket.on("registerSource", (payload) => {
|
292
|
+
SocketIOCall.echoLog(`${socket.id} sends registerSource with ${JSON.stringify(payload)}`);
|
293
|
+
new RegisterSourceProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
294
|
+
});
|
295
|
+
socket.on("registerProcessor", (payload) => {
|
296
|
+
SocketIOCall.echoLog(`${socket.id} sends registerProcessor with ${JSON.stringify(payload)}`);
|
297
|
+
new RegisterProcessorProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
298
|
+
});
|
299
|
+
|
300
|
+
socket.on("checkSrcResponse", (payload) => {
|
301
|
+
//SocketIOCall.echoLog(`${socket.id} sends checkSrcResponse with ${JSON.stringify(payload)}`);
|
302
|
+
new CheckSrcResponseProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
303
|
+
});
|
304
|
+
socket.on("readSrcResponse", (payload) => {
|
305
|
+
//SocketIOCall.echoLog(`${socket.id} sends readSrcResponse with ${JSON.stringify(payload)}`);
|
306
|
+
new ReadSrcResponseProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
307
|
+
});
|
308
|
+
socket.on("processResponse", (payload) => {
|
309
|
+
//SocketIOCall.echoLog(`${socket.id} sends processResponse with ${JSON.stringify(payload)}`);
|
310
|
+
new ProcessResponseProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
311
|
+
});
|
312
|
+
socket.on("subscribeme", (payload) => {
|
313
|
+
SocketIOCall.echoLog(`${socket.id} sends subscribeme with ${JSON.stringify(payload)}`);
|
314
|
+
new SubscribemeProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
315
|
+
});
|
316
|
+
socket.on("sendChat", (payload) => {
|
317
|
+
//SocketIOCall.echoLog(`${socket.id} sends sendChat with ${JSON.stringify(payload)}`);
|
318
|
+
new SendChatProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
319
|
+
});
|
320
|
+
socket.on("updateMyInformation", (payload) => {
|
321
|
+
//SocketIOCall.echoLog(`${socket.id} sends updateMyInformation with ${JSON.stringify(payload)}`);
|
322
|
+
new UpdateMyInformationProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
323
|
+
});
|
324
|
+
socket.on("chatSetSawProcessor", (payload) => {
|
325
|
+
//SocketIOCall.echoLog(`${socket.id} sends chatSetSawProcessor with ${JSON.stringify(payload)}`);
|
326
|
+
new ChatSetSawProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
327
|
+
});
|
328
|
+
socket.on("openVideoChat", (payload) => {
|
329
|
+
//SocketIOCall.echoLog(`${socket.id} sends openVideoChat with ${JSON.stringify(payload)}`);
|
330
|
+
new OpenVideoChatProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
331
|
+
});
|
332
|
+
socket.on("closeVideoChat", (payload) => {
|
333
|
+
//SocketIOCall.echoLog(`${socket.id} sends closeVideoChat with ${JSON.stringify(payload)}`);
|
334
|
+
new CloseVideoChatProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
335
|
+
});
|
336
|
+
socket.on("includeOtherPeers", (payload) => {
|
337
|
+
//SocketIOCall.echoLog(`${socket.id} sends includeOtherPeers with ${JSON.stringify(payload)}`);
|
338
|
+
new IncludeOtherPeersProcessor(SocketIOCall, SocketIOCall.io, socket).execute(payload);
|
339
|
+
});
|
340
|
+
}
|
341
|
+
|
342
|
+
static async disconnect(socket) {
|
343
|
+
const headers = SocketIOCall.getCustomHeaders(socket);
|
344
|
+
// Lo saco de la lista en memoria
|
345
|
+
await SocketIOCall.unregisterSocket(socket);
|
346
|
+
SocketIOCall.io.to(headers.room).emit("removeUser", {
|
347
|
+
socketId: socket.id
|
348
|
+
});
|
349
|
+
}
|
350
|
+
|
351
|
+
static handle(io) {
|
352
|
+
SocketIOCall.io = io;
|
353
|
+
SocketIOCall.getFlowChartExec("processors");
|
354
|
+
io.on("connection", SocketIOCall.connect);
|
355
|
+
return () => { }
|
356
|
+
}
|
357
|
+
|
358
|
+
static async processorResponse(req, res, next) {
|
359
|
+
const buffer = req.body;
|
360
|
+
const decoded = decode(buffer);
|
361
|
+
await new ProcessResponseProcessor(SocketIOCall, SocketIOCall.io, null).execute(decoded);
|
362
|
+
res.status(200).send({
|
363
|
+
status: "ok",
|
364
|
+
});
|
365
|
+
}
|
366
|
+
|
367
|
+
static async loadFlowChart(req, res, next) {
|
368
|
+
const buffer = req.body;
|
369
|
+
await new LoadFlowChartProcessor(SocketIOCall, SocketIOCall.io, null).execute(buffer);
|
370
|
+
if (buffer.autoStart === true) {
|
371
|
+
new StartFlowChartProcessor(SocketIOCall, SocketIOCall.io, null).execute(buffer);
|
372
|
+
}
|
373
|
+
res.status(200).send({
|
374
|
+
status: "ok",
|
375
|
+
});
|
376
|
+
}
|
377
|
+
|
378
|
+
static async processorProcess(req, res, next) {
|
379
|
+
console.log(`processorProcess...`);
|
380
|
+
const buffer = req.body;
|
381
|
+
|
382
|
+
let decoded = buffer;
|
383
|
+
if (/\/processor_process$/.exec(req.path) != null) {
|
384
|
+
decoded = decode(buffer);
|
385
|
+
}
|
386
|
+
//console.log(decoded);
|
387
|
+
const { processorMethod, room, channel } = decoded;
|
388
|
+
const parts = /(^[^\d\.]+)(\d*)\.(.*)$/.exec(processorMethod);
|
389
|
+
if (!parts) {
|
390
|
+
throw Error(`processorMethod ${processorMethod} does not matches /(^[^\d\.]+)(\d*)\.(.*)$/`);
|
391
|
+
}
|
392
|
+
const processor = parts[1];
|
393
|
+
const instance = parts[2];
|
394
|
+
decoded['method'] = parts[3];
|
395
|
+
|
396
|
+
// Get socket destiny if channel is websocket
|
397
|
+
let socketId = null;
|
398
|
+
let postUrl = null;
|
399
|
+
const processorsModel = SocketIOCall.getRoomLiveTupleModel("processors");
|
400
|
+
if (channel == "websocket") {
|
401
|
+
const path = `model.data.state.processors.${processor}.socket`;
|
402
|
+
socketId = SimpleObj.getValue(processorsModel, path, null);
|
403
|
+
if (!socketId) {
|
404
|
+
throw Error(`Not processor with valid socketId for ${processor}`);
|
405
|
+
}
|
406
|
+
} else if (channel == "post") {
|
407
|
+
const path = `model.data.state.processors.${processor}.postUrl`;
|
408
|
+
postUrl = SimpleObj.getValue(processorsModel, path, null);
|
409
|
+
if (!postUrl) {
|
410
|
+
throw Error(`Not processor with postUrl for ${processor}`);
|
411
|
+
}
|
412
|
+
}
|
413
|
+
|
414
|
+
// Complete data if room provided, room is optional
|
415
|
+
if (room) {
|
416
|
+
const allModel = SocketIOCall.getRoomLiveTupleModel(room);
|
417
|
+
const pathData = `model.data.state.processors.${processor}.${instance}`;
|
418
|
+
const temp = SimpleObj.getValue(allModel, pathData, null);
|
419
|
+
if (decoded['data']) {
|
420
|
+
if (temp) {
|
421
|
+
Object.assign(decoded['data'], temp);
|
422
|
+
}
|
423
|
+
} else {
|
424
|
+
decoded['data'] = temp;
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
const messageUID = IdGen.num2ord(new Date().getTime());
|
429
|
+
|
430
|
+
if (!decoded['id']) {
|
431
|
+
decoded['id'] = `${processorMethod}-${messageUID}`;
|
432
|
+
}
|
433
|
+
|
434
|
+
let promesa = Promise.resolve({});
|
435
|
+
|
436
|
+
if (channel == "websocket") {
|
437
|
+
promesa = new Promise((resolve, reject) => {
|
438
|
+
const socket = SocketIOCall.socketIdToSocket[socketId];
|
439
|
+
if (!socket) {
|
440
|
+
reject(`No socket with id ${socketId} for processor ${processor}`);
|
441
|
+
}
|
442
|
+
const listener = (valor) => {
|
443
|
+
if (valor.id == decoded['id']) {
|
444
|
+
socket.off("processResponse", listener);
|
445
|
+
resolve(valor);
|
446
|
+
}
|
447
|
+
};
|
448
|
+
socket.on("processResponse", listener);
|
449
|
+
});
|
450
|
+
SocketIOCall.io.to(socketId).emit("process", decoded);
|
451
|
+
} else if (channel == "post") {
|
452
|
+
const options = {
|
453
|
+
maxBodyLength: Infinity,
|
454
|
+
maxContentLength: Infinity,
|
455
|
+
headers: { "Content-Type": "application/octet-stream" }
|
456
|
+
};
|
457
|
+
const encoded = encode(decoded);
|
458
|
+
const buffer = Buffer.from(encoded);
|
459
|
+
console.log(`POST to ${postUrl}...`);
|
460
|
+
const temp = await axios.post(`${postUrl}/syncprocess`, buffer, options);
|
461
|
+
console.log(`POST to ${postUrl}... OK!`);
|
462
|
+
promesa = Promise.resolve({ data: temp.data });
|
463
|
+
}
|
464
|
+
|
465
|
+
|
466
|
+
const respuesta = await promesa;
|
467
|
+
res.status(200).send({
|
468
|
+
status: "ok",
|
469
|
+
response: respuesta
|
470
|
+
});
|
471
|
+
}
|
472
|
+
|
473
|
+
static async introspect(req, res, next) {
|
474
|
+
const body = req.body;
|
475
|
+
const rooms = Object.keys(SocketIOCall.roomLiveTupleModel);
|
476
|
+
const path = `model.data.scope.progress`;
|
477
|
+
const data = rooms.map((room) => {
|
478
|
+
const modelo = SocketIOCall.roomLiveTupleModel[room];
|
479
|
+
const progress = SimpleObj.getValue(modelo, path, null);
|
480
|
+
return {
|
481
|
+
room: room,
|
482
|
+
percentage: progress
|
483
|
+
};
|
484
|
+
}).filter((data) => {
|
485
|
+
return typeof data.percentage == "number" && ["processors", "public"].indexOf(data.room) < 0;
|
486
|
+
});
|
487
|
+
|
488
|
+
const response = {
|
489
|
+
status: "ok",
|
490
|
+
response: data
|
491
|
+
};
|
492
|
+
res.status(200).send(response);
|
493
|
+
}
|
494
|
+
}
|
package/srv/TupleSrv.mjs
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
import { MyStore } from "./common/MyStore.mjs";
|
2
|
+
import { MalaPeticionException, NoExisteException } from "./MyError.mjs";
|
3
|
+
import { General } from "./common/General.mjs";
|
4
|
+
import MyDatesBack from "@ejfdelgado/ejflab-common/src/MyDatesBack.mjs";
|
5
|
+
import { KeysSrv } from "./KeysSrv.mjs";
|
6
|
+
|
7
|
+
const TUPLE_TYPE = "tuple";
|
8
|
+
const TUPLE_TEMP_TYPE = "tuple-temp";
|
9
|
+
const MAX_READ_SIZE = 60;
|
10
|
+
|
11
|
+
/*
|
12
|
+
{
|
13
|
+
id: "${pageId}:${actual.k}",
|
14
|
+
v: { },
|
15
|
+
act: YYYYMMddHHmmSSmmm,
|
16
|
+
cre: YYYYMMddHHmmSSmmm
|
17
|
+
}
|
18
|
+
*/
|
19
|
+
export class TupleSrv {
|
20
|
+
|
21
|
+
static async deleteAll(req, res, next) {
|
22
|
+
const pageId = req.params['pageId'];
|
23
|
+
const { max, offset } = General.readMaxOffset(req, MAX_READ_SIZE);
|
24
|
+
if (!pageId) {
|
25
|
+
throw new MalaPeticionException("Falta el id");
|
26
|
+
}
|
27
|
+
// Se debe validar el permiso de borrado
|
28
|
+
// TODO
|
29
|
+
|
30
|
+
// Se debe realizar la lectura como tal
|
31
|
+
const where = [
|
32
|
+
{ key: "pg", oper: "==", value: pageId },
|
33
|
+
];
|
34
|
+
const response = await MyStore.paginate(TUPLE_TYPE, [{ name: "act", dir: 'asc' }], offset, max, where);
|
35
|
+
|
36
|
+
const batch = MyStore.getBatch();
|
37
|
+
for (let i = 0; i < response.length; i++) {
|
38
|
+
const actual = response[i];
|
39
|
+
MyStore.deleteById(TUPLE_TYPE, actual.id, batch);
|
40
|
+
}
|
41
|
+
// Commit the batch
|
42
|
+
await batch.commit();
|
43
|
+
res.status(200).send({ count: response.length });
|
44
|
+
}
|
45
|
+
|
46
|
+
static async read(req, res, next) {
|
47
|
+
//const AHORA = MyDatesBack.getDayAsContinuosNumberHmmSSmmm(new Date());
|
48
|
+
const AHORA = new Date().getTime();
|
49
|
+
// Se debe leer el parametro id, offset, max
|
50
|
+
const pageId = req.params['pageId'];
|
51
|
+
const { max, offset } = General.readMaxOffset(req, MAX_READ_SIZE);
|
52
|
+
|
53
|
+
if (!pageId) {
|
54
|
+
throw new MalaPeticionException("Falta el id");
|
55
|
+
}
|
56
|
+
|
57
|
+
// Se debe validar el permiso de lectura
|
58
|
+
// TODO
|
59
|
+
|
60
|
+
// Se debe realizar la lectura como tal
|
61
|
+
const where = [
|
62
|
+
{ key: "pg", oper: "==", value: pageId },
|
63
|
+
];
|
64
|
+
const response = await MyStore.paginate(TUPLE_TYPE, [{ name: "act", dir: 'asc' }], offset, max, where);
|
65
|
+
for (let i = 0; i < response.length; i++) {
|
66
|
+
const actual = response[i];
|
67
|
+
}
|
68
|
+
res.status(200).send({
|
69
|
+
t: AHORA,
|
70
|
+
payload: response,
|
71
|
+
});
|
72
|
+
}
|
73
|
+
static async save(req, res, next) {
|
74
|
+
const token = res.locals.token;
|
75
|
+
//const AHORA = MyDatesBack.getDayAsContinuosNumberHmmSSmmm(new Date());
|
76
|
+
const AHORA = new Date().getTime();
|
77
|
+
// Se debe leer el parametro id y body
|
78
|
+
const pageId = req.params['pageId'];
|
79
|
+
const live = General.readParam(req, "live");
|
80
|
+
const secret = General.readParam(req, "secret");
|
81
|
+
const body = General.readParam(req, "body", undefined);
|
82
|
+
|
83
|
+
if (!pageId) {
|
84
|
+
throw new MalaPeticionException("Falta el id");
|
85
|
+
}
|
86
|
+
if (body === undefined) {
|
87
|
+
throw new MalaPeticionException("Falta el body");
|
88
|
+
}
|
89
|
+
|
90
|
+
// Se debe validar el permiso de esritura
|
91
|
+
// TODO
|
92
|
+
|
93
|
+
const batch = MyStore.getBatch();
|
94
|
+
// Se deben escribir los borrados
|
95
|
+
const borrados = body["-"];
|
96
|
+
for (let i = 0; i < borrados.length; i++) {
|
97
|
+
const actual = borrados[i];
|
98
|
+
MyStore.deleteById(TUPLE_TYPE, `${pageId}:${actual.k}`, batch);
|
99
|
+
}
|
100
|
+
// Se deben escribir las adiciones
|
101
|
+
const adiciones = body["+"];
|
102
|
+
for (let i = 0; i < adiciones.length; i++) {
|
103
|
+
const actual = adiciones[i];
|
104
|
+
const payload = {
|
105
|
+
v: actual.v,
|
106
|
+
act: AHORA,
|
107
|
+
cre: AHORA,
|
108
|
+
pg: pageId,
|
109
|
+
k: actual.k,
|
110
|
+
};
|
111
|
+
MyStore.createById(TUPLE_TYPE, `${pageId}:${actual.k}`, payload, batch);
|
112
|
+
}
|
113
|
+
|
114
|
+
// Se deben escribir las actualizaciones
|
115
|
+
const actualizaciones = body["*"];
|
116
|
+
for (let i = 0; i < actualizaciones.length; i++) {
|
117
|
+
const actual = actualizaciones[i];
|
118
|
+
const payload = {
|
119
|
+
v: actual.v,
|
120
|
+
act: AHORA,
|
121
|
+
};
|
122
|
+
MyStore.updateOrCreateById(TUPLE_TYPE, `${pageId}:${actual.k}`, payload, batch);
|
123
|
+
}
|
124
|
+
|
125
|
+
// Place the live changes
|
126
|
+
if (live == "1") {
|
127
|
+
let nuevo = {};
|
128
|
+
if (secret == "1") {
|
129
|
+
const cifrado = await KeysSrv.cifrar(body, pageId);
|
130
|
+
nuevo = { pg: pageId, cifrado, who: token.uid, t: AHORA };
|
131
|
+
} else {
|
132
|
+
nuevo = { pg: pageId, body, who: token.uid, t: AHORA };
|
133
|
+
}
|
134
|
+
MyStore.createById(TUPLE_TEMP_TYPE, `${pageId}:${token.uid}`, nuevo, batch);
|
135
|
+
}
|
136
|
+
|
137
|
+
// Commit the batch
|
138
|
+
await batch.commit();
|
139
|
+
res.status(204).send();
|
140
|
+
}
|
141
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import fs from "fs";
|
2
|
+
import { GenericProcessor } from "./GenericProcessor.mjs";
|
3
|
+
|
4
|
+
export class AskIceServersProcessor extends GenericProcessor {
|
5
|
+
constructor(context, io, socket) {
|
6
|
+
super(context, io, socket);
|
7
|
+
}
|
8
|
+
execute(args) {
|
9
|
+
// Reads from credentilas file...
|
10
|
+
const text = fs.readFileSync(`./credentials/webrtcconfig.json`, 'utf8');
|
11
|
+
const parsed = JSON.parse(text);
|
12
|
+
this.io.to(this.socket.id).emit("oniceservers", parsed);
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { GenericProcessor } from "./GenericProcessor.mjs";
|
2
|
+
|
3
|
+
|
4
|
+
export class AskRoomProcessor extends GenericProcessor {
|
5
|
+
constructor(context, io, socket) {
|
6
|
+
super(context, io, socket);
|
7
|
+
}
|
8
|
+
execute(args) {
|
9
|
+
const headers = this.context.getCustomHeaders(this.socket);
|
10
|
+
this.io.to(this.socket.id).emit("updateUserList", {
|
11
|
+
socketIds: this.context.mapSockets[headers.room]
|
12
|
+
});
|
13
|
+
this.context.sendCurrentModel(this.socket);
|
14
|
+
}
|
15
|
+
}
|