vani-meeting-server 2.2.4 → 2.2.6
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.
|
@@ -25,12 +25,12 @@ export declare class RedisHandler {
|
|
|
25
25
|
deleteIpForRoomId(roomId: string, ipAddress: string): Promise<void>;
|
|
26
26
|
storeMesagesForRoom(roomId: string, messagePayload: MessagePayload): Promise<void>;
|
|
27
27
|
fetchMessagesForRoom(roomId: string): Promise<MessagePayload[]>;
|
|
28
|
-
storeMeetingTimeForRoom(roomId: string, time?: number): Promise<
|
|
28
|
+
storeMeetingTimeForRoom(roomId: string, time?: number): Promise<undefined>;
|
|
29
29
|
fetchMeetingTimeForRoom(roomId: string): Promise<number | undefined>;
|
|
30
|
-
removeParticipantForRoom(roomId: string, participant: Participant): Promise<
|
|
31
|
-
addUpdateParticipantForRoom(roomId: string, participant: Participant): Promise<
|
|
30
|
+
removeParticipantForRoom(roomId: string, participant: Participant): Promise<undefined>;
|
|
31
|
+
addUpdateParticipantForRoom(roomId: string, participant: Participant): Promise<undefined>;
|
|
32
32
|
getParticipantByUserId(roomId: string, userId: string): Promise<Participant | undefined>;
|
|
33
33
|
getAllParticipants(roomId: string): Promise<Participant[]>;
|
|
34
|
-
getAllRoomsId(): Promise<string[]>;
|
|
34
|
+
getAllRoomsId(): Promise<string[] | undefined>;
|
|
35
35
|
private updateRoomCleanupTimeOut;
|
|
36
36
|
}
|
|
@@ -25,145 +25,254 @@ class RedisHandler {
|
|
|
25
25
|
return this.redisHandler;
|
|
26
26
|
}
|
|
27
27
|
init() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
try {
|
|
29
|
+
console.log("this.redisClient redis client", ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisUrl);
|
|
30
|
+
this.redisClient = (0, redis_1.createClient)({ url: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisUrl, database: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisDBIndex });
|
|
31
|
+
this.redisSubscriber = (0, redis_1.createClient)({ url: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisUrl });
|
|
32
|
+
this.redisPublisher = (0, redis_1.createClient)({ url: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisUrl });
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
console.log("init", err);
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
async connectDB() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
try {
|
|
40
|
+
this.redisClient.on("connect", (data) => {
|
|
41
|
+
console.info('Redis has been connected successfully.', data);
|
|
42
|
+
});
|
|
43
|
+
this.redisClient.on('end', (err) => {
|
|
44
|
+
console.log('Redis connection has been closed.', err);
|
|
45
|
+
});
|
|
46
|
+
this.redisClient.on('error', (err) => {
|
|
47
|
+
console.log('Unknown exception occurred at Redis', err);
|
|
48
|
+
});
|
|
49
|
+
this.redisClient.on('ready', () => console.log('client is ready'));
|
|
50
|
+
this.redisSubscriber.on("connect", (data) => {
|
|
51
|
+
console.info(' redisSubscriber Redis has been connected successfully.', data);
|
|
52
|
+
});
|
|
53
|
+
this.redisSubscriber.on('end', (err) => {
|
|
54
|
+
console.log('redisSubscriber Redis connection has been closed.', err);
|
|
55
|
+
});
|
|
56
|
+
this.redisSubscriber.on('error', (err) => {
|
|
57
|
+
console.log('redisSubscriber Unknown exception occurred at Redis', err);
|
|
58
|
+
});
|
|
59
|
+
this.redisSubscriber.on('ready', () => console.log('redisSubscriber client is ready'));
|
|
60
|
+
this.redisPublisher.on("connect", (data) => {
|
|
61
|
+
console.info('redisPublisher Redis has been connected successfully.', data);
|
|
62
|
+
});
|
|
63
|
+
this.redisPublisher.on('end', (err) => {
|
|
64
|
+
console.log('redisPublisher Redis connection has been closed.', err);
|
|
65
|
+
});
|
|
66
|
+
this.redisPublisher.on('error', (err) => {
|
|
67
|
+
console.log('redisPublisher Unknown exception occurred at Redis', err);
|
|
68
|
+
});
|
|
69
|
+
this.redisPublisher.on('ready', () => console.log('redisPublisher client is ready'));
|
|
70
|
+
await this.redisClient.connect();
|
|
71
|
+
await this.redisSubscriber.connect();
|
|
72
|
+
await this.redisPublisher.connect();
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
console.log("connectDB", err);
|
|
76
|
+
}
|
|
46
77
|
// await this.redisClient.hSet("rooms","123","HSETObject")
|
|
47
78
|
// console.log(await this.redisClient.hGet("rooms","123"))
|
|
48
79
|
}
|
|
49
80
|
async cleanUp() {
|
|
50
|
-
|
|
51
|
-
|
|
81
|
+
try {
|
|
82
|
+
if (ServerHandler_1.ServerHandler.getInstance().serverStartRequest.shouldCleanRedisOnStartUp) {
|
|
83
|
+
return await this.redisClient.flushDb();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.log("cleanUp", err);
|
|
52
88
|
}
|
|
53
89
|
}
|
|
54
90
|
//Clean Room Id
|
|
55
91
|
async cleanUpRoomId(roomId) {
|
|
56
|
-
|
|
57
|
-
|
|
92
|
+
try {
|
|
93
|
+
console.log("Cleanup Room From Redis");
|
|
94
|
+
await this.redisClient.del(roomId);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
console.log("cleanUpRoomId", err);
|
|
98
|
+
}
|
|
58
99
|
}
|
|
59
100
|
//ip addresss
|
|
60
101
|
async setIpForRoomId(roomId, ipAddress) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
102
|
+
try {
|
|
103
|
+
const oldIps = await this.fetchIpsForRoomId(roomId);
|
|
104
|
+
const isOldIpPresent = oldIps.find((eachOldIp) => eachOldIp.ip === ipAddress && eachOldIp.port === ServerHandler_1.ServerHandler.getInstance().serverStartRequest.port);
|
|
105
|
+
if (isOldIpPresent) {
|
|
106
|
+
console.log("setIpForRoomId", isOldIpPresent);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
oldIps.push({ ip: ipAddress, port: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.port });
|
|
110
|
+
await this.redisClient.hSet(roomId, RedisKeyType.IpAddress, JSON.stringify(oldIps));
|
|
111
|
+
this.updateRoomCleanupTimeOut(roomId);
|
|
112
|
+
await this.fetchIpsForRoomId(roomId);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
console.log("setIpForRoomId", err);
|
|
66
116
|
}
|
|
67
|
-
oldIps.push({ ip: ipAddress, port: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.port });
|
|
68
|
-
await this.redisClient.hSet(roomId, RedisKeyType.IpAddress, JSON.stringify(oldIps));
|
|
69
|
-
this.updateRoomCleanupTimeOut(roomId);
|
|
70
|
-
await this.fetchIpsForRoomId(roomId);
|
|
71
117
|
}
|
|
72
118
|
async fetchIpsForRoomId(roomId) {
|
|
73
119
|
// setTimeout(() => {
|
|
74
120
|
// this.fetchIpsForRoomId(roomId)
|
|
75
121
|
// }, 10000)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
122
|
+
try {
|
|
123
|
+
const ipAddress = await this.redisClient.hGet(roomId, RedisKeyType.IpAddress);
|
|
124
|
+
if (ipAddress) {
|
|
125
|
+
console.log("fetchIpsForRoomId", JSON.parse(ipAddress));
|
|
126
|
+
return JSON.parse(ipAddress);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.log("fetchIpsForRoomId", []);
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
80
132
|
}
|
|
81
|
-
|
|
82
|
-
console.log("fetchIpsForRoomId",
|
|
133
|
+
catch (err) {
|
|
134
|
+
console.log("fetchIpsForRoomId", err);
|
|
83
135
|
return [];
|
|
84
136
|
}
|
|
85
137
|
}
|
|
86
138
|
async deleteIpForRoomId(roomId, ipAddress) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
139
|
+
try {
|
|
140
|
+
const oldIps = await this.fetchIpsForRoomId(roomId);
|
|
141
|
+
const newIps = oldIps.filter((eachOldIp) => !(eachOldIp.ip === ipAddress && eachOldIp.port === ServerHandler_1.ServerHandler.getInstance().serverStartRequest.port));
|
|
142
|
+
await this.redisClient.hSet(roomId, RedisKeyType.IpAddress, JSON.stringify(newIps));
|
|
143
|
+
this.updateRoomCleanupTimeOut(roomId);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
console.log("deleteIpForRoomId", err);
|
|
147
|
+
}
|
|
91
148
|
}
|
|
92
149
|
//Messages
|
|
93
150
|
async storeMesagesForRoom(roomId, messagePayload) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
151
|
+
try {
|
|
152
|
+
const messages = await this.fetchMessagesForRoom(roomId);
|
|
153
|
+
messages.push(messagePayload);
|
|
154
|
+
await this.redisClient.hSet(roomId, RedisKeyType.Messages, JSON.stringify(messages));
|
|
155
|
+
this.updateRoomCleanupTimeOut(roomId);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
console.log("storeMesagesForRoom", err);
|
|
159
|
+
}
|
|
98
160
|
}
|
|
99
161
|
async fetchMessagesForRoom(roomId) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
162
|
+
try {
|
|
163
|
+
const messages = await this.redisClient.hGet(roomId, RedisKeyType.Messages);
|
|
164
|
+
if (messages) {
|
|
165
|
+
return JSON.parse(messages);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
103
170
|
}
|
|
104
|
-
|
|
171
|
+
catch (err) {
|
|
172
|
+
console.log("fetchMessagesForRoom", err);
|
|
105
173
|
return [];
|
|
106
174
|
}
|
|
107
175
|
}
|
|
108
176
|
//Meeting Time
|
|
109
177
|
async storeMeetingTimeForRoom(roomId, time) {
|
|
110
|
-
|
|
111
|
-
|
|
178
|
+
try {
|
|
179
|
+
await this.redisClient.hSet(roomId, RedisKeyType.MeetingTime, time ? time : new Date().getTime());
|
|
180
|
+
this.updateRoomCleanupTimeOut(roomId);
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
console.log("storeMeetingTimeForRoom", err);
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
112
186
|
}
|
|
113
187
|
async fetchMeetingTimeForRoom(roomId) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
188
|
+
try {
|
|
189
|
+
const meetingTime = await this.redisClient.hGet(roomId, RedisKeyType.MeetingTime);
|
|
190
|
+
if (meetingTime) {
|
|
191
|
+
return +meetingTime;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
117
196
|
}
|
|
118
|
-
|
|
197
|
+
catch (err) {
|
|
198
|
+
console.log("fetchMeetingTimeForRoom", err);
|
|
119
199
|
return undefined;
|
|
120
200
|
}
|
|
121
201
|
}
|
|
122
202
|
//Users
|
|
123
203
|
async removeParticipantForRoom(roomId, participant) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
204
|
+
try {
|
|
205
|
+
console.log("removeParticipantForRoom", participant);
|
|
206
|
+
const participantKey = RedisKeyType.Participants + ":" + participant.userId;
|
|
207
|
+
await this.redisClient.hDel(roomId, participantKey);
|
|
208
|
+
// console.log("removeParticipantForRoom =====" , participantKey)
|
|
209
|
+
// console.log(await this.getAllParticipants(roomId))
|
|
210
|
+
// console.log("removeParticipantForRoom +++++")
|
|
211
|
+
this.updateRoomCleanupTimeOut(roomId);
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
console.log("removeParticipantForRoom", err);
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
131
217
|
}
|
|
132
218
|
async addUpdateParticipantForRoom(roomId, participant) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
participant.serverIpAddress
|
|
219
|
+
try {
|
|
220
|
+
console.log("addUpdateParticipantForRoom", participant);
|
|
221
|
+
const participantKey = RedisKeyType.Participants + ":" + participant.userId;
|
|
222
|
+
if (!participant.serverIpAddress) {
|
|
223
|
+
participant.serverIpAddress = await Constant_1.default.getPublicIp();
|
|
224
|
+
}
|
|
225
|
+
await this.redisClient.hSet(roomId, participantKey, JSON.stringify(participant));
|
|
226
|
+
// console.log("addUpdateParticipantForRoom =====" , participantKey)
|
|
227
|
+
// console.log(await this.getAllParticipants(roomId))
|
|
228
|
+
// console.log("addUpdateParticipantForRoom +++++")
|
|
229
|
+
this.updateRoomCleanupTimeOut(roomId);
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
console.log("addUpdateParticipantForRoom", err);
|
|
233
|
+
return undefined;
|
|
137
234
|
}
|
|
138
|
-
await this.redisClient.hSet(roomId, participantKey, JSON.stringify(participant));
|
|
139
|
-
// console.log("addUpdateParticipantForRoom =====" , participantKey)
|
|
140
|
-
// console.log(await this.getAllParticipants(roomId))
|
|
141
|
-
// console.log("addUpdateParticipantForRoom +++++")
|
|
142
|
-
this.updateRoomCleanupTimeOut(roomId);
|
|
143
235
|
}
|
|
144
236
|
async getParticipantByUserId(roomId, userId) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
237
|
+
try {
|
|
238
|
+
const participantKey = RedisKeyType.Participants + ":" + userId;
|
|
239
|
+
const particpantString = await this.redisClient.hGet(roomId, participantKey);
|
|
240
|
+
if (particpantString) {
|
|
241
|
+
return JSON.parse(particpantString);
|
|
242
|
+
}
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
console.log("getParticipantByUserId", err);
|
|
247
|
+
return undefined;
|
|
149
248
|
}
|
|
150
|
-
return undefined;
|
|
151
249
|
}
|
|
152
250
|
async getAllParticipants(roomId) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
251
|
+
try {
|
|
252
|
+
const particpantsInStringify = await this.redisClient.hGetAll(roomId);
|
|
253
|
+
const participants = [];
|
|
254
|
+
if (particpantsInStringify) {
|
|
255
|
+
Object.entries(particpantsInStringify).forEach(([key, value]) => {
|
|
256
|
+
if (key.includes(RedisKeyType.Participants)) {
|
|
257
|
+
participants.push(Object.assign(new Participant_1.Participant(), JSON.parse(value)));
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return participants;
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
console.log("getAllParticipants", err);
|
|
265
|
+
return [];
|
|
161
266
|
}
|
|
162
|
-
return participants;
|
|
163
267
|
}
|
|
164
268
|
//get all rooms
|
|
165
269
|
async getAllRoomsId() {
|
|
166
|
-
|
|
270
|
+
try {
|
|
271
|
+
return await this.redisClient.keys("*");
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
console.log("getAllRoomsId", err);
|
|
275
|
+
}
|
|
167
276
|
}
|
|
168
277
|
// private getRediRoomModelForRoomId(roomId: string): RedisRoomModel {
|
|
169
278
|
// if (this.redisRoomModelHash.has(roomId)) {
|
|
@@ -176,7 +285,12 @@ class RedisHandler {
|
|
|
176
285
|
// }
|
|
177
286
|
// }
|
|
178
287
|
updateRoomCleanupTimeOut(roomId) {
|
|
179
|
-
|
|
288
|
+
try {
|
|
289
|
+
this.redisClient.expire(roomId, ServerHandler_1.ServerHandler.getInstance().serverStartRequest.redisRoomDestoryTimeOutInSec);
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
console.log("updateRoomCleanupTimeOut", err);
|
|
293
|
+
}
|
|
180
294
|
}
|
|
181
295
|
}
|
|
182
296
|
exports.RedisHandler = RedisHandler;
|