@mulingai-npm/redis 2.1.1 → 2.2.0

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.
@@ -59,14 +59,7 @@ export declare class MulingstreamChunkManager {
59
59
  * or null if the room doesn't exist in Redis.
60
60
  */
61
61
  getMulingstreamChunksByRoom(roomId: string): Promise<MulingstreamChunkData[] | null>;
62
- /**
63
- * Returns the room array "as is" for debugging
64
- * (same as getMulingstreamChunksByRoom in this example).
65
- */
66
62
  getRoomById(roomId: string): Promise<MulingstreamChunkData[] | null>;
67
- /**
68
- * Adds a new Mulingstream chunk to the array stored at [${roomId}].
69
- */
70
63
  addMulingstreamChunk(params: {
71
64
  roomId: string;
72
65
  chunkNumber: number;
@@ -47,25 +47,12 @@ class MulingstreamChunkManager {
47
47
  }
48
48
  return chunks;
49
49
  }
50
- /**
51
- * Returns the room array "as is" for debugging
52
- * (same as getMulingstreamChunksByRoom in this example).
53
- */
54
50
  async getRoomById(roomId) {
55
51
  return this.getMulingstreamChunksByRoom(roomId);
56
52
  }
57
- /**
58
- * Adds a new Mulingstream chunk to the array stored at [${roomId}].
59
- */
60
53
  async addMulingstreamChunk(params) {
54
+ var _a;
61
55
  const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, theme, sttProviders, translationTargetLanguages, ttsTargetLanguages } = params;
62
- // ensure we only keep the last 5 elements
63
- const currentLength = await this.redisClient.jsonArrLen(`[${roomId}]`, '.');
64
- if ((currentLength !== null && currentLength !== void 0 ? currentLength : 0) >= ROOM_ARRAY_LENGTH) {
65
- // remove the oldest (front of the array)
66
- await this.redisClient.jsonArrPop(`[${roomId}]`, '.', 0);
67
- }
68
- // Build the chunk
69
56
  const audioChunk = {
70
57
  start,
71
58
  end,
@@ -75,25 +62,23 @@ class MulingstreamChunkManager {
75
62
  theme,
76
63
  processingStart: Date.now()
77
64
  };
78
- // Build stt object
79
65
  const stt = {};
80
- for (const svc of sttProviders) {
81
- stt[svc] = {
66
+ for (const sttProvider of sttProviders) {
67
+ stt[sttProvider] = {
82
68
  transcription: '',
83
69
  status: 'INIT'
84
70
  };
85
71
  }
86
- // Build translation and tts objects
87
72
  const translation = {};
88
73
  const tts = {};
89
- for (const language of translationTargetLanguages) {
90
- translation[language] = {
74
+ for (const lang of translationTargetLanguages) {
75
+ translation[lang] = {
91
76
  translation: '',
92
77
  status: 'INIT'
93
78
  };
94
79
  }
95
- for (const language of ttsTargetLanguages) {
96
- tts[language] = {
80
+ for (const lang of ttsTargetLanguages) {
81
+ tts[lang] = {
97
82
  ttsAudioPath: '',
98
83
  status: 'INIT',
99
84
  isEmitted: false
@@ -113,9 +98,19 @@ class MulingstreamChunkManager {
113
98
  translation,
114
99
  tts
115
100
  };
116
- // Append it to the array
117
- await this.redisClient.jsonArrAppend(`[${roomId}]`, '.', // the root of the JSON document (the array)
118
- newChunk);
101
+ const chunks = (_a = (await this.redisClient.jsonGet(`[${roomId}]`, '.'))) !== null && _a !== void 0 ? _a : [];
102
+ const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
103
+ if (idx !== -1) {
104
+ chunks[idx] = newChunk;
105
+ }
106
+ else {
107
+ chunks.push(newChunk);
108
+ if (chunks.length > ROOM_ARRAY_LENGTH) {
109
+ chunks.shift();
110
+ }
111
+ }
112
+ await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
113
+ await this.redisClient.expire(`[${roomId}]`, EXPIRATION);
119
114
  }
120
115
  /**
121
116
  * Given roomId and chunkNumber, return the single chunk from the array
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {