@mulingai-npm/redis 2.5.0 → 2.5.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.
|
@@ -22,13 +22,14 @@ export declare class MulingstreamSpeakerManager {
|
|
|
22
22
|
removeSpeakerBySocketId(socketId: string): Promise<boolean>;
|
|
23
23
|
removeSpeakersByUserId(userId: string): Promise<number>;
|
|
24
24
|
removeSpeakersByRoomId(roomId: string): Promise<number>;
|
|
25
|
-
/** internal: remove hash + all index references */
|
|
26
25
|
private removeSpeakerById;
|
|
27
26
|
getSpeakerBySpeakerId(speakerId: string): Promise<MulingstreamSpeakerData | null>;
|
|
28
27
|
getSpeakerBySocketId(socketId: string): Promise<MulingstreamSpeakerData | null>;
|
|
29
28
|
getSpeakersByRoomId(roomId: string): Promise<MulingstreamSpeakerData[]>;
|
|
30
29
|
getSpeakersByUserId(userId: string): Promise<MulingstreamSpeakerData[]>;
|
|
31
30
|
getSpeakerByUserRoom(roomId: string, userId: string): Promise<MulingstreamSpeakerData | null>;
|
|
31
|
+
getSpeakersLength(roomId: string): Promise<number>;
|
|
32
|
+
isRoomEmpty(roomId: string): Promise<boolean>;
|
|
32
33
|
updateSourceLanguage(socketId: string, newLang: string): Promise<boolean>;
|
|
33
34
|
updateTargetLanguages(socketId: string, languages: string[]): Promise<boolean>;
|
|
34
35
|
increaseRecordingDuration(socketId: string, delta: number): Promise<number>;
|
|
@@ -6,7 +6,6 @@ class MulingstreamSpeakerManager {
|
|
|
6
6
|
constructor(redisClient) {
|
|
7
7
|
this.redisClient = redisClient;
|
|
8
8
|
}
|
|
9
|
-
/* ------------------------------------------------ helpers */
|
|
10
9
|
parseHash(hash) {
|
|
11
10
|
return {
|
|
12
11
|
speakerId: hash.speakerId,
|
|
@@ -41,7 +40,6 @@ class MulingstreamSpeakerManager {
|
|
|
41
40
|
buildKey(speakerId) {
|
|
42
41
|
return `speaker:${speakerId}`;
|
|
43
42
|
}
|
|
44
|
-
/* ------------------------------------------------ insert */
|
|
45
43
|
async addSpeaker(payload) {
|
|
46
44
|
const speakerId = this.buildId(payload.roomId, payload.userId, payload.socketId);
|
|
47
45
|
const key = this.buildKey(speakerId);
|
|
@@ -59,7 +57,6 @@ class MulingstreamSpeakerManager {
|
|
|
59
57
|
await this.redisClient.expire(`socket:${payload.socketId}:speaker`, EXPIRATION);
|
|
60
58
|
return speakerId;
|
|
61
59
|
}
|
|
62
|
-
/* ------------------------------------------------ remove helpers */
|
|
63
60
|
async removeSpeakerBySocketId(socketId) {
|
|
64
61
|
const speakerId = await this.redisClient.get(`socket:${socketId}:speaker`);
|
|
65
62
|
if (speakerId === null) {
|
|
@@ -94,7 +91,6 @@ class MulingstreamSpeakerManager {
|
|
|
94
91
|
}
|
|
95
92
|
return deletedCount;
|
|
96
93
|
}
|
|
97
|
-
/** internal: remove hash + all index references */
|
|
98
94
|
async removeSpeakerById(speakerId) {
|
|
99
95
|
const key = this.buildKey(speakerId);
|
|
100
96
|
const data = await this.redisClient.hgetall(key);
|
|
@@ -107,12 +103,11 @@ class MulingstreamSpeakerManager {
|
|
|
107
103
|
await this.cleanIndexes(speakerId);
|
|
108
104
|
return true;
|
|
109
105
|
}
|
|
110
|
-
/* ------------------------------------------------ lookup helpers */
|
|
111
106
|
async getSpeakerBySpeakerId(speakerId) {
|
|
112
107
|
const key = this.buildKey(speakerId);
|
|
113
108
|
const hash = await this.redisClient.hgetall(key);
|
|
114
109
|
if (hash === null || Object.keys(hash).length === 0) {
|
|
115
|
-
|
|
110
|
+
// the hash has expired or was never there – remove any stray index refs
|
|
116
111
|
await this.cleanIndexes(speakerId);
|
|
117
112
|
return null;
|
|
118
113
|
}
|
|
@@ -173,7 +168,14 @@ class MulingstreamSpeakerManager {
|
|
|
173
168
|
}
|
|
174
169
|
return null;
|
|
175
170
|
}
|
|
176
|
-
|
|
171
|
+
async getSpeakersLength(roomId) {
|
|
172
|
+
const speakers = await this.getSpeakersByRoomId(roomId);
|
|
173
|
+
return speakers.length;
|
|
174
|
+
}
|
|
175
|
+
async isRoomEmpty(roomId) {
|
|
176
|
+
const totalSpeakers = await this.getSpeakersLength(roomId);
|
|
177
|
+
return totalSpeakers === 0;
|
|
178
|
+
}
|
|
177
179
|
async updateSourceLanguage(socketId, newLang) {
|
|
178
180
|
const speaker = await this.getSpeakerBySocketId(socketId);
|
|
179
181
|
if (speaker === null) {
|
|
@@ -205,7 +207,6 @@ class MulingstreamSpeakerManager {
|
|
|
205
207
|
});
|
|
206
208
|
return speaker.recordingsDuration;
|
|
207
209
|
}
|
|
208
|
-
/* ------------------------------------------------ index cleanup */
|
|
209
210
|
async cleanIndexes(speakerId) {
|
|
210
211
|
const parts = speakerId
|
|
211
212
|
.substring(1, speakerId.length - 1) // remove outer [...]
|