@mulingai-npm/redis 1.3.2 → 1.5.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.
@@ -1,4 +1,4 @@
1
- export declare enum RedisDatabase {
2
- MULINGSTREAM_LISTENER = 0,
3
- AUDIO_STT = 1
4
- }
1
+ export declare enum RedisDatabase {
2
+ MULINGSTREAM_LISTENER = 0,
3
+ AUDIO_STT = 1
4
+ }
@@ -1,8 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisDatabase = void 0;
4
- var RedisDatabase;
5
- (function (RedisDatabase) {
6
- RedisDatabase[RedisDatabase["MULINGSTREAM_LISTENER"] = 0] = "MULINGSTREAM_LISTENER";
7
- RedisDatabase[RedisDatabase["AUDIO_STT"] = 1] = "AUDIO_STT";
8
- })(RedisDatabase = exports.RedisDatabase || (exports.RedisDatabase = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisDatabase = void 0;
4
+ var RedisDatabase;
5
+ (function (RedisDatabase) {
6
+ RedisDatabase[RedisDatabase["MULINGSTREAM_LISTENER"] = 0] = "MULINGSTREAM_LISTENER";
7
+ RedisDatabase[RedisDatabase["AUDIO_STT"] = 1] = "AUDIO_STT";
8
+ })(RedisDatabase = exports.RedisDatabase || (exports.RedisDatabase = {}));
@@ -1,28 +1,33 @@
1
- import { RedisClient } from '../redis-client';
2
- export type AudioSttData = {
3
- audioSttId: string;
4
- roomId: string;
5
- start: number;
6
- end: number;
7
- duration: number;
8
- chunkNumber: number;
9
- isFirst: boolean;
10
- isLast: boolean;
11
- language: string;
12
- theme: string;
13
- azureTranscription?: string;
14
- whisperTranscription?: string;
15
- googleTranscription?: string;
16
- processingStart: number;
17
- totalStatusCheck: number;
18
- status: 'RECEIVED' | 'DISCARDED' | 'READY' | 'USED';
19
- };
20
- export declare class AudioSttManager {
21
- private redisClient;
22
- constructor(redisClient: RedisClient);
23
- private parseHashData;
24
- addAudioStt(sttData: Omit<AudioSttData, 'audioSttId' | 'processingStart' | 'totalStatusCheck' | 'status'>): Promise<string>;
25
- getAllAudioStt(): Promise<AudioSttData[]>;
26
- getAllAudioSttByRoom(roomId: string): Promise<AudioSttData[]>;
27
- getAudioStt(audioSttId: string): Promise<AudioSttData | null>;
28
- }
1
+ import { RedisClient } from '../redis-client';
2
+ type AudioSttStatus = 'RECEIVED' | 'DISCARDED' | 'EMPTY' | 'READY' | 'USED';
3
+ export type AudioSttData = {
4
+ audioSttId: string;
5
+ roomId: string;
6
+ start: number;
7
+ end: number;
8
+ duration: number;
9
+ chunkNumber: number;
10
+ isFirst: boolean;
11
+ isLast: boolean;
12
+ language: string;
13
+ theme: string;
14
+ services: string[];
15
+ azureTranscription?: string;
16
+ whisperTranscription?: string;
17
+ googleTranscription?: string;
18
+ processingStart: number;
19
+ totalStatusCheck: number;
20
+ status: AudioSttStatus;
21
+ };
22
+ export declare class AudioSttManager {
23
+ private redisClient;
24
+ constructor(redisClient: RedisClient);
25
+ private parseHashData;
26
+ addAudioStt(sttData: Omit<AudioSttData, 'audioSttId' | 'processingStart' | 'totalStatusCheck' | 'status'>): Promise<string>;
27
+ getAllAudioStt(): Promise<AudioSttData[]>;
28
+ getAllAudioSttByRoom(roomId: string): Promise<AudioSttData[]>;
29
+ getAudioStt(audioSttId: string): Promise<AudioSttData | null>;
30
+ updateAudioSttStatus(audioSttId: string, status: AudioSttStatus): Promise<boolean>;
31
+ updateAudioSttAzureTranscription(audioSttId: string, azureTranscription: string, status: AudioSttStatus): Promise<boolean>;
32
+ }
33
+ export {};
@@ -1,101 +1,131 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AudioSttManager = void 0;
4
- const uuid_1 = require("uuid");
5
- const EXPIRATION = 4 * 60 * 60; // 4 hours in seconds
6
- class AudioSttManager {
7
- constructor(redisClient) {
8
- this.redisClient = redisClient;
9
- }
10
- parseHashData(data) {
11
- return {
12
- audioSttId: data.audioSttId,
13
- roomId: data.roomId,
14
- start: parseInt(data.start, 10),
15
- end: parseInt(data.end, 10),
16
- duration: parseInt(data.duration, 10),
17
- chunkNumber: parseInt(data.chunkNumber, 10),
18
- isFirst: data.isFirst === 'true',
19
- isLast: data.isLast === 'true',
20
- language: data.language,
21
- theme: data.theme,
22
- azureTranscription: data.azureTranscription || undefined,
23
- whisperTranscription: data.whisperTranscription || undefined,
24
- googleTranscription: data.googleTranscription || undefined,
25
- processingStart: parseInt(data.processingStart, 10),
26
- totalStatusCheck: parseInt(data.totalStatusCheck, 10),
27
- status: data.status
28
- };
29
- }
30
- // Creates a new audio-stt entry.
31
- // - Generates a unique audioSttId and adds it to the room’s set.
32
- // - Stores the data in a Redis hash under `audioStt:{audioSttId}`.
33
- // - Optionally sets an expiration (4h).
34
- async addAudioStt(sttData) {
35
- const audioSttId = `[${sttData.roomId}]-[${(0, uuid_1.v4)()}]`;
36
- // Add audioSttId to the set for that room
37
- await this.redisClient.sadd(`room:${sttData.roomId}:audioStt`, audioSttId);
38
- // Store audio-stt data in a hash
39
- await this.redisClient.hset(`audioStt:${audioSttId}`, {
40
- audioSttId,
41
- roomId: sttData.roomId,
42
- start: sttData.start.toString(),
43
- end: sttData.end.toString(),
44
- duration: sttData.duration.toString(),
45
- chunkNumber: sttData.chunkNumber.toString(),
46
- isFirst: sttData.isFirst.toString(),
47
- isLast: sttData.isLast.toString(),
48
- language: sttData.language,
49
- theme: sttData.theme,
50
- processingStart: Date.now().toString(),
51
- totalStatusCheck: (0).toString(),
52
- status: 'RECEIVED'
53
- });
54
- // Set expiration if desired
55
- await this.redisClient.expire(`audioStt:${audioSttId}`, EXPIRATION);
56
- return audioSttId;
57
- }
58
- // Retrieves *all* audio-stt entries by scanning the keys that match `audioStt:*`
59
- async getAllAudioStt() {
60
- const keys = await this.redisClient.keys('audioStt:*');
61
- if (!keys || keys.length === 0) {
62
- return [];
63
- }
64
- const results = [];
65
- for (const key of keys) {
66
- const data = await this.redisClient.hgetall(key);
67
- if (data && data.audioSttId) {
68
- results.push(this.parseHashData(data));
69
- }
70
- }
71
- return results;
72
- }
73
- // Retrieves all audio-stt entries for a specific room by looking up
74
- // the set `room:{roomId}:audioStt` and then fetching each hash.
75
- async getAllAudioSttByRoom(roomId) {
76
- const audioSttIds = await this.redisClient.smembers(`room:${roomId}:audioStt`);
77
- if (!audioSttIds || audioSttIds.length === 0) {
78
- return [];
79
- }
80
- const results = [];
81
- for (const id of audioSttIds) {
82
- const data = await this.redisClient.hgetall(`audioStt:${id}`);
83
- // if the hash doesn't exist, it may have expired, so remove from the set
84
- if (!data || Object.keys(data).length === 0) {
85
- await this.redisClient.srem(`room:${roomId}:audioStt`, id);
86
- continue;
87
- }
88
- results.push(this.parseHashData(data));
89
- }
90
- return results;
91
- }
92
- // Retrieves a single audio-stt entry by ID.
93
- async getAudioStt(audioSttId) {
94
- const data = await this.redisClient.hgetall(`audioStt:${audioSttId}`);
95
- if (!data || !data.audioSttId) {
96
- return null;
97
- }
98
- return this.parseHashData(data);
99
- }
100
- }
101
- exports.AudioSttManager = AudioSttManager;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AudioSttManager = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const EXPIRATION = 4 * 60 * 60; // 4 hours in seconds
6
+ class AudioSttManager {
7
+ constructor(redisClient) {
8
+ this.redisClient = redisClient;
9
+ }
10
+ parseHashData(data) {
11
+ return {
12
+ audioSttId: data.audioSttId,
13
+ roomId: data.roomId,
14
+ start: parseInt(data.start, 10),
15
+ end: parseInt(data.end, 10),
16
+ duration: parseInt(data.duration, 10),
17
+ chunkNumber: parseInt(data.chunkNumber, 10),
18
+ isFirst: data.isFirst === 'true',
19
+ isLast: data.isLast === 'true',
20
+ language: data.language,
21
+ theme: data.theme,
22
+ services: data.services ? JSON.parse(data.services) : [],
23
+ azureTranscription: data.azureTranscription || undefined,
24
+ whisperTranscription: data.whisperTranscription || undefined,
25
+ googleTranscription: data.googleTranscription || undefined,
26
+ processingStart: parseInt(data.processingStart, 10),
27
+ totalStatusCheck: parseInt(data.totalStatusCheck, 10),
28
+ status: data.status
29
+ };
30
+ }
31
+ // Creates a new audio-stt entry.
32
+ // - Generates a unique audioSttId and adds it to the room’s set.
33
+ // - Stores the data in a Redis hash under `audioStt:{audioSttId}`.
34
+ // - Optionally sets an expiration (4h).
35
+ async addAudioStt(sttData) {
36
+ const audioSttId = `[${sttData.roomId}]-[${(0, uuid_1.v4)()}]`;
37
+ const servicesJson = sttData.services ? JSON.stringify(sttData.services) : '[]';
38
+ // Add audioSttId to the set for that room
39
+ await this.redisClient.sadd(`room:${sttData.roomId}:audioStt`, audioSttId);
40
+ // Store audio-stt data in a hash
41
+ await this.redisClient.hset(`audioStt:${audioSttId}`, {
42
+ audioSttId,
43
+ roomId: sttData.roomId,
44
+ start: sttData.start.toString(),
45
+ end: sttData.end.toString(),
46
+ duration: sttData.duration.toString(),
47
+ chunkNumber: sttData.chunkNumber.toString(),
48
+ isFirst: sttData.isFirst.toString(),
49
+ isLast: sttData.isLast.toString(),
50
+ language: sttData.language,
51
+ theme: sttData.theme,
52
+ services: servicesJson,
53
+ processingStart: Date.now().toString(),
54
+ totalStatusCheck: (0).toString(),
55
+ status: 'RECEIVED'
56
+ });
57
+ // Set expiration if desired
58
+ await this.redisClient.expire(`audioStt:${audioSttId}`, EXPIRATION);
59
+ return audioSttId;
60
+ }
61
+ // Retrieves *all* audio-stt entries by scanning the keys that match `audioStt:*`
62
+ async getAllAudioStt() {
63
+ const keys = await this.redisClient.keys('audioStt:*');
64
+ if (!keys || keys.length === 0) {
65
+ return [];
66
+ }
67
+ const results = [];
68
+ for (const key of keys) {
69
+ const data = await this.redisClient.hgetall(key);
70
+ if (data && data.audioSttId) {
71
+ results.push(this.parseHashData(data));
72
+ }
73
+ }
74
+ return results;
75
+ }
76
+ // Retrieves all audio-stt entries for a specific room by looking up
77
+ // the set `room:{roomId}:audioStt` and then fetching each hash.
78
+ async getAllAudioSttByRoom(roomId) {
79
+ const audioSttIds = await this.redisClient.smembers(`room:${roomId}:audioStt`);
80
+ if (!audioSttIds || audioSttIds.length === 0) {
81
+ return [];
82
+ }
83
+ const results = [];
84
+ for (const id of audioSttIds) {
85
+ const data = await this.redisClient.hgetall(`audioStt:${id}`);
86
+ // if the hash doesn't exist, it may have expired, so remove from the set
87
+ if (!data || Object.keys(data).length === 0) {
88
+ await this.redisClient.srem(`room:${roomId}:audioStt`, id);
89
+ continue;
90
+ }
91
+ results.push(this.parseHashData(data));
92
+ }
93
+ return results;
94
+ }
95
+ // Retrieves a single audio-stt entry by ID.
96
+ async getAudioStt(audioSttId) {
97
+ const data = await this.redisClient.hgetall(`audioStt:${audioSttId}`);
98
+ if (!data || !data.audioSttId) {
99
+ return null;
100
+ }
101
+ return this.parseHashData(data);
102
+ }
103
+ async updateAudioSttStatus(audioSttId, status) {
104
+ // Attempt to fetch the data first
105
+ const data = await this.redisClient.hgetall(`audioStt:${audioSttId}`);
106
+ if (!data || !data.audioSttId) {
107
+ // AudioStt either doesn’t exist or has expired
108
+ return false;
109
+ }
110
+ // update the status field
111
+ await this.redisClient.hset(`audioStt:${audioSttId}`, {
112
+ status
113
+ });
114
+ return true;
115
+ }
116
+ async updateAudioSttAzureTranscription(audioSttId, azureTranscription, status) {
117
+ // Attempt to fetch the data first
118
+ const data = await this.redisClient.hgetall(`audioStt:${audioSttId}`);
119
+ if (!data || !data.audioSttId) {
120
+ // AudioStt either doesn’t exist or has expired
121
+ return false;
122
+ }
123
+ // Update the azureTranscription and status fields
124
+ await this.redisClient.hset(`audioStt:${audioSttId}`, {
125
+ azureTranscription,
126
+ status
127
+ });
128
+ return true;
129
+ }
130
+ }
131
+ exports.AudioSttManager = AudioSttManager;
@@ -1,24 +1,24 @@
1
- import { RedisClient } from '../redis-client';
2
- export type MulingstreamListenerData = {
3
- listenerId: string;
4
- roomId: string;
5
- socketId?: string;
6
- token: string;
7
- name?: string;
8
- firstJoined: number;
9
- language?: string;
10
- isActive?: boolean;
11
- };
12
- export declare class MulingstreamListenerManager {
13
- private redisClient;
14
- constructor(redisClient: RedisClient);
15
- private parseHashData;
16
- addListener(listenerData: Omit<MulingstreamListenerData, 'listenerId'>): Promise<string>;
17
- getAllListeners(): Promise<MulingstreamListenerData[]>;
18
- getListenersByRoom(roomId: string): Promise<MulingstreamListenerData[]>;
19
- getListener(listenerIdOrToken: string): Promise<MulingstreamListenerData | null>;
20
- removeListenerByToken(token: string): Promise<boolean>;
21
- updateNameLanguage(listenerIdOrToken: string, name: string, language: string): Promise<boolean>;
22
- updateSocketId(listenerIdOrToken: string, socketId: string): Promise<boolean>;
23
- getTargetSocketIdsByRoomLanguage(roomId: string, language: string): Promise<string[]>;
24
- }
1
+ import { RedisClient } from '../redis-client';
2
+ export type MulingstreamListenerData = {
3
+ listenerId: string;
4
+ roomId: string;
5
+ socketId?: string;
6
+ token: string;
7
+ name?: string;
8
+ firstJoined: number;
9
+ language?: string;
10
+ isActive?: boolean;
11
+ };
12
+ export declare class MulingstreamListenerManager {
13
+ private redisClient;
14
+ constructor(redisClient: RedisClient);
15
+ private parseHashData;
16
+ addListener(listenerData: Omit<MulingstreamListenerData, 'listenerId'>): Promise<string>;
17
+ getAllListeners(): Promise<MulingstreamListenerData[]>;
18
+ getListenersByRoom(roomId: string): Promise<MulingstreamListenerData[]>;
19
+ getListener(listenerIdOrToken: string): Promise<MulingstreamListenerData | null>;
20
+ removeListenerByToken(token: string): Promise<boolean>;
21
+ updateNameLanguage(listenerIdOrToken: string, name: string, language: string): Promise<boolean>;
22
+ updateSocketId(listenerIdOrToken: string, socketId: string): Promise<boolean>;
23
+ getTargetSocketIdsByRoomLanguage(roomId: string, language: string): Promise<string[]>;
24
+ }