@ejfdelgado/ejflab-back 1.34.2 → 1.34.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.34.2",
3
+ "version": "1.34.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -54,6 +54,41 @@ export class SocketIOCall {
54
54
  static internalBus = new EventEmitter();
55
55
  static sessionsByProvider = {};
56
56
 
57
+ static {
58
+ // check dead sockets
59
+ const cleanDeadSockets = () => {
60
+ for (let providerId in SocketIOCall.sessionsByProvider) {
61
+ const provider = SocketIOCall.sessionsByProvider[providerId];
62
+ const { sockets, sessions } = provider;
63
+ // Check the sockets
64
+ if (sockets) {
65
+ const socketsIds = Object.keys(sockets);
66
+ if (socketsIds.length > 0) {
67
+ const deadSockets = socketsIds.map((socketId) => {
68
+ const connected1 = !!(SocketIOCall.io.of("/").sockets.get(socketId));
69
+ const connected2 = SocketIOCall.io.of("/").adapter.sids.has(socketId);
70
+ return { connected1, connected2, socketId }
71
+ }).filter((status) => {
72
+ return !status.connected1 || !status.connected2;
73
+ });
74
+ //
75
+ deadSockets.forEach((socketMap) => {
76
+ const socketId = socketMap.socketId;
77
+ console.log(`cleanDeadSockets: Forcing disconnect "${socketId}"...`);
78
+ SocketIOCall.internalBus.emit("disconnect", {
79
+ socketId: socketId,
80
+ });
81
+ });
82
+ }
83
+ }
84
+ }
85
+ };
86
+
87
+ setInterval(() => {
88
+ cleanDeadSockets();
89
+ }, 4000);
90
+ }
91
+
57
92
  static echoLog(message) {
58
93
  if (process.env.ENV != "pro") {
59
94
  console.log(message);
@@ -54,10 +54,10 @@ export class DisconnectProcessor extends GenericProcessor {
54
54
  }
55
55
 
56
56
  async execute(args) {
57
- const socketId = this.socket.id;
57
+ const socketId = typeof args.socketId == "string" ? args.socketId : this.socket.id;
58
58
  console.log(`DisconnectProcessor "${socketId}"`);
59
59
  // Busco los sources
60
- const room = this.context.getRoomFromSocket(this.socket);
60
+ const room = this.context.getRoomFromSocket({ id: socketId });
61
61
  const instance = await this.context.getFlowChartExec(room);
62
62
  const roomData = this.context.getRoomLiveTupleModel(room);
63
63
  if (instance) {
@@ -18,6 +18,18 @@ export class UnregisterSessionProcessor extends GenericProcessor {
18
18
  delete sessions[oldSession];
19
19
  delete sockets[socketId];
20
20
  }
21
+ } else {
22
+ // Search in all providers the socketId
23
+ for (let providerTemp in sessionsData) {
24
+ const userSessions = sessionsData[providerTemp];
25
+ const { sockets, sessions } = userSessions;
26
+ // Get session by socketId
27
+ const oldSession = sockets[socketId];
28
+ if (oldSession) {
29
+ delete sessions[oldSession];
30
+ delete sockets[socketId];
31
+ }
32
+ }
21
33
  }
22
34
  console.log(JSON.stringify(sessionsData, null, 4));
23
35
  const allSockets = Object.keys(sessionsData[provider].sockets);