@mulingai-npm/redis 2.10.0 → 2.11.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.
@@ -53,6 +53,7 @@ class MulingstreamChunkManager {
53
53
  async addMulingstreamChunk(params) {
54
54
  var _a;
55
55
  const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, theme, sttProviders, targetLanguages, shortCodeTargetLanguages } = params;
56
+ /* ---------- build chunk skeleton ---------- */
56
57
  const audioChunk = {
57
58
  start,
58
59
  end,
@@ -63,25 +64,14 @@ class MulingstreamChunkManager {
63
64
  processingStart: Date.now()
64
65
  };
65
66
  const stt = {};
66
- for (const sttProvider of sttProviders) {
67
- stt[sttProvider] = {
68
- transcription: '',
69
- status: 'INIT'
70
- };
67
+ for (const p of sttProviders) {
68
+ stt[p] = { transcription: '', status: 'INIT' };
71
69
  }
72
70
  const translation = {};
73
71
  const tts = {};
74
72
  for (const lang of shortCodeTargetLanguages) {
75
- translation[lang] = {
76
- translation: '',
77
- status: 'INIT'
78
- };
79
- tts[lang] = {
80
- ttsAudioPath: '',
81
- status: 'INIT',
82
- isEmitted: false,
83
- totalCheck: 0
84
- };
73
+ translation[lang] = { translation: '', status: 'INIT' };
74
+ tts[lang] = { ttsAudioPath: '', status: 'INIT', isEmitted: false, totalCheck: 0 };
85
75
  }
86
76
  const newChunk = {
87
77
  roomId,
@@ -98,17 +88,23 @@ class MulingstreamChunkManager {
98
88
  translation,
99
89
  tts
100
90
  };
101
- const chunks = (_a = (await this.redisClient.jsonGet(`[${roomId}]`, '.'))) !== null && _a !== void 0 ? _a : [];
91
+ /* ---------- pull existing room array ---------- */
92
+ let chunks = (_a = (await this.redisClient.jsonGet(`[${roomId}]`, '.'))) !== null && _a !== void 0 ? _a : [];
93
+ /* ---------- reset the room if this is the first chunk ---------- */
94
+ if (chunkNumber === 1) {
95
+ chunks = []; // start fresh
96
+ }
97
+ /* ---------- insert / replace ---------- */
102
98
  const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
103
99
  if (idx !== -1) {
104
100
  chunks[idx] = newChunk;
105
101
  }
106
102
  else {
107
103
  chunks.push(newChunk);
108
- if (chunks.length > ROOM_ARRAY_LENGTH) {
104
+ if (chunks.length > ROOM_ARRAY_LENGTH)
109
105
  chunks.shift();
110
- }
111
106
  }
107
+ /* ---------- persist ---------- */
112
108
  await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
113
109
  await this.redisClient.expire(`[${roomId}]`, EXPIRATION);
114
110
  }
@@ -436,6 +432,7 @@ class MulingstreamChunkManager {
436
432
  for (let i = lastDone + 1; i < window.length; i++) {
437
433
  const entry = window[i].tts[language];
438
434
  if (entry.status === 'INIT') {
435
+ console.log(window[i].createdAt, ' --- ', window[i].chunkNumber);
439
436
  if (now - window[i].createdAt > timeoutMs) {
440
437
  entry.status = 'DISCARDED';
441
438
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {