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