vani-meeting-server 1.1.0 → 1.1.2

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.
@@ -9,5 +9,6 @@ export declare class ServerHandler {
9
9
  sfuHandler?: SFUHandler;
10
10
  static instance: ServerHandler;
11
11
  static getInstance(): ServerHandler;
12
+ constructor();
12
13
  initWithServerStartRequest(serverStartRequest: WebSocketServerStartRequest): Promise<void>;
13
14
  }
@@ -1,35 +1,32 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { RedisHandler } from "./lib/redis/RedisHandler";
11
- import { WebSocketServerStartRequest } from "./models/WebSocketServerStartRequest";
12
- import { SFUHandler } from "./sfu/SFUHandler";
13
- import { WebSocketHandler } from "./websocket/WebSocketHandler";
14
- export class ServerHandler {
15
- constructor() {
16
- this.serverStartRequest = new WebSocketServerStartRequest();
17
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServerHandler = void 0;
4
+ const RedisHandler_1 = require("./lib/redis/RedisHandler");
5
+ const WebSocketServerStartRequest_1 = require("./models/WebSocketServerStartRequest");
6
+ const SFUHandler_1 = require("./sfu/SFUHandler");
7
+ const WebSocketHandler_1 = require("./websocket/WebSocketHandler");
8
+ class ServerHandler {
9
+ serverStartRequest = new WebSocketServerStartRequest_1.WebSocketServerStartRequest();
10
+ rediHandler;
11
+ webSocketHandler;
12
+ sfuHandler;
13
+ static instance = new ServerHandler();
18
14
  static getInstance() {
19
15
  return ServerHandler.instance;
20
16
  }
21
- initWithServerStartRequest(serverStartRequest) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- this.serverStartRequest = serverStartRequest;
24
- this.rediHandler = RedisHandler.getInstance();
25
- yield this.rediHandler.connectDB();
26
- yield this.rediHandler.cleanUp();
27
- console.info("On Redis Connected");
28
- this.webSocketHandler = new WebSocketHandler();
29
- this.webSocketHandler.connect();
30
- this.sfuHandler = SFUHandler.getInstance();
31
- this.sfuHandler.init();
32
- });
17
+ constructor() {
18
+ console.log("ServerHandler constructor");
19
+ }
20
+ async initWithServerStartRequest(serverStartRequest) {
21
+ this.serverStartRequest = serverStartRequest;
22
+ this.rediHandler = RedisHandler_1.RedisHandler.getInstance();
23
+ await this.rediHandler.connectDB();
24
+ await this.rediHandler.cleanUp();
25
+ console.info("On Redis Connected");
26
+ this.webSocketHandler = new WebSocketHandler_1.WebSocketHandler();
27
+ this.webSocketHandler.connect();
28
+ this.sfuHandler = SFUHandler_1.SFUHandler.getInstance();
29
+ this.sfuHandler.init();
33
30
  }
34
31
  }
