vani-meeting-server 2.9.1 → 2.9.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RedisClientType } from "redis";
|
|
2
2
|
import { MessagePayload } from "../../models/MessagePayload";
|
|
3
3
|
import { Participant } from "../../models/Participant";
|
|
4
|
+
import { SyncLocalEvent } from "../../websocket/EachSocketConnectionHandler";
|
|
4
5
|
export declare enum RedisKeyType {
|
|
5
6
|
Messages = "messages",
|
|
6
7
|
MeetingTime = "meetingTime",
|
|
@@ -13,6 +14,7 @@ export declare class RedisHandler {
|
|
|
13
14
|
private localCacheDataStorage;
|
|
14
15
|
redisPublisher: RedisClientType;
|
|
15
16
|
redisSubscriber: RedisClientType;
|
|
17
|
+
private localEventUpdateRedisSubsciption?;
|
|
16
18
|
static getInstance(): RedisHandler;
|
|
17
19
|
init(): void;
|
|
18
20
|
isRedisConnected: () => Promise<boolean>;
|
|
@@ -22,6 +24,8 @@ export declare class RedisHandler {
|
|
|
22
24
|
private deleteKeyValueForLocalCache;
|
|
23
25
|
private getKeyValueForLocalCache;
|
|
24
26
|
private storeKeyValueForLocalCache;
|
|
27
|
+
storeKeyValueForLocalCacheFromOtherServer: (data: SyncLocalEvent) => Promise<void>;
|
|
28
|
+
protected redisBroadcastMessageToTopic: (topic: string, data: SyncLocalEvent) => Promise<void>;
|
|
25
29
|
setIpForRoomId(roomId: string, ipAddress: string): Promise<void>;
|
|
26
30
|
fetchIpsForRoomId(roomId: string): Promise<{
|
|
27
31
|
ip: string;
|
|
@@ -9,6 +9,7 @@ const Participant_1 = require("../../models/Participant");
|
|
|
9
9
|
const ServerHandler_1 = require("../../ServerHandler");
|
|
10
10
|
const Constant_1 = __importDefault(require("../../utility/Constant"));
|
|
11
11
|
const WebSocketServerStartRequest_1 = require("../../models/WebSocketServerStartRequest");
|
|
12
|
+
const EachSocketConnectionHandler_1 = require("../../websocket/EachSocketConnectionHandler");
|
|
12
13
|
var RedisKeyType;
|
|
13
14
|
(function (RedisKeyType) {
|
|
14
15
|
RedisKeyType["Messages"] = "messages";
|
|
@@ -22,6 +23,7 @@ class RedisHandler {
|
|
|
22
23
|
localCacheDataStorage = new Map;
|
|
23
24
|
redisPublisher;
|
|
24
25
|
redisSubscriber;
|
|
26
|
+
localEventUpdateRedisSubsciption;
|
|
25
27
|
static getInstance() {
|
|
26
28
|
if (!this.redisHandler) {
|
|
27
29
|
this.redisHandler = new RedisHandler();
|
|
@@ -65,13 +67,44 @@ class RedisHandler {
|
|
|
65
67
|
console.log('Unknown exception occurred at Redis', err);
|
|
66
68
|
});
|
|
67
69
|
this.redisClient.on('ready', () => console.log('client is ready'));
|
|
68
|
-
this.redisSubscriber.on("connect", (data) => {
|
|
70
|
+
this.redisSubscriber.on("connect", async (data) => {
|
|
69
71
|
console.info(' redisSubscriber Redis has been connected successfully.', data);
|
|
72
|
+
try {
|
|
73
|
+
if (this.localEventUpdateRedisSubsciption) {
|
|
74
|
+
RedisHandler.getInstance().redisSubscriber.unsubscribe(this.localEventUpdateRedisSubsciption.topic, this.localEventUpdateRedisSubsciption.listener);
|
|
75
|
+
this.localEventUpdateRedisSubsciption = undefined;
|
|
76
|
+
}
|
|
77
|
+
const listener = (data) => {
|
|
78
|
+
// this.onRedisMessage(JSON.parse(data))
|
|
79
|
+
const parsedData = JSON.parse(data);
|
|
80
|
+
this.storeKeyValueForLocalCacheFromOtherServer(parsedData);
|
|
81
|
+
};
|
|
82
|
+
await RedisHandler.getInstance().redisSubscriber.subscribe(EachSocketConnectionHandler_1.MultiSystemEvents.SyncLocalEvent, listener);
|
|
83
|
+
this.localEventUpdateRedisSubsciption = { listener: listener, topic: EachSocketConnectionHandler_1.MultiSystemEvents.SyncLocalEvent };
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
}
|
|
70
87
|
});
|
|
71
88
|
this.redisSubscriber.on('end', (err) => {
|
|
89
|
+
try {
|
|
90
|
+
if (this.localEventUpdateRedisSubsciption) {
|
|
91
|
+
RedisHandler.getInstance().redisSubscriber.unsubscribe(this.localEventUpdateRedisSubsciption.topic, this.localEventUpdateRedisSubsciption.listener);
|
|
92
|
+
this.localEventUpdateRedisSubsciption = undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
}
|
|
72
97
|
console.log('redisSubscriber Redis connection has been closed.', err);
|
|
73
98
|
});
|
|
74
99
|
this.redisSubscriber.on('error', (err) => {
|
|
100
|
+
try {
|
|
101
|
+
if (this.localEventUpdateRedisSubsciption) {
|
|
102
|
+
RedisHandler.getInstance().redisSubscriber.unsubscribe(this.localEventUpdateRedisSubsciption.topic, this.localEventUpdateRedisSubsciption.listener);
|
|
103
|
+
this.localEventUpdateRedisSubsciption = undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
}
|
|
75
108
|
console.log('redisSubscriber Unknown exception occurred at Redis', err);
|
|
76
109
|
});
|
|
77
110
|
this.redisSubscriber.on('ready', () => console.log('redisSubscriber client is ready'));
|
|
@@ -137,14 +170,44 @@ class RedisHandler {
|
|
|
137
170
|
}
|
|
138
171
|
return undefined;
|
|
139
172
|
};
|
|
140
|
-
storeKeyValueForLocalCache = (key, fieldOne, fieldTwo) => {
|
|
173
|
+
storeKeyValueForLocalCache = async (key, fieldOne, fieldTwo) => {
|
|
141
174
|
let keyData = this.localCacheDataStorage.get(key);
|
|
142
175
|
if (!keyData) {
|
|
143
176
|
keyData = new Map();
|
|
144
177
|
this.localCacheDataStorage.set(key, keyData);
|
|
145
178
|
}
|
|
179
|
+
try {
|
|
180
|
+
await this.redisBroadcastMessageToTopic(EachSocketConnectionHandler_1.MultiSystemEvents.SyncLocalEvent, { senderIp: (await Constant_1.default.getPublicIp()).toString(), data: { key: key, fieldOne: fieldOne, fieldTwo: fieldTwo }, interfaceName: 'SyncLocalEvent', type: EachSocketConnectionHandler_1.MultiSystemEvents.SyncLocalEvent });
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
}
|
|
146
184
|
keyData.set(fieldOne, fieldTwo);
|
|
147
185
|
};
|
|
186
|
+
storeKeyValueForLocalCacheFromOtherServer = async (data) => {
|
|
187
|
+
try {
|
|
188
|
+
ServerHandler_1.ServerHandler.getInstance().serverStartRequest && ServerHandler_1.ServerHandler.getInstance().serverStartRequest.logLevel !== WebSocketServerStartRequest_1.LogLevel.None
|
|
189
|
+
&& console.log("storeKeyValueForLocalCacheFromOtherServer recived ", data);
|
|
190
|
+
if (data.senderIp !== await Constant_1.default.getPublicIp()) {
|
|
191
|
+
const key = data.data?.key;
|
|
192
|
+
const fieldOne = data.data?.fieldOne;
|
|
193
|
+
const fieldTwo = data.data?.fieldTwo;
|
|
194
|
+
if (key) {
|
|
195
|
+
let keyData = this.localCacheDataStorage.get(key);
|
|
196
|
+
if (keyData && fieldOne && fieldTwo) {
|
|
197
|
+
keyData.set(fieldOne, fieldTwo);
|
|
198
|
+
ServerHandler_1.ServerHandler.getInstance().serverStartRequest && ServerHandler_1.ServerHandler.getInstance().serverStartRequest.logLevel !== WebSocketServerStartRequest_1.LogLevel.None
|
|
199
|
+
&& console.log("storeKeyValueForLocalCacheFromOtherServer set ", keyData);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
redisBroadcastMessageToTopic = async (topic, data) => {
|
|
208
|
+
const stringifyData = JSON.stringify(data);
|
|
209
|
+
RedisHandler.getInstance().redisPublisher.publish(topic, stringifyData);
|
|
210
|
+
};
|
|
148
211
|
async setIpForRoomId(roomId, ipAddress) {
|
|
149
212
|
try {
|
|
150
213
|
const oldIps = await this.fetchIpsForRoomId(roomId);
|
|
@@ -154,7 +217,7 @@ class RedisHandler {
|
|
|
154
217
|
return;
|
|
155
218
|
}
|
|
156
219
|
oldIps.push({ ip: ipAddress, port: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.port });
|
|
157
|
-
this.storeKeyValueForLocalCache(roomId, RedisKeyType.IpAddress, JSON.stringify(oldIps));
|
|
220
|
+
await this.storeKeyValueForLocalCache(roomId, RedisKeyType.IpAddress, JSON.stringify(oldIps));
|
|
158
221
|
/*await*/ this.redisClient.hSet(roomId, RedisKeyType.IpAddress, JSON.stringify(oldIps));
|
|
159
222
|
this.updateRoomCleanupTimeOut(roomId);
|
|
160
223
|
// await this.fetchIpsForRoomId(roomId)
|
|
@@ -188,7 +251,7 @@ class RedisHandler {
|
|
|
188
251
|
try {
|
|
189
252
|
const oldIps = await this.fetchIpsForRoomId(roomId);
|
|
190
253
|
const newIps = oldIps.filter((eachOldIp) => !(eachOldIp.ip === ipAddress && eachOldIp.port === ServerHandler_1.ServerHandler.getInstance().serverStartRequest.port));
|
|
191
|
-
this.storeKeyValueForLocalCache(roomId, RedisKeyType.IpAddress, JSON.stringify(newIps));
|
|
254
|
+
await this.storeKeyValueForLocalCache(roomId, RedisKeyType.IpAddress, JSON.stringify(newIps));
|
|
192
255
|
/*await*/ this.redisClient.hSet(roomId, RedisKeyType.IpAddress, JSON.stringify(newIps));
|
|
193
256
|
this.updateRoomCleanupTimeOut(roomId);
|
|
194
257
|
}
|
|
@@ -228,7 +291,7 @@ class RedisHandler {
|
|
|
228
291
|
//Meeting Time
|
|
229
292
|
async storeMeetingTimeForRoom(roomId, time) {
|
|
230
293
|
try {
|
|
231
|
-
this.storeKeyValueForLocalCache(roomId, RedisKeyType.MeetingTime, time ? time : new Date().getTime());
|
|
294
|
+
await this.storeKeyValueForLocalCache(roomId, RedisKeyType.MeetingTime, time ? time : new Date().getTime());
|
|
232
295
|
/*await*/ this.redisClient.hSet(roomId, RedisKeyType.MeetingTime, time ? time : new Date().getTime());
|
|
233
296
|
this.updateRoomCleanupTimeOut(roomId);
|
|
234
297
|
}
|
|
@@ -277,7 +340,7 @@ class RedisHandler {
|
|
|
277
340
|
if (!participant.serverIpAddress) {
|
|
278
341
|
participant.serverIpAddress = await Constant_1.default.getPublicIp();
|
|
279
342
|
}
|
|
280
|
-
this.storeKeyValueForLocalCache(roomId, participantKey, JSON.stringify(participant));
|
|
343
|
+
await this.storeKeyValueForLocalCache(roomId, participantKey, JSON.stringify(participant));
|
|
281
344
|
/*await*/ this.redisClient.hSet(roomId, participantKey, JSON.stringify(participant));
|
|
282
345
|
// console.log("addUpdateParticipantForRoom =====" , participantKey)
|
|
283
346
|
// console.log(await this.getAllParticipants(roomId))
|
|
@@ -48,6 +48,9 @@ class SFUEachRoomMutliServerHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket
|
|
|
48
48
|
onMutiRoomMessage = async (message) => {
|
|
49
49
|
ServerHandler_1.ServerHandler.getInstance().serverStartRequest && ServerHandler_1.ServerHandler.getInstance().serverStartRequest.logLevel !== WebSocketServerStartRequest_1.LogLevel.None && console.log("onMutiRoomMessage", message);
|
|
50
50
|
if (message.type === EachSocketConnectionHandler_1.MultiSystemEvents.OnNewServerJoinedForRoom) {
|
|
51
|
+
if (await Constant_1.default.getPublicIp() === message.data.ip) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
51
54
|
const pipeTransportAndPort = await this.createPipeTransport(message.data.ip);
|
|
52
55
|
if (pipeTransportAndPort && await Constant_1.default.getPublicIp() !== message.data.ip) {
|
|
53
56
|
if (!pipeTransportAndPort.transport.tuple.remoteIp) {
|
|
@@ -78,7 +78,8 @@ export declare enum MultiSystemEvents {
|
|
|
78
78
|
OnRemoteConsumerClosed = "OnRemoteConsumerClosed",
|
|
79
79
|
OnConnectPipe = "OnConnectPipe",
|
|
80
80
|
OnPipeConnected = "OnPipeConnected",
|
|
81
|
-
OnPipeClosed = "OnPipeClosed"
|
|
81
|
+
OnPipeClosed = "OnPipeClosed",
|
|
82
|
+
SyncLocalEvent = "SyncLocalEvent"
|
|
82
83
|
}
|
|
83
84
|
export declare enum LocalMessageType {
|
|
84
85
|
OnNewUserJoinedRoom = "onNewUserJoinedRoom",
|
|
@@ -86,7 +87,17 @@ export declare enum LocalMessageType {
|
|
|
86
87
|
SocketMessage = "socketMessage",
|
|
87
88
|
SelfLeftForceFully = "SelfLeftForceFully"
|
|
88
89
|
}
|
|
89
|
-
export type WebSocketEvents = SFUMessageType | WebSocketBasicEvents | LocalMessageType | MultiSystemEvents;
|
|
90
|
+
export type WebSocketEvents = SFUMessageType | WebSocketBasicEvents | LocalMessageType | MultiSystemEvents | SyncLocalEvent;
|
|
91
|
+
export interface SyncLocalEvent {
|
|
92
|
+
interfaceName: 'SyncLocalEvent';
|
|
93
|
+
type: MultiSystemEvents;
|
|
94
|
+
data?: {
|
|
95
|
+
key: string;
|
|
96
|
+
fieldOne: any;
|
|
97
|
+
fieldTwo: any;
|
|
98
|
+
};
|
|
99
|
+
senderIp?: string;
|
|
100
|
+
}
|
|
90
101
|
export interface WebSocketMessageBody {
|
|
91
102
|
interfaceName: 'WebSocketMessageBody';
|
|
92
103
|
type: WebSocketEvents;
|
|
@@ -101,6 +101,7 @@ var MultiSystemEvents;
|
|
|
101
101
|
MultiSystemEvents["OnConnectPipe"] = "OnConnectPipe";
|
|
102
102
|
MultiSystemEvents["OnPipeConnected"] = "OnPipeConnected";
|
|
103
103
|
MultiSystemEvents["OnPipeClosed"] = "OnPipeClosed";
|
|
104
|
+
MultiSystemEvents["SyncLocalEvent"] = "SyncLocalEvent";
|
|
104
105
|
})(MultiSystemEvents || (exports.MultiSystemEvents = MultiSystemEvents = {}));
|
|
105
106
|
var LocalMessageType;
|
|
106
107
|
(function (LocalMessageType) {
|