vani-meeting-server 2.4.0 → 2.4.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.
@@ -32,4 +32,5 @@ export declare class ServerHandler {
32
32
  getAllOnGoingMeetingRoomIds(): Promise<string[] | undefined>;
33
33
  sendMessage(messagePayload: MessagePayload): Promise<void>;
34
34
  getAllParticipatnsForRoomId(roomId: string): Promise<Participant[]>;
35
+ closeTheRoomForcefully: (roomId: string) => Promise<void>;
35
36
  }
@@ -50,5 +50,26 @@ class ServerHandler {
50
50
  async getAllParticipatnsForRoomId(roomId) {
51
51
  return await RedisHandler_1.RedisHandler.getInstance().getAllParticipants(roomId);
52
52
  }
53
+ closeTheRoomForcefully = async (roomId) => {
54
+ try {
55
+ const participants = await RedisHandler_1.RedisHandler.getInstance().getAllParticipants(roomId);
56
+ if (participants && participants.length > 0) {
57
+ let shouldMoveToNext = true;
58
+ let index = 0;
59
+ while (shouldMoveToNext && index < participants.length) {
60
+ const eachSocketConnection = this.webSocketHandler?.getSocketConnectionByParticpant(participants[index]);
61
+ if (eachSocketConnection) {
62
+ shouldMoveToNext = false;
63
+ eachSocketConnection.closeRoomForcefully();
64
+ break;
65
+ }
66
+ index = index + 1;
67
+ }
68
+ }
69
+ }
70
+ catch (err) {
71
+ console.log("closeTheRoomForcefully", err);
72
+ }
73
+ };
53
74
  }
54
75
  exports.ServerHandler = ServerHandler;
