vani-meeting-server 2.0.7 → 2.0.9
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.
- package/lib/lib/redis/RedisHandler.d.ts +1 -0
- package/lib/lib/redis/RedisHandler.js +7 -0
- package/lib/sfu/SFUEachRoomHandler.d.ts +3 -0
- package/lib/sfu/SFUEachRoomHandler.js +26 -0
- package/lib/sfu/SFUEachRoomMutliServerHandler.js +12 -7
- package/lib/websocket/EachSocketConnectionHandler.js +8 -9
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ export declare class RedisHandler {
|
|
|
22
22
|
ip: string;
|
|
23
23
|
port: number;
|
|
24
24
|
}[]>;
|
|
25
|
+
deleteIpForRoomId(roomId: string, ipAddress: string): Promise<void>;
|
|
25
26
|
storeMesagesForRoom(roomId: string, messagePayload: MessagePayload): Promise<void>;
|
|
26
27
|
fetchMessagesForRoom(roomId: string): Promise<MessagePayload[]>;
|
|
27
28
|
storeMeetingTimeForRoom(roomId: string, time?: number): Promise<void>;
|
|
@@ -62,6 +62,7 @@ class RedisHandler {
|
|
|
62
62
|
}
|
|
63
63
|
oldIps.push({ ip: ipAddress, port: ServerHandler_1.ServerHandler.getInstance().serverStartRequest.port });
|
|
64
64
|
await this.redisClient.hSet(roomId, RedisKeyType.IpAddress, JSON.stringify(oldIps));
|
|
65
|
+
this.updateRoomCleanupTimeOut(roomId);
|
|
65
66
|
}
|
|
66
67
|
async fetchIpsForRoomId(roomId) {
|
|
67
68
|
const ipAddress = await this.redisClient.hGet(roomId, RedisKeyType.IpAddress);
|
|
@@ -74,6 +75,12 @@ class RedisHandler {
|
|
|
74
75
|
return [];
|
|
75
76
|
}
|
|
76
77
|
}
|
|
78
|
+
async deleteIpForRoomId(roomId, ipAddress) {
|
|
79
|
+
const oldIps = await this.fetchIpsForRoomId(roomId);
|
|
80
|
+
const newIps = oldIps.filter((eachOldIp) => !(eachOldIp.ip === ipAddress && eachOldIp.port === ServerHandler_1.ServerHandler.getInstance().serverStartRequest.port));
|
|
81
|
+
await this.redisClient.hSet(roomId, RedisKeyType.IpAddress, JSON.stringify(newIps));
|
|
82
|
+
this.updateRoomCleanupTimeOut(roomId);
|
|
83
|
+
}
|
|
77
84
|
//Messages
|
|
78
85
|
async storeMesagesForRoom(roomId, messagePayload) {
|
|
79
86
|
const messages = await this.fetchMessagesForRoom(roomId);
|
|
@@ -46,6 +46,7 @@ export declare class SFUEachRoomHandler extends BaseSFUWebsocket implements SFUE
|
|
|
46
46
|
private audioObserver?;
|
|
47
47
|
private connectionProtocol;
|
|
48
48
|
private eachRoomMutliserverHandler?;
|
|
49
|
+
private redisSubscribtionDetails;
|
|
49
50
|
constructor(roomId: string, workers: Worker[], sendWorkerIndex: number, connectionProtocol?: ConnectionProtocol);
|
|
50
51
|
onInit: () => Promise<void>;
|
|
51
52
|
getConnectionProtocolType(): ConnectionProtocol;
|
|
@@ -68,5 +69,7 @@ export declare class SFUEachRoomHandler extends BaseSFUWebsocket implements SFUE
|
|
|
68
69
|
resumeAllBroadcastingConsumers(): Promise<void>;
|
|
69
70
|
startBroadcasting(plainTransportPayload: PlainTransportPayload): Promise<void>;
|
|
70
71
|
private consumeProducerForPlainTransport;
|
|
72
|
+
private redisSubscribeToTopic;
|
|
73
|
+
private onRedisMessage;
|
|
71
74
|
cleanUp(): Promise<void>;
|
|
72
75
|
}
|
|
@@ -49,6 +49,7 @@ class SFUEachRoomHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
49
49
|
audioObserver;
|
|
50
50
|
connectionProtocol = ServerHandler_1.ServerHandler.getInstance().serverStartRequest.connectionProtocol;
|
|
51
51
|
eachRoomMutliserverHandler;
|
|
52
|
+
redisSubscribtionDetails = [];
|
|
52
53
|
constructor(roomId, workers, sendWorkerIndex, connectionProtocol) {
|
|
53
54
|
super();
|
|
54
55
|
this.roomId = roomId;
|
|
@@ -63,6 +64,7 @@ class SFUEachRoomHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
63
64
|
this.onInit();
|
|
64
65
|
}
|
|
65
66
|
onInit = async () => {
|
|
67
|
+
await this.redisSubscribeToTopic(Utility_1.Utility.getTopicForRoomIdAndIp(this.roomId, await Constant_1.default.getPublicIp()));
|
|
66
68
|
await this.setUpForRoomId(this.workers, this.sendWorkerIndex);
|
|
67
69
|
if (this.sendRouter) {
|
|
68
70
|
this.eachRoomMutliserverHandler = new SFUEachRoomMutliServerHandler_1.SFUEachRoomMutliServerHandler(this.roomId, this.sendRouter, this);
|
|
@@ -372,6 +374,25 @@ class SFUEachRoomHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
372
374
|
}
|
|
373
375
|
}
|
|
374
376
|
}
|
|
377
|
+
async redisSubscribeToTopic(topic) {
|
|
378
|
+
const isListenerAlreadyExist = this.redisSubscribtionDetails.find((eachRedisSubscribtionDetails) => eachRedisSubscribtionDetails.topic === topic);
|
|
379
|
+
if (!isListenerAlreadyExist) {
|
|
380
|
+
const listener = (data) => {
|
|
381
|
+
this.onRedisMessage(JSON.parse(data));
|
|
382
|
+
};
|
|
383
|
+
await RedisHandler_1.RedisHandler.getInstance().redisSubscriber.subscribe(topic, listener);
|
|
384
|
+
this.redisSubscribtionDetails.push({ topic, listener });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
onRedisMessage = async (data) => {
|
|
388
|
+
if (data.interfaceName === 'MultiSystemEventsBody') {
|
|
389
|
+
console.log("MultiSystemEventsBody recived ", data);
|
|
390
|
+
const multiSystemEvent = data;
|
|
391
|
+
if (multiSystemEvent.roomId === this.roomId) {
|
|
392
|
+
this.onMutiRoomMessage(multiSystemEvent);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
};
|
|
375
396
|
async cleanUp() {
|
|
376
397
|
console.debug("Clean Up Room Id ", this.roomId);
|
|
377
398
|
const allParticipants = await RedisHandler_1.RedisHandler.getInstance().getAllParticipants(this.roomId);
|
|
@@ -388,6 +409,11 @@ class SFUEachRoomHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
388
409
|
EventEmitterHandler_1.EventEmitterHandler.getInstance().vaniEventEmitter.emit(Event_1.VaniEvent.OnNewMeetingEnded, this.roomId);
|
|
389
410
|
}
|
|
390
411
|
EventEmitterHandler_1.EventEmitterHandler.getInstance().vaniEventEmitter.emit(Event_1.VaniEvent.OnAllParticipantLeftOnServer, this.roomId);
|
|
412
|
+
RedisHandler_1.RedisHandler.getInstance().deleteIpForRoomId(this.roomId, await Constant_1.default.getPublicIp());
|
|
413
|
+
this.redisSubscribtionDetails.forEach((eachRedisSubscribtionDetails) => {
|
|
414
|
+
RedisHandler_1.RedisHandler.getInstance().redisSubscriber.unsubscribe(eachRedisSubscribtionDetails.topic, eachRedisSubscribtionDetails.listener);
|
|
415
|
+
});
|
|
416
|
+
this.redisSubscribtionDetails = [];
|
|
391
417
|
this.eachRoomMutliserverHandler?.cleanUp();
|
|
392
418
|
this.eachRoomMutliserverHandler = undefined;
|
|
393
419
|
this.roomPaticipants.forEach((sfuEachRoomUser) => {
|
|
@@ -49,18 +49,22 @@ class SFUEachRoomMutliServerHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket
|
|
|
49
49
|
if (message.type === EachSocketConnectionHandler_1.MultiSystemEvents.OnNewServerJoinedForRoom) {
|
|
50
50
|
const pipeTransportAndPort = await this.createPipeTransport(message.data.ip);
|
|
51
51
|
if (pipeTransportAndPort) {
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
if (!pipeTransportAndPort.transport.tuple.remoteIp) {
|
|
53
|
+
await pipeTransportAndPort.transport?.connect({ ip: message.data.ip, port: message.data.port });
|
|
54
|
+
this.redisBroadcastMessageToTopic(Utility_1.Utility.getTopicForRoomIdAndIp(message.roomId, message.data.ip), this.prepareMutilSystemEvents(EachSocketConnectionHandler_1.MultiSystemEvents.OnConnectPipe, message.roomId, { ip: await Constant_1.default.getPublicIp(), port: pipeTransportAndPort.port }));
|
|
55
|
+
}
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
else if (message.type === EachSocketConnectionHandler_1.MultiSystemEvents.OnConnectPipe) {
|
|
57
59
|
const ip = message.data.ip;
|
|
58
60
|
if (this.pipeTransports[ip]) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
if (!this.pipeTransports[ip].transport.tuple.remoteIp) {
|
|
62
|
+
await this.pipeTransports[ip].transport.connect({ ip: ip, port: message.data.port });
|
|
63
|
+
this.redisBroadcastMessageToTopic(Utility_1.Utility.getTopicForRoomIdAndIp(message.roomId, message.data.ip), this.prepareMutilSystemEvents(EachSocketConnectionHandler_1.MultiSystemEvents.OnPipeConnected, message.roomId, { ip: await Constant_1.default.getPublicIp() }));
|
|
64
|
+
this.roomHandlerDataSource.getAllProducerForRoom().forEach(async (eachRoomProducer) => {
|
|
65
|
+
await this.consumeProductAndInfrom(this.pipeTransports[ip].transport, ip, eachRoomProducer);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
else if (message.type === EachSocketConnectionHandler_1.MultiSystemEvents.OnPipeConnected) {
|
|
@@ -86,6 +90,7 @@ class SFUEachRoomMutliServerHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket
|
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
else if (message.type === EachSocketConnectionHandler_1.MultiSystemEvents.OnPipeClosed) {
|
|
93
|
+
console.log("on remote");
|
|
89
94
|
if (message.data.ip) {
|
|
90
95
|
if (this.pipeTransports[message.data.ip]) {
|
|
91
96
|
this.pipeTransports[message.data.ip].transport.close();
|
|
@@ -274,7 +274,6 @@ class EachSocketConnectionHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
274
274
|
if (this.roomIds.includes(roomId) === false) {
|
|
275
275
|
this.roomIds.push(roomId);
|
|
276
276
|
this.redisSubscribeToTopic(roomId);
|
|
277
|
-
this.redisSubscribeToTopic(Utility_1.Utility.getTopicForRoomIdAndIp(roomId, await Constant_1.default.getPublicIp()));
|
|
278
277
|
}
|
|
279
278
|
//Send Local Event To Close Old Socket for same User id
|
|
280
279
|
const localEventData = { roomId: roomId, senderUUID: this.uuid, userId: userId };
|
|
@@ -407,14 +406,14 @@ class EachSocketConnectionHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
407
406
|
const socketMessageBody = data;
|
|
408
407
|
this.sendMessageToClient(socketMessageBody);
|
|
409
408
|
}
|
|
410
|
-
else if (data.interfaceName === 'MultiSystemEventsBody') {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
409
|
+
// else if (data.interfaceName === 'MultiSystemEventsBody') {
|
|
410
|
+
// console.log("MultiSystemEventsBody recived ", data)
|
|
411
|
+
// const multiSystemEvent: MultiSystemEventsBody = data
|
|
412
|
+
// const roomSFUHandler = SFUHandler.getInstance().getRoomSFUHandler(multiSystemEvent.roomId)
|
|
413
|
+
// if (roomSFUHandler) {
|
|
414
|
+
// roomSFUHandler.onMutiRoomMessage(multiSystemEvent)
|
|
415
|
+
// }
|
|
416
|
+
// }
|
|
418
417
|
}
|
|
419
418
|
async subscribeToRedisMessages() {
|
|
420
419
|
RedisHandler_1.RedisHandler.getInstance().redisSubscriber.on('message', (roomId, messageInString) => {
|