@mulingai-npm/redis 3.40.14 → 3.40.16

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.
@@ -11,6 +11,7 @@ export type MulingstreamSpeakerData = {
11
11
  recordingsDuration: number;
12
12
  targetLanguages: string[];
13
13
  timestamp: string;
14
+ lastHeartbeat?: number;
14
15
  isDemoSession?: boolean;
15
16
  demoExpiresAt?: number;
16
17
  };
@@ -37,6 +38,17 @@ export declare class MulingstreamSpeakerManager {
37
38
  getSpeakersLength(roomId: string): Promise<number>;
38
39
  isRoomEmpty(roomId: string): Promise<boolean>;
39
40
  updateSourceLanguage(socketId: string, newLang: string): Promise<boolean>;
41
+ /**
42
+ * Update lastHeartbeat timestamp for a speaker (called on every HEARTBEAT event from frontend).
43
+ * Returns the updated speaker, or null if not found.
44
+ * Mirrors MulingstreamListenerManager.updateHeartbeat — see MULINGSTREAM_RELIABILITY_ROADMAP.md §0.2.
45
+ */
46
+ updateHeartbeat(speakerId: string): Promise<MulingstreamSpeakerData | null>;
47
+ /**
48
+ * Update socketId for a speaker (called by heartbeat self-heal when reconnect creates a new socket).
49
+ * Mirrors the listener-side self-heal pattern — see MULINGSTREAM_RELIABILITY_ROADMAP.md §0.2.
50
+ */
51
+ updateSocketId(speakerId: string, newSocketId: string): Promise<boolean>;
40
52
  updateTargetLanguages(socketId: string, languages: string[]): Promise<boolean>;
41
53
  updateSourceLanguageByRoomId(roomId: string, newLang: string): Promise<number>;
42
54
  updateTargetLanguagesByRoomId(roomId: string, languages: string[]): Promise<number>;
@@ -33,6 +33,7 @@ class MulingstreamSpeakerManager {
33
33
  recordingsDuration: parseInt(hash.recordingsDuration, 10) || 0,
34
34
  targetLanguages: JSON.parse(hash.targetLanguages || '[]'),
35
35
  timestamp: hash.timestamp,
36
+ lastHeartbeat: hash.lastHeartbeat ? parseInt(hash.lastHeartbeat, 10) : undefined,
36
37
  isDemoSession: hash.isDemoSession === 'true',
37
38
  demoExpiresAt: parseInt(hash.demoExpiresAt, 10) || 0
38
39
  };
@@ -50,9 +51,12 @@ class MulingstreamSpeakerManager {
50
51
  targetLanguages: JSON.stringify(data.targetLanguages),
51
52
  timestamp: data.timestamp
52
53
  };
53
- if (data.roomUuid) {
54
+ if (data.roomUuid !== undefined) {
54
55
  result.roomUuid = data.roomUuid;
55
56
  }
57
+ if (data.lastHeartbeat !== undefined) {
58
+ result.lastHeartbeat = data.lastHeartbeat.toString();
59
+ }
56
60
  if (data.isDemoSession) {
57
61
  result.isDemoSession = 'true';
58
62
  }
@@ -202,6 +206,30 @@ class MulingstreamSpeakerManager {
202
206
  await this.redisClient.hset(this.buildKey(speaker.speakerId), { sourceLanguage: newLang });
203
207
  return true;
204
208
  }
209
+ /**
210
+ * Update lastHeartbeat timestamp for a speaker (called on every HEARTBEAT event from frontend).
211
+ * Returns the updated speaker, or null if not found.
212
+ * Mirrors MulingstreamListenerManager.updateHeartbeat — see MULINGSTREAM_RELIABILITY_ROADMAP.md §0.2.
213
+ */
214
+ async updateHeartbeat(speakerId) {
215
+ const speaker = await this.getSpeakerBySpeakerId(speakerId);
216
+ if (speaker === null)
217
+ return null;
218
+ const now = Date.now();
219
+ await this.redisClient.hset(this.buildKey(speakerId), { lastHeartbeat: now.toString() });
220
+ return { ...speaker, lastHeartbeat: now };
221
+ }
222
+ /**
223
+ * Update socketId for a speaker (called by heartbeat self-heal when reconnect creates a new socket).
224
+ * Mirrors the listener-side self-heal pattern — see MULINGSTREAM_RELIABILITY_ROADMAP.md §0.2.
225
+ */
226
+ async updateSocketId(speakerId, newSocketId) {
227
+ const speaker = await this.getSpeakerBySpeakerId(speakerId);
228
+ if (speaker === null)
229
+ return false;
230
+ await this.redisClient.hset(this.buildKey(speakerId), { socketId: newSocketId });
231
+ return true;
232
+ }
205
233
  async updateTargetLanguages(socketId, languages) {
206
234
  const speaker = await this.getSpeakerBySocketId(socketId);
207
235
  if (speaker === null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.40.14",
3
+ "version": "3.40.16",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {