@mulingai-npm/redis 3.10.1 → 3.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.
|
@@ -62,13 +62,24 @@ class MulingstreamSpeakerManager {
|
|
|
62
62
|
speakerId,
|
|
63
63
|
timestamp: new Date(Date.now()).toISOString()
|
|
64
64
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
try {
|
|
66
|
+
// Store main speaker hash
|
|
67
|
+
const serializedData = this.serialize(speakerData);
|
|
68
|
+
await this.redisClient.hset(key, serializedData);
|
|
69
|
+
await this.redisClient.expire(key, EXPIRATION);
|
|
70
|
+
// Add to room index
|
|
71
|
+
await this.redisClient.sadd(`room:${payload.roomId}:speakers`, speakerId);
|
|
72
|
+
// Add to user index
|
|
73
|
+
await this.redisClient.sadd(`user:${payload.userId}:speakers`, speakerId);
|
|
74
|
+
// Create socket mapping
|
|
75
|
+
await this.redisClient.set(`socket:${payload.socketId}:speaker`, speakerId);
|
|
76
|
+
await this.redisClient.expire(`socket:${payload.socketId}:speaker`, EXPIRATION);
|
|
77
|
+
return speakerId;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error('❌ [addSpeaker] Error during speaker registration:', error);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
72
83
|
}
|
|
73
84
|
async removeSpeakerBySocketId(socketId) {
|
|
74
85
|
const speakerId = await this.redisClient.get(`socket:${socketId}:speaker`);
|
|
@@ -123,17 +134,27 @@ class MulingstreamSpeakerManager {
|
|
|
123
134
|
return null;
|
|
124
135
|
}
|
|
125
136
|
async getSpeakersByRoomId(roomId) {
|
|
137
|
+
console.log(`🔍 [getSpeakersByRoomId] Looking for speakers in room: ${roomId}`);
|
|
126
138
|
const ids = await this.redisClient.smembers(`room:${roomId}:speakers`);
|
|
139
|
+
console.log(`🔍 [getSpeakersByRoomId] Found speaker IDs in room index:`, ids);
|
|
127
140
|
const result = [];
|
|
128
141
|
for (const id of ids) {
|
|
129
|
-
|
|
142
|
+
console.log(`🔍 [getSpeakersByRoomId] Processing speaker ID: ${id}`);
|
|
143
|
+
const key = this.buildKey(id);
|
|
144
|
+
console.log(`🔍 [getSpeakersByRoomId] Generated key: ${key}`);
|
|
145
|
+
const hash = await this.redisClient.hgetall(key);
|
|
146
|
+
console.log(`🔍 [getSpeakersByRoomId] Retrieved hash for ${id}:`, hash);
|
|
130
147
|
if (hash !== null && Object.keys(hash).length > 0) {
|
|
131
|
-
|
|
148
|
+
const parsedSpeaker = this.parseHash(hash);
|
|
149
|
+
console.log(`✅ [getSpeakersByRoomId] Successfully parsed speaker:`, parsedSpeaker);
|
|
150
|
+
result.push(parsedSpeaker);
|
|
132
151
|
}
|
|
133
152
|
else {
|
|
153
|
+
console.log(`⚠️ [getSpeakersByRoomId] Speaker ${id} not found or empty, cleaning indexes`);
|
|
134
154
|
await this.cleanIndexes(id);
|
|
135
155
|
}
|
|
136
156
|
}
|
|
157
|
+
console.log(`🔍 [getSpeakersByRoomId] Final result for room ${roomId}:`, result);
|
|
137
158
|
return result;
|
|
138
159
|
}
|
|
139
160
|
async getSpeakersByUserId(userId) {
|