@ejfdelgado/ejflab-back 1.34.1 → 1.34.3

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.1",
3
+ "version": "1.34.3",
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,9 +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
+ console.log(`DisconnectProcessor "${socketId}"`);
58
59
  // Busco los sources
59
- const room = this.context.getRoomFromSocket(this.socket);
60
+ const room = this.context.getRoomFromSocket({ id: socketId });
60
61
  const instance = await this.context.getFlowChartExec(room);
61
62
  const roomData = this.context.getRoomLiveTupleModel(room);
62
63
  if (instance) {
@@ -6,7 +6,7 @@ export class RegisterSessionProcessor extends GenericProcessor {
6
6
  super(context, io, socket);
7
7
  }
8
8
  execute(args) {
9
- //console.log(`RegisterSessionProcessor... ${JSON.stringify(args)}`);
9
+ console.log(`RegisterSessionProcessor... ${JSON.stringify(args)}`);
10
10
  const sessionsData = this.context.sessionsByProvider;
11
11
  const { socketId, sessionId, provider } = args;
12
12
  if (!(provider in sessionsData)) {
@@ -32,7 +32,7 @@ export class RegisterSessionProcessor extends GenericProcessor {
32
32
  userSessions.sessions[sessionId] = socketId;
33
33
  }
34
34
  }
35
- //console.log(JSON.stringify(sessionsData, null, 4));
35
+ console.log(JSON.stringify(sessionsData, null, 4));
36
36
  // Notify all sockets the amount of sessions
37
37
  const allSockets = Object.keys(sessionsData[provider].sockets);
38
38
  const count = allSockets.length;
@@ -6,7 +6,7 @@ export class UnregisterSessionProcessor extends GenericProcessor {
6
6
  super(context, io, socket);
7
7
  }
8
8
  execute(args) {
9
- //console.log(`UnregisterSessionProcessor... ${JSON.stringify(args)}`);
9
+ console.log(`UnregisterSessionProcessor... ${JSON.stringify(args)}`);
10
10
  const sessionsData = this.context.sessionsByProvider;
11
11
  const { socketId, provider } = args;
12
12
  if ((provider in sessionsData)) {
@@ -19,7 +19,7 @@ export class UnregisterSessionProcessor extends GenericProcessor {
19
19
  delete sockets[socketId];
20
20
  }
21
21
  }
22
- //console.log(JSON.stringify(sessionsData, null, 4));
22
+ console.log(JSON.stringify(sessionsData, null, 4));
23
23
  const allSockets = Object.keys(sessionsData[provider].sockets);
24
24
  const count = allSockets.length;
25
25
  for (let i = 0; i < allSockets.length; i++) {