@mulingai-npm/redis 3.23.1 → 3.23.3
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.
|
@@ -2,6 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MulingstreamListenerManager = void 0;
|
|
4
4
|
const EXPIRATION = 24 * 60 * 60; // 24 hours in seconds
|
|
5
|
+
/**
|
|
6
|
+
* Generates a bright RGB color suitable for dark backgrounds.
|
|
7
|
+
* Algorithm:
|
|
8
|
+
* 1. Random 1-3: how many RGB channels to give random values (180-255)
|
|
9
|
+
* 2. Remaining channels stay at 255 (max brightness)
|
|
10
|
+
* 3. Randomly select which channels get the random values
|
|
11
|
+
* 4. Each selected channel gets a random value from 180-255
|
|
12
|
+
*
|
|
13
|
+
* This ensures colors are always bright enough to be visible on dark backgrounds.
|
|
14
|
+
* @returns RGB color string in format "R,G,B" (e.g., "193,255,221")
|
|
15
|
+
*/
|
|
16
|
+
function generateBrightColor() {
|
|
17
|
+
// Start with all channels at max brightness
|
|
18
|
+
const rgb = [255, 255, 255];
|
|
19
|
+
// Random 1-3: how many channels to modify
|
|
20
|
+
const channelsToModify = Math.floor(Math.random() * 3) + 1;
|
|
21
|
+
// Create array of channel indices [0, 1, 2] and shuffle
|
|
22
|
+
const channelIndices = [0, 1, 2];
|
|
23
|
+
for (let i = channelIndices.length - 1; i > 0; i--) {
|
|
24
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
25
|
+
[channelIndices[i], channelIndices[j]] = [channelIndices[j], channelIndices[i]];
|
|
26
|
+
}
|
|
27
|
+
// Modify the selected number of channels with random values 180-255
|
|
28
|
+
for (let i = 0; i < channelsToModify; i++) {
|
|
29
|
+
const channelIndex = channelIndices[i];
|
|
30
|
+
rgb[channelIndex] = Math.floor(Math.random() * (255 - 180 + 1)) + 180;
|
|
31
|
+
}
|
|
32
|
+
return `${rgb[0]},${rgb[1]},${rgb[2]}`;
|
|
33
|
+
}
|
|
5
34
|
class MulingstreamListenerManager {
|
|
6
35
|
constructor(redisClient) {
|
|
7
36
|
this.redisClient = redisClient;
|
|
@@ -15,7 +44,8 @@ class MulingstreamListenerManager {
|
|
|
15
44
|
name: data.name || '',
|
|
16
45
|
firstJoined: parseInt(data.firstJoined, 10),
|
|
17
46
|
lastHeartbeat: parseInt(data.lastHeartbeat, 10),
|
|
18
|
-
language: data.language || ''
|
|
47
|
+
language: data.language || '',
|
|
48
|
+
color: data.color || ''
|
|
19
49
|
};
|
|
20
50
|
}
|
|
21
51
|
// Creates a new listener.
|
|
@@ -25,6 +55,8 @@ class MulingstreamListenerManager {
|
|
|
25
55
|
var _a, _b, _c;
|
|
26
56
|
// You can combine roomId + uuid, or just a uuid, up to you:
|
|
27
57
|
const listenerId = listenerData.listenerId;
|
|
58
|
+
// Generate a unique bright color for this listener's activity log
|
|
59
|
+
const color = generateBrightColor();
|
|
28
60
|
// Add listenerId to the set for that room
|
|
29
61
|
await this.redisClient.sadd(`room:${listenerData.roomId}:listeners`, listenerId);
|
|
30
62
|
// Store listener data in a hash
|
|
@@ -36,7 +68,8 @@ class MulingstreamListenerManager {
|
|
|
36
68
|
name: (_b = listenerData.name) !== null && _b !== void 0 ? _b : '',
|
|
37
69
|
firstJoined: listenerData.firstJoined.toString(),
|
|
38
70
|
lastHeartbeat: listenerData.lastHeartbeat.toString(),
|
|
39
|
-
language: (_c = listenerData.language) !== null && _c !== void 0 ? _c : ''
|
|
71
|
+
language: (_c = listenerData.language) !== null && _c !== void 0 ? _c : '',
|
|
72
|
+
color
|
|
40
73
|
});
|
|
41
74
|
// expire listener
|
|
42
75
|
await this.redisClient.expire(`listener:${listenerId}`, EXPIRATION);
|