35
- ServerHandler.instance = new ServerHandler();
32
+ exports.ServerHandler = ServerHandler;
@@ -1,18 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { RedisHandler } from "../lib/redis/RedisHandler";
11
- export class BaseSFUWebsocket {
12
- redisBroadcastMessageToTopic(topic, data) {
13
- return __awaiter(this, void 0, void 0, function* () {
14
- RedisHandler.getInstance().redisPublisher.publish(topic, JSON.stringify(data));
15
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseSFUWebsocket = void 0;
4
+ const RedisHandler_1 = require("../lib/redis/RedisHandler");
5
+ class BaseSFUWebsocket {
6
+ async redisBroadcastMessageToTopic(topic, data) {
7
+ RedisHandler_1.RedisHandler.getInstance().redisPublisher.publish(topic, JSON.stringify(data));
16
8
  }
17
9
  //Utilility function
18
10
  preapreClientMessageBody(shouldSendToSelf, senderParticipant, broadcastMessage) {
@@ -22,3 +14,4 @@ export class BaseSFUWebsocket {
22
14
  return { type, data, interfaceName: 'WebSocketMessageBody' };
23
15
  }
24
16
  }
17
+ exports.BaseSFUWebsocket = BaseSFUWebsocket;
package/lib/index.js CHANGED
@@ -1,3 +1,19 @@
1
- export * from './models/Event';
2
- export * from './models/WebSocketServerStartRequest';
3
- export * from './ServerHandler';
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./models/Event"), exports);
18
+ __exportStar(require("./models/WebSocketServerStartRequest"), exports);
19
+ __exportStar(require("./ServerHandler"), exports);
@@ -1,135 +1,112 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { createClient } from "redis";
11
- import { Participant } from "../../models/Participant";
12
- import { ServerHandler } from "../../ServerHandler";
13
- export var RedisKeyType;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisHandler = exports.RedisKeyType = void 0;
4
+ const redis_1 = require("redis");
5
+ const Participant_1 = require("../../models/Participant");
6
+ const ServerHandler_1 = require("../../ServerHandler");
7
+ var RedisKeyType;
14
8
  (function (RedisKeyType) {
15
9
  RedisKeyType["Messages"] = "messages";
16
10
  RedisKeyType["MeetingTime"] = "meetingTime";
17
11
  RedisKeyType["Participants"] = "participants";
18
- })(RedisKeyType || (RedisKeyType = {}));
19
- export class RedisHandler {
12
+ })(RedisKeyType = exports.RedisKeyType || (exports.RedisKeyType = {}));
13
+ class RedisHandler {
14
+ static redisHandler = new RedisHandler();
15
+ redisClient;
16
+ // private redisRoomModelHash = new Map<string, RedisRoomModel>;
17
+ redisPublisher;
18
+ redisSubscriber;
20
19
  constructor() {
21
- this.redisClient = createClient({ url: ServerHandler.getInstance().serverStartRequest.redisUrl, database: ServerHandler.getInstance().serverStartRequest.redisDBIndex });
22
- this.redisSubscriber = createClient({ url: ServerHandler.getInstance().serverStartRequest.redisUrl });
23
- this.redisPublisher = createClient({ url: ServerHandler.getInstance().serverStartRequest.redisUrl });
20
+ this.redisClient = (0, redis_1.createClient)({ url: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisUrl, database: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisDBIndex });
21
+ this.redisSubscriber = (0, redis_1.createClient)({ url: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisUrl });
22
+ this.redisPublisher = (0, redis_1.createClient)({ url: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisUrl });
24
23
  }
25
24
  static getInstance() {
26
25
  return this.redisHandler;
27
26
  }
28
- connectDB() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- this.redisClient.on("connect", (data) => {
31
- console.info('Redis has been connected successfully.', data);
32
- });
33
- this.redisClient.on('end', (err) => {
34
- console.error('Redis connection has been closed.', err);
35
- });
36
- this.redisClient.on('error', (err) => {
37
- console.error('Unknown exception occurred at Redis', err);
38
- });
39
- yield this.redisClient.connect();
40
- yield this.redisSubscriber.connect();
41
- yield this.redisPublisher.connect();
42
- // await this.redisClient.hSet("rooms","123","HSETObject")
43
- // console.log(await this.redisClient.hGet("rooms","123"))
27
+ async connectDB() {
28
+ this.redisClient.on("connect", (data) => {
29
+ console.info('Redis has been connected successfully.', data);
44
30
  });
45
- }
46
- cleanUp() {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- return yield this.redisClient.flushDb();
31
+ this.redisClient.on('end', (err) => {
32
+ console.error('Redis connection has been closed.', err);
33
+ });
34
+ this.redisClient.on('error', (err) => {
35
+ console.error('Unknown exception occurred at Redis', err);
49
36
  });
37
+ await this.redisClient.connect();
38
+ await this.redisSubscriber.connect();
39
+ await this.redisPublisher.connect();
40
+ // await this.redisClient.hSet("rooms","123","HSETObject")
41
+ // console.log(await this.redisClient.hGet("rooms","123"))
42
+ }
43
+ async cleanUp() {
44
+ return await this.redisClient.flushDb();
50
45
  }
51
46
  //Clean Room Id
52
- cleanUpRoomId(roomId) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- yield this.redisClient.del(roomId);
55
- });
47
+ async cleanUpRoomId(roomId) {
48
+ await this.redisClient.del(roomId);
56
49
  }
57
50
  //Messages
58
- storeMesagesForRoom(roomId, messagePayload) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const messages = yield this.fetchMessagesForRoom(roomId);
61
- messages.push(messagePayload);
62
- yield this.redisClient.hSet(roomId, RedisKeyType.Messages, JSON.stringify(messages));
63
- this.updateRoomCleanupTimeOut(roomId);
64
- });
51
+ async storeMesagesForRoom(roomId, messagePayload) {
52
+ const messages = await this.fetchMessagesForRoom(roomId);
53
+ messages.push(messagePayload);
54
+ await this.redisClient.hSet(roomId, RedisKeyType.Messages, JSON.stringify(messages));
55
+ this.updateRoomCleanupTimeOut(roomId);
65
56
  }
66
- fetchMessagesForRoom(roomId) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const messages = yield this.redisClient.hGet(roomId, RedisKeyType.Messages);
69
- if (messages) {
70
- return JSON.parse(messages);
71
- }
72
- else {
73
- return [];
74
- }
75
- });
57
+ async fetchMessagesForRoom(roomId) {
58
+ const messages = await this.redisClient.hGet(roomId, RedisKeyType.Messages);
59
+ if (messages) {
60
+ return JSON.parse(messages);
61
+ }
62
+ else {
63
+ return [];
64
+ }
76
65
  }
77
66
  //Meeting Time
78
- storeMeetingTimeForRoom(roomId, time) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- yield this.redisClient.hSet(roomId, RedisKeyType.MeetingTime, time ? time : new Date().getTime());
81
- this.updateRoomCleanupTimeOut(roomId);
82
- });
67
+ async storeMeetingTimeForRoom(roomId, time) {
68
+ await this.redisClient.hSet(roomId, RedisKeyType.MeetingTime, time ? time : new Date().getTime());
69
+ this.updateRoomCleanupTimeOut(roomId);
83
70
  }
84
- fetchMeetingTimeForRoom(roomId) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- const meetingTime = yield this.redisClient.hGet(roomId, RedisKeyType.MeetingTime);
87
- if (meetingTime) {
88
- return +meetingTime;
89
- }
90
- else {
91
- return undefined;
92
- }
93
- });
71
+ async fetchMeetingTimeForRoom(roomId) {
72
+ const meetingTime = await this.redisClient.hGet(roomId, RedisKeyType.MeetingTime);
73
+ if (meetingTime) {
74
+ return +meetingTime;
75
+ }
76
+ else {
77
+ return undefined;
78
+ }
94
79
  }
95
80
  //Users
96
- removeParticipantForRoom(roomId, participant) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const participantKey = RedisKeyType.Participants + ":" + participant.userId;
99
- yield this.redisClient.hDel(roomId, participantKey);
100
- this.updateRoomCleanupTimeOut(roomId);
101
- });
81
+ async removeParticipantForRoom(roomId, participant) {
82
+ const participantKey = RedisKeyType.Participants + ":" + participant.userId;
83
+ await this.redisClient.hDel(roomId, participantKey);
84
+ this.updateRoomCleanupTimeOut(roomId);
102
85
  }
103
- addUpdateParticipantForRoom(roomId, participant) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- const participantKey = RedisKeyType.Participants + ":" + participant.userId;
106
- yield this.redisClient.hSet(roomId, participantKey, JSON.stringify(participant));
107
- this.updateRoomCleanupTimeOut(roomId);
108
- });
86
+ async addUpdateParticipantForRoom(roomId, participant) {
87
+ const participantKey = RedisKeyType.Participants + ":" + participant.userId;
88
+ await this.redisClient.hSet(roomId, participantKey, JSON.stringify(participant));
89
+ this.updateRoomCleanupTimeOut(roomId);
109
90
  }
110
- getParticipantByUserId(roomId, userId) {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- const participantKey = RedisKeyType.Participants + ":" + userId;
113
- const particpantString = yield this.redisClient.hGet(roomId, participantKey);
114
- if (particpantString) {
115
- return JSON.parse(particpantString);
116
- }
117
- return undefined;
118
- });
91
+ async getParticipantByUserId(roomId, userId) {
92
+ const participantKey = RedisKeyType.Participants + ":" + userId;
93
+ const particpantString = await this.redisClient.hGet(roomId, participantKey);
94
+ if (particpantString) {
95
+ return JSON.parse(particpantString);
96
+ }
97
+ return undefined;
119
98
  }
120
- getAllParticipants(roomId) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- const particpantsInStringify = yield this.redisClient.hGetAll(roomId);
123
- const participants = [];
124
- if (particpantsInStringify) {
125
- Object.entries(particpantsInStringify).forEach(([key, value]) => {
126
- if (key.includes(RedisKeyType.Participants)) {
127
- participants.push(Object.assign(new Participant(), JSON.parse(value)));
128
- }
129
- });
130
- }
131
- return participants;
132
- });
99
+ async getAllParticipants(roomId) {
100
+ const particpantsInStringify = await this.redisClient.hGetAll(roomId);
101
+ const participants = [];
102
+ if (particpantsInStringify) {
103
+ Object.entries(particpantsInStringify).forEach(([key, value]) => {
104
+ if (key.includes(RedisKeyType.Participants)) {
105
+ participants.push(Object.assign(new Participant_1.Participant(), JSON.parse(value)));
106
+ }
107
+ });
108
+ }
109
+ return participants;
133
110
  }
134
111
  // private getRediRoomModelForRoomId(roomId: string): RedisRoomModel {
135
112
  // if (this.redisRoomModelHash.has(roomId)) {
@@ -142,7 +119,7 @@ export class RedisHandler {
142
119
  // }
143
120
  // }
144
121
  updateRoomCleanupTimeOut(roomId) {
145
- this.redisClient.expire(roomId, ServerHandler.getInstance().serverStartRequest.redisRoomDestoryTimeOutInSec);
122
+ this.redisClient.expire(roomId, ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisRoomDestoryTimeOutInSec);
146
123
  }
147
124
  }
148
- RedisHandler.redisHandler = new RedisHandler();
125
+ exports.RedisHandler = RedisHandler;
@@ -1,8 +1,11 @@
1
- export var VaniEvent;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VaniEvent = void 0;
4
+ var VaniEvent;
2
5
  (function (VaniEvent) {
3
6
  VaniEvent["OnNewMeetingStarted"] = "onNewMeetingStarted";
4
7
  VaniEvent["OnNewMeetingEnded"] = "onNewMeetingEnded";
5
8
  VaniEvent["OnUserJoined"] = "onUserJoined";
6
9
  VaniEvent["OnUserLeft"] = "onUserLeft";
7
10
  VaniEvent["OnServerStarted"] = "onServerStarted";
8
- })(VaniEvent || (VaniEvent = {}));
11
+ })(VaniEvent = exports.VaniEvent || (exports.VaniEvent = {}));
@@ -1,29 +1,26 @@
1
- export var ChatMessageType;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessagePayload = exports.ChatSendVia = exports.ChatMessageType = void 0;
4
+ var ChatMessageType;
2
5
  (function (ChatMessageType) {
3
6
  ChatMessageType["Chat"] = "chat";
4
7
  ChatMessageType["File"] = "file";
5
8
  ChatMessageType["Info"] = "info";
6
- })(ChatMessageType || (ChatMessageType = {}));
7
- export var ChatSendVia;
9
+ })(ChatMessageType = exports.ChatMessageType || (exports.ChatMessageType = {}));
10
+ var ChatSendVia;
8
11
  (function (ChatSendVia) {
9
12
  ChatSendVia["WebSocket"] = "WebSocket";
10
13
  ChatSendVia["DataChannel"] = "DataChannel";
11
- })(ChatSendVia || (ChatSendVia = {}));
12
- export class MessagePayload {
13
- constructor() {
14
- this.to = "all";
15
- this.extraData = {};
16
- // public sender? :Participant;
17
- this.shouldPresist = false;
18
- this.time = new Date().getTime();
19
- this.chatSendVia = ChatSendVia.WebSocket;
20
- // constructor( _message : string)
21
- // constructor( _message : string , _to: string )
22
- // constructor(_message : string , _to: string = "all" , _sender ? : Participant , _type : ChatMessageType | string = ChatMessageType.Chat) {
23
- // this.message = _message;
24
- // this.to = _to;
25
- // this.sender = _sender;
26
- // this.type = _type;
27
- // }
28
- }
14
+ })(ChatSendVia = exports.ChatSendVia || (exports.ChatSendVia = {}));
15
+ class MessagePayload {
16
+ message;
17
+ to = "all";
18
+ extraData = {};
19
+ type;
20
+ senderUserId;
21
+ // public sender? :Participant;
22
+ shouldPresist = false;
23
+ time = new Date().getTime();
24
+ chatSendVia = ChatSendVia.WebSocket;
29
25
  }
26
+ exports.MessagePayload = MessagePayload;
@@ -1,20 +1,19 @@
1
- export class Participant {
2
- constructor() {
3
- this.isAdmin = false;
4
- this.isAudioBlockedByAdmin = false;
5
- this.isVideoBlockedByAdmin = false;
6
- this.isMessageBlockedByAdmin = false;
7
- this.isWhiteboardBlockedByAdmin = true;
8
- this.isScreenshareBlockedByAdmin = false;
9
- this.isVideoEnable = false;
10
- this.isAudioEnable = false;
11
- this.isStartMeetingCalled = false;
12
- this.isRecordingUser = false;
13
- // constructor(_userId: string, _roomId: string, _userData: any = {}, _isAdmin: boolean = false) {
14
- // this.userId = _userId;
15
- // this.roomId = _roomId;
16
- // this.userData = _userData;
17
- // this.isAdmin = _isAdmin;
18
- // }
19
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Participant = void 0;
4
+ class Participant {
5
+ userId;
6
+ userData;
7
+ isAdmin = false;
8
+ isAudioBlockedByAdmin = false;
9
+ isVideoBlockedByAdmin = false;
10
+ isMessageBlockedByAdmin = false;
11
+ isWhiteboardBlockedByAdmin = true;
12
+ isScreenshareBlockedByAdmin = false;
13
+ roomId;
14
+ isVideoEnable = false;
15
+ isAudioEnable = false;
16
+ isStartMeetingCalled = false;
17
+ isRecordingUser = false;
20
18
  }
19
+ exports.Participant = Participant;
@@ -1,11 +1,13 @@
1
- export class WebSocketServerStartRequest {
2
- constructor() {
3
- this.port = 4010;
4
- this.redisUrl = "redis://127.0.0.1:6378";
5
- this.redisDBIndex = 5;
6
- this.redisRoomDestoryTimeOutInSec = 1800;
7
- this.rtcMinPort = 40000;
8
- this.rtcMaxPort = 59999;
9
- this.isTCPConnection = false;
10
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebSocketServerStartRequest = void 0;
4
+ class WebSocketServerStartRequest {
5
+ port = 4010;
6
+ redisUrl = "redis://127.0.0.1:6378";
7
+ redisDBIndex = 5;
8
+ redisRoomDestoryTimeOutInSec = 1800;
9
+ rtcMinPort = 40000;
10
+ rtcMaxPort = 59999;
11
+ isTCPConnection = false;
11
12
  }
13
+ exports.WebSocketServerStartRequest = WebSocketServerStartRequest;