@@ -4,6 +4,7 @@ import WebSocket from "ws";
4
4
  export declare enum WebSocketBasicEvents {
5
5
  Config = "config",
6
6
  JoinRoom = "joinRoom",
7
+ CloseRoomForceFully = "CloseRoomForceFully",
7
8
  IsSetupDone = "setupDone",
8
9
  Ping = "ping",
9
10
  Pong = "pong",
@@ -75,7 +76,8 @@ export declare enum MultiSystemEvents {
75
76
  export declare enum LocalMessageType {
76
77
  OnNewUserJoinedRoom = "onNewUserJoinedRoom",
77
78
  OnUserLeft = "OnUserLeft",
78
- SocketMessage = "socketMessage"
79
+ SocketMessage = "socketMessage",
80
+ SelfLeftForceFully = "SelfLeftForceFully"
79
81
  }
80
82
  export declare type WebSocketEvents = SFUMessageType | WebSocketBasicEvents | LocalMessageType | MultiSystemEvents;
81
83
  export interface WebSocketMessageBody {
@@ -102,7 +104,7 @@ export interface RediSubsciptionDetail {
102
104
  export declare class EachSocketConnectionHandler extends BaseSFUWebsocket {
103
105
  private uuid;
104
106
  private socket;
105
- private selfParticipant?;
107
+ selfParticipant?: Participant;
106
108
  private appId;
107
109
  private isActive;
108
110
  private isUserJoinedFromAnotherSocket;
@@ -120,6 +122,7 @@ export declare class EachSocketConnectionHandler extends BaseSFUWebsocket {
120
122
  private onSocketClosed;
121
123
  private onUserLeft;
122
124
  private onNewMessage;
125
+ closeRoomForcefully: () => Promise<void>;
123
126
  private onAudioVideoPauseResume;
124
127
  private onStartMeetingCalled;
125
128
  private onConfig;
@@ -20,6 +20,7 @@ var WebSocketBasicEvents;
20
20
  (function (WebSocketBasicEvents) {
21
21
  WebSocketBasicEvents["Config"] = "config";
22
22
  WebSocketBasicEvents["JoinRoom"] = "joinRoom";
23
+ WebSocketBasicEvents["CloseRoomForceFully"] = "CloseRoomForceFully";
23
24
  WebSocketBasicEvents["IsSetupDone"] = "setupDone";
24
25
  WebSocketBasicEvents["Ping"] = "ping";
25
26
  WebSocketBasicEvents["Pong"] = "pong";
@@ -95,6 +96,7 @@ var LocalMessageType;
95
96
  LocalMessageType["OnNewUserJoinedRoom"] = "onNewUserJoinedRoom";
96
97
  LocalMessageType["OnUserLeft"] = "OnUserLeft";
97
98
  LocalMessageType["SocketMessage"] = "socketMessage";
99
+ LocalMessageType["SelfLeftForceFully"] = "SelfLeftForceFully";
98
100
  })(LocalMessageType = exports.LocalMessageType || (exports.LocalMessageType = {}));
99
101
  class EachSocketConnectionHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
100
102
  uuid = (0, uuid_1.v4)();
@@ -176,6 +178,9 @@ class EachSocketConnectionHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
176
178
  else if (paylod.type === WebSocketBasicEvents.JoinRoom) {
177
179
  this.joinRoom(paylod.data);
178
180
  }
181
+ else if (paylod.type === WebSocketBasicEvents.CloseRoomForceFully) {
182
+ this.closeRoomForcefully();
183
+ }
179
184
  else if (paylod.type === WebSocketBasicEvents.IsSetupDone) {
180
185
  this.onSetupDone(paylod.data);
181
186
  }
@@ -229,6 +234,20 @@ class EachSocketConnectionHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
229
234
  }
230
235
  this.sendVaniEvent(Event_1.VaniEvent.OnNewChatMessageReceived, paylod);
231
236
  }
237
+ closeRoomForcefully = async () => {
238
+ this.redisBroadcastMessageToTopic(this.selfParticipant?.roomId, this.preapreClientMessageBody(true, this.selfParticipant, this.preapreWebSocketMessageBody(WebSocketBasicEvents.CloseRoomForceFully, {})));
239
+ const roomId = this.selfParticipant?.roomId;
240
+ setTimeout(async () => {
241
+ if (roomId && (await RedisHandler_1.RedisHandler.getInstance().getAllParticipants(roomId)).length > 0) {
242
+ let participant = this.selfParticipant;
243
+ if (!participant) {
244
+ participant = new Participant_1.Participant();
245
+ participant.userId = (0, uuid_1.v4)();
246
+ }
247
+ this.redisBroadcastMessageToTopic(roomId, this.preapreWebSocketMessageBody(LocalMessageType.SelfLeftForceFully, {}));
248
+ }
249
+ }, 2000);
250
+ };
232
251
  async onAudioVideoPauseResume(data) {
233
252
  if (this.selfParticipant) {
234
253
  if (data.message && data.message.type && data.message.type === "video") {
@@ -414,6 +433,9 @@ class EachSocketConnectionHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
414
433
  if (webSocketMessageBody.type === LocalMessageType.OnNewUserJoinedRoom) {
415
434
  this.onNewUserJoinedRoomWithSameUserId(webSocketMessageBody.data);
416
435
  }
436
+ else if (webSocketMessageBody.type === LocalMessageType.SelfLeftForceFully) {
437
+ this.onUserLeft();
438
+ }
417
439
  }
418
440
  else if (data.interfaceName === 'ClientMessageBody') {
419
441
  const socketMessageBody = data;
@@ -1,6 +1,9 @@
1
+ import { EachSocketConnectionHandler } from "./EachSocketConnectionHandler";
2
+ import { Participant } from "../models/Participant";
1
3
  export declare class WebSocketHandler {
2
4
  private wss;
3
5
  private socketConnections;
4
6
  constructor();
5
7
  connect(): void;
8
+ getSocketConnectionByParticpant: (participant: Participant) => EachSocketConnectionHandler | undefined;
6
9
  }
@@ -39,5 +39,8 @@ class WebSocketHandler {
39
39
  });
40
40
  EventEmitterHandler_1.EventEmitterHandler.getInstance().vaniEventEmitter.emit(Event_1.VaniEvent.OnServerStarted, {});
41
41
  }
42
+ getSocketConnectionByParticpant = (participant) => {
43
+ return this.socketConnections.find((eachSocketConnection) => eachSocketConnection.selfParticipant && eachSocketConnection.selfParticipant.userId === participant.userId && eachSocketConnection.selfParticipant.roomId === participant.roomId);
44
+ };
42
45
  }
43
46
  exports.WebSocketHandler = WebSocketHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vani-meeting-server",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Vani Meeting Server SDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",