@ejfdelgado/ejflab-back 1.34.0 → 1.34.1

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.0",
3
+ "version": "1.34.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -29,7 +29,7 @@ export class DisconnectProcessor extends GenericProcessor {
29
29
  //console.log(`Register session end to ${user_id}`);
30
30
  this.context.internalBus.emit("unregisterSession", {
31
31
  provider: user_id,
32
- room: room,
32
+ socketId: socketId,
33
33
  });
34
34
  }
35
35
  }
@@ -6,8 +6,39 @@ export class RegisterSessionProcessor extends GenericProcessor {
6
6
  super(context, io, socket);
7
7
  }
8
8
  execute(args) {
9
- console.log(`RegisterSessionProcessor... to ${args.to}`);
10
- const sessions = this.context.sessionsByProvider;
11
- console.log(JSON.stringify(sessions, null, 4));
9
+ //console.log(`RegisterSessionProcessor... ${JSON.stringify(args)}`);
10
+ const sessionsData = this.context.sessionsByProvider;
11
+ const { socketId, sessionId, provider } = args;
12
+ if (!(provider in sessionsData)) {
13
+ const userSessions = {
14
+ sockets: {},
15
+ sessions: {},
16
+ };
17
+ sessionsData[provider] = userSessions;
18
+ userSessions.sockets[socketId] = sessionId;
19
+ userSessions.sessions[sessionId] = socketId;
20
+ } else {
21
+ const userSessions = sessionsData[provider];
22
+ const { sockets, sessions } = userSessions;
23
+ if (sessionId in sessions) {
24
+ // If it is an existent session, then switch the socketId
25
+ const oldSocketId = sessions[sessionId];
26
+ sessions[sessionId] = socketId;
27
+ delete sockets[oldSocketId];
28
+ sockets[socketId] = sessionId;
29
+ } else {
30
+ // Register the new session
31
+ userSessions.sockets[socketId] = sessionId;
32
+ userSessions.sessions[sessionId] = socketId;
33
+ }
34
+ }
35
+ //console.log(JSON.stringify(sessionsData, null, 4));
36
+ // Notify all sockets the amount of sessions
37
+ const allSockets = Object.keys(sessionsData[provider].sockets);
38
+ const count = allSockets.length;
39
+ for (let i = 0; i < allSockets.length; i++) {
40
+ const socketIdOther = allSockets[i];
41
+ this.io.to(socketIdOther).emit("sessionCount", { count });
42
+ }
12
43
  }
13
44
  }
@@ -6,8 +6,25 @@ export class UnregisterSessionProcessor extends GenericProcessor {
6
6
  super(context, io, socket);
7
7
  }
8
8
  execute(args) {
9
- console.log(`UnregisterSessionProcessor... to ${args.to}`);
10
- const sessions = this.context.sessionsByProvider;
11
- console.log(JSON.stringify(sessions, null, 4));
9
+ //console.log(`UnregisterSessionProcessor... ${JSON.stringify(args)}`);
10
+ const sessionsData = this.context.sessionsByProvider;
11
+ const { socketId, provider } = args;
12
+ if ((provider in sessionsData)) {
13
+ const userSessions = sessionsData[provider];
14
+ const { sockets, sessions } = userSessions;
15
+ // Get session by socketId
16
+ const oldSession = sockets[socketId];
17
+ if (oldSession) {
18
+ delete sessions[oldSession];
19
+ delete sockets[socketId];
20
+ }
21
+ }
22
+ //console.log(JSON.stringify(sessionsData, null, 4));
23
+ const allSockets = Object.keys(sessionsData[provider].sockets);
24
+ const count = allSockets.length;
25
+ for (let i = 0; i < allSockets.length; i++) {
26
+ const socketIdOther = allSockets[i];
27
+ this.io.to(socketIdOther).emit("sessionCount", { count });
28
+ }
12
29
  }
13
30
  }