@mulingai-npm/redis 2.5.0 → 2.5.3
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.
|
@@ -87,9 +87,11 @@ export declare class MulingstreamChunkManager {
|
|
|
87
87
|
transcription?: string;
|
|
88
88
|
sttStatus?: StepStatus;
|
|
89
89
|
}): Promise<boolean>;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
updateSttObject(roomId: string, chunkNumber: number, newStt: Record<string, {
|
|
91
|
+
transcription: string;
|
|
92
|
+
status: StepStatus;
|
|
93
|
+
}>): Promise<boolean>;
|
|
94
|
+
discardStt(roomId: string, chunkNumber: number): Promise<boolean>;
|
|
93
95
|
updateFinalTranscription(roomId: string, chunkNumber: number, transcription: string, sttStatus: StepStatus): Promise<boolean>;
|
|
94
96
|
/**
|
|
95
97
|
* Discards all post-STT steps for a given chunk:
|
|
@@ -151,9 +151,48 @@ class MulingstreamChunkManager {
|
|
|
151
151
|
await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
|
|
152
152
|
return true;
|
|
153
153
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
async updateSttObject(roomId, chunkNumber, newStt) {
|
|
155
|
+
// Fetch all chunks in the room
|
|
156
|
+
const chunks = await this.getMulingstreamChunksByRoom(roomId);
|
|
157
|
+
if (!chunks) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
// Locate the target chunk
|
|
161
|
+
const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
|
|
162
|
+
if (idx === -1) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
// Replace the stt object
|
|
166
|
+
chunks[idx].stt = newStt;
|
|
167
|
+
// Persist back to Redis
|
|
168
|
+
await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
async discardStt(roomId, chunkNumber) {
|
|
172
|
+
// Fetch all chunks in this room
|
|
173
|
+
const chunks = await this.getMulingstreamChunksByRoom(roomId);
|
|
174
|
+
if (!chunks) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
// Locate the desired chunk
|
|
178
|
+
const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
|
|
179
|
+
if (idx === -1) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
const chunk = chunks[idx];
|
|
183
|
+
// Reset every STT provider entry
|
|
184
|
+
for (const provider of Object.keys(chunk.stt)) {
|
|
185
|
+
chunk.stt[provider].transcription = '';
|
|
186
|
+
chunk.stt[provider].status = 'DISCARDED';
|
|
187
|
+
}
|
|
188
|
+
// Reset aggregate STT fields
|
|
189
|
+
chunk.finalTranscription = '';
|
|
190
|
+
chunk.sttStatus = 'DISCARDED';
|
|
191
|
+
// Persist back to Redis
|
|
192
|
+
chunks[idx] = chunk;
|
|
193
|
+
await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
157
196
|
async updateFinalTranscription(roomId, chunkNumber, transcription, sttStatus) {
|
|
158
197
|
const chunks = await this.getMulingstreamChunksByRoom(roomId);
|
|
159
198
|
if (!chunks)
|
|
@@ -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 [...]
|