@xiboplayer/utils 0.7.10 → 0.7.12
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.
- package/package.json +3 -3
- package/src/event-emitter.js +5 -1
- package/src/event-emitter.test.js +4 -7
- package/src/fetch-retry.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiboplayer/utils",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12",
|
|
4
4
|
"description": "Shared utilities for Xibo Player packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"./config": "./src/config.js"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@xiboplayer/crypto": "0.7.
|
|
15
|
+
"@xiboplayer/crypto": "0.7.12"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"vitest": "^
|
|
18
|
+
"vitest": "^4.1.2"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"xibo",
|
package/src/event-emitter.js
CHANGED
|
@@ -61,7 +61,11 @@ export class EventEmitter {
|
|
|
61
61
|
// Make a copy to handle listeners that remove themselves during emission
|
|
62
62
|
const listeners = this.events.get(event).slice();
|
|
63
63
|
for (const listener of listeners) {
|
|
64
|
-
|
|
64
|
+
try {
|
|
65
|
+
listener(...args);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
console.error(`[EventEmitter] Listener error on '${event}':`, err);
|
|
68
|
+
}
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
|
@@ -372,15 +372,12 @@ describe('EventEmitter', () => {
|
|
|
372
372
|
emitter.on('test', callback2);
|
|
373
373
|
emitter.on('test', callback3);
|
|
374
374
|
|
|
375
|
-
// Error in callback2
|
|
376
|
-
|
|
377
|
-
emitter.emit('test');
|
|
378
|
-
}).toThrow('Callback error');
|
|
375
|
+
// Error in callback2 is caught — does not stop other listeners
|
|
376
|
+
emitter.emit('test');
|
|
379
377
|
|
|
380
|
-
//
|
|
378
|
+
// All callbacks were called despite callback2 throwing
|
|
381
379
|
expect(callback1).toHaveBeenCalledTimes(1);
|
|
382
|
-
|
|
383
|
-
expect(callback3).not.toHaveBeenCalled();
|
|
380
|
+
expect(callback3).toHaveBeenCalledTimes(1);
|
|
384
381
|
});
|
|
385
382
|
|
|
386
383
|
it('should handle multiple events independently', () => {
|
package/src/fetch-retry.js
CHANGED
|
@@ -106,7 +106,7 @@ export async function fetchWithRetry(url, options = {}, retryOptions = {}) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
if (attempt < maxRetries) {
|
|
109
|
-
const delay = Math.min(baseDelayMs *
|
|
109
|
+
const delay = Math.min(baseDelayMs * 2 ** attempt, maxDelayMs);
|
|
110
110
|
const jitter = delay * (0.5 + Math.random() * 0.5); // 50-100% of delay
|
|
111
111
|
log.debug(`Retry ${attempt + 1}/${maxRetries} in ${Math.round(jitter)}ms:`, String(url).slice(0, 80));
|
|
112
112
|
await new Promise(resolve => setTimeout(resolve, jitter));
|