@ejfdelgado/ejflab-back 1.33.1 → 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.33.1",
3
+ "version": "1.34.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -34,6 +34,8 @@ import { PostgresSrv } from "./PostgresSrv.mjs";
34
34
  import { OpenVideoChatProcessor } from "./callprocessors/OpenVideoChatProcessor.mjs";
35
35
  import { CloseVideoChatProcessor } from "./callprocessors/CloseVideoChatProcessor.mjs";
36
36
  import { IncludeOtherPeersProcessor } from "./callprocessors/IncludeOtherPeersProcessor.mjs";
37
+ import { RegisterSessionProcessor } from "./callprocessors/RegisterSessionProcessor.mjs";
38
+ import { UnregisterSessionProcessor } from "./callprocessors/UnregisterSessionProcessor.mjs";
37
39
 
38
40
  import stream from "stream";
39
41
 
@@ -50,6 +52,7 @@ export class SocketIOCall {
50
52
  static socketToImage = {};
51
53
  static hookProcessors = {};
52
54
  static internalBus = new EventEmitter();
55
+ static sessionsByProvider = {};
53
56
 
54
57
  static echoLog(message) {
55
58
  if (process.env.ENV != "pro") {
@@ -374,6 +377,14 @@ export class SocketIOCall {
374
377
  //SocketIOCall.echoLog(`${socket.id} sends includeOtherPeers with ${JSON.stringify(payload)}`);
375
378
  new IncludeOtherPeersProcessor(SocketIOCall, SocketIOCall.io, socket).executeSave(payload);
376
379
  });
380
+ socket.on("registerSession", (payload) => {
381
+ //SocketIOCall.echoLog(`${socket.id} sends includeOtherPeers with ${JSON.stringify(payload)}`);
382
+ new RegisterSessionProcessor(SocketIOCall, SocketIOCall.io, socket).executeSave(payload);
383
+ });
384
+ socket.on("unregisterSession", (payload) => {
385
+ //SocketIOCall.echoLog(`${socket.id} sends includeOtherPeers with ${JSON.stringify(payload)}`);
386
+ new UnregisterSessionProcessor(SocketIOCall, SocketIOCall.io, socket).executeSave(payload);
387
+ });
377
388
 
378
389
  const extraHooks = Object.keys(SocketIOCall.hookProcessors);
379
390
  for (let k = 0; k < extraHooks.length; k++) {
@@ -20,6 +20,19 @@ export class DisconnectProcessor extends GenericProcessor {
20
20
  clearPersonFromPeople(people, socketId, room) {
21
21
  for (let personId in people) {
22
22
  const onePerson = people[personId];
23
+ //console.log(room, JSON.stringify(onePerson));
24
+ if (room == "public") {
25
+ // public room control
26
+ const { type, user_id } = onePerson;
27
+ if (type == "provider") {
28
+ // It's provider, then remove it from connected providers
29
+ //console.log(`Register session end to ${user_id}`);
30
+ this.context.internalBus.emit("unregisterSession", {
31
+ provider: user_id,
32
+ socketId: socketId,
33
+ });
34
+ }
35
+ }
23
36
  if (onePerson.socket == socketId || socketId == personId) {
24
37
  if (onePerson.sharedState && onePerson.sharedState.user_id) {
25
38
  this.context.internalBus.emit("closeVideoChat", {
@@ -0,0 +1,44 @@
1
+ import { GenericProcessor } from "./GenericProcessor.mjs";
2
+
3
+
4
+ export class RegisterSessionProcessor extends GenericProcessor {
5
+ constructor(context, io, socket) {
6
+ super(context, io, socket);
7
+ }
8
+ execute(args) {
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
+ }
43
+ }
44
+ }
@@ -0,0 +1,30 @@
1
+ import { GenericProcessor } from "./GenericProcessor.mjs";
2
+
3
+
4
+ export class UnregisterSessionProcessor extends GenericProcessor {
5
+ constructor(context, io, socket) {
6
+ super(context, io, socket);
7
+ }
8
+ execute(args) {
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
+ }
29
+ }
30
+ }