@mulingai-npm/redis 3.40.19 → 3.40.21

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.
@@ -79,6 +79,13 @@ export declare class MulingstreamChunkManager {
79
79
  initRoom(roomId: string): Promise<boolean>;
80
80
  getRooms(): Promise<string[]>;
81
81
  getMulingstreamChunksByRoom(roomId: string): Promise<MulingstreamChunkData[] | null>;
82
+ /**
83
+ * Return the most recent `limit` chunks for a room, ordered oldest → newest.
84
+ * Used by the /translation-history and /transcription-history endpoints
85
+ * (§0.8) to prime listeners' panels when they switch language or toggle
86
+ * Speaker's Words on.
87
+ */
88
+ getRecentChunks(roomId: string, limit: number): Promise<MulingstreamChunkData[]>;
82
89
  getRoomById(roomId: string): Promise<MulingstreamChunkData[]>;
83
90
  /**
84
91
  * Add a streaming chunk with STT already completed
@@ -73,6 +73,25 @@ class MulingstreamChunkManager {
73
73
  return null;
74
74
  return res === null || res === void 0 ? void 0 : res.map(([, d]) => this.hashToChunk(d));
75
75
  }
76
+ /**
77
+ * Return the most recent `limit` chunks for a room, ordered oldest → newest.
78
+ * Used by the /translation-history and /transcription-history endpoints
79
+ * (§0.8) to prime listeners' panels when they switch language or toggle
80
+ * Speaker's Words on.
81
+ */
82
+ async getRecentChunks(roomId, limit) {
83
+ if (limit <= 0)
84
+ return [];
85
+ const ids = await this.redisClient.zrange(this.roomZsetKey(roomId), -limit, -1);
86
+ if (!ids.length)
87
+ return [];
88
+ const pipe = this.redisClient.pipeline();
89
+ ids.forEach((cid) => pipe.hgetall(this.chunkHashKey(cid)));
90
+ const res = await pipe.exec();
91
+ if (!res)
92
+ return [];
93
+ return res.map(([, d]) => this.hashToChunk(d));
94
+ }
76
95
  getRoomById(roomId) {
77
96
  return this.getMulingstreamChunksByRoom(roomId);
78
97
  }
@@ -1,4 +1,5 @@
1
1
  import { RedisClient } from '../redis-client';
2
+ export type ListenerBreakpoint = 'mobile' | 'desktop' | 'display';
2
3
  export type MulingstreamListenerData = {
3
4
  listenerId: string;
4
5
  roomId: string;
@@ -10,6 +11,7 @@ export type MulingstreamListenerData = {
10
11
  language?: string;
11
12
  color?: string;
12
13
  isListening?: boolean;
14
+ breakpoint?: ListenerBreakpoint;
13
15
  };
14
16
  export declare class MulingstreamListenerManager {
15
17
  private redisClient;
@@ -22,6 +24,11 @@ export declare class MulingstreamListenerManager {
22
24
  removeListener(tokenOrListenerId: string): Promise<MulingstreamListenerData | null>;
23
25
  updateNameLanguage(listenerIdOrToken: string, name: string, language: string): Promise<MulingstreamListenerData | null>;
24
26
  updateSocketId(listenerIdOrToken: string, socketId: string): Promise<MulingstreamListenerData | null>;
27
+ /**
28
+ * Update viewport breakpoint. Called on LISTENER_JOINED and on UPDATE_BREAKPOINT
29
+ * (resize crossing the 1024px threshold). Drives Socket.IO room membership (§0.8).
30
+ */
31
+ updateBreakpoint(listenerIdOrToken: string, breakpoint: ListenerBreakpoint): Promise<MulingstreamListenerData | null>;
25
32
  getTargetSocketIdsByRoomLanguage(roomId: string, language: string): Promise<string[]>;
26
33
  getUniqueLanguagesByRoom(roomId: string): Promise<string[]>;
27
34
  updateHeartbeat(listenerIdOrToken: string): Promise<MulingstreamListenerData | null>;
@@ -36,6 +36,7 @@ class MulingstreamListenerManager {
36
36
  this.redisClient = redisClient;
37
37
  }
38
38
  parseHashData(data) {
39
+ const bp = data.breakpoint;
39
40
  return {
40
41
  listenerId: data.listenerId,
41
42
  roomId: data.roomId,
@@ -46,14 +47,15 @@ class MulingstreamListenerManager {
46
47
  lastHeartbeat: parseInt(data.lastHeartbeat, 10),
47
48
  language: data.language || '',
48
49
  color: data.color || '',
49
- isListening: data.isListening === 'true'
50
+ isListening: data.isListening === 'true',
51
+ breakpoint: bp === 'mobile' || bp === 'desktop' || bp === 'display' ? bp : undefined
50
52
  };
51
53
  }
52
54
  // Creates a new listener.
53
55
  // -Generates a unique listenerId and adds it to the room's set.
54
56
  // -Stores the listener data in a Redis hash under `listener:{listenerId}`.
55
57
  async addListener(listenerData) {
56
- var _a, _b, _c;
58
+ var _a, _b, _c, _d;
57
59
  // You can combine roomId + uuid, or just a uuid, up to you:
58
60
  const listenerId = listenerData.listenerId;
59
61
  // Generate a unique bright color for this listener's activity log
@@ -71,7 +73,8 @@ class MulingstreamListenerManager {
71
73
  lastHeartbeat: listenerData.lastHeartbeat.toString(),
72
74
  language: (_c = listenerData.language) !== null && _c !== void 0 ? _c : '',
73
75
  color,
74
- isListening: 'false'
76
+ isListening: 'false',
77
+ breakpoint: (_d = listenerData.breakpoint) !== null && _d !== void 0 ? _d : ''
75
78
  });
76
79
  // expire listener
77
80
  await this.redisClient.expire(`listener:${listenerId}`, EXPIRATION);
@@ -166,6 +169,18 @@ class MulingstreamListenerManager {
166
169
  });
167
170
  return { ...listener, socketId };
168
171
  }
172
+ /**
173
+ * Update viewport breakpoint. Called on LISTENER_JOINED and on UPDATE_BREAKPOINT
174
+ * (resize crossing the 1024px threshold). Drives Socket.IO room membership (§0.8).
175
+ */
176
+ async updateBreakpoint(listenerIdOrToken, breakpoint) {
177
+ const listener = await this.getListener(listenerIdOrToken);
178
+ if (!listener) {
179
+ return null;
180
+ }
181
+ await this.redisClient.hset(`listener:${listener.listenerId}`, { breakpoint });
182
+ return { ...listener, breakpoint };
183
+ }
169
184
  async getTargetSocketIdsByRoomLanguage(roomId, language) {
170
185
  const listeners = await this.getListenersByRoom(roomId);
171
186
  const filteredListeners = listeners.filter((listener) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.40.19",
3
+ "version": "3.40.21",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {