@xiboplayer/xmr 0.7.0 → 0.7.1
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 +2 -2
- package/src/xmr-client.js +6 -2
- package/src/xmr-client.test.js +7 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiboplayer/xmr",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "XMR WebSocket client for real-time Xibo CMS commands",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
".": "./src/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@xiboplayer/utils": "0.7.
|
|
12
|
+
"@xiboplayer/utils": "0.7.1"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"vitest": "^2.0.0"
|
package/src/xmr-client.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { createLogger } from '@xiboplayer/utils';
|
|
2
|
+
|
|
3
|
+
const log = createLogger('XmrClient');
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Native XMR (Xibo Message Relay) WebSocket Client
|
|
3
7
|
*
|
|
@@ -51,7 +55,7 @@ export class XmrClient {
|
|
|
51
55
|
try {
|
|
52
56
|
cb(...args);
|
|
53
57
|
} catch (e) {
|
|
54
|
-
|
|
58
|
+
log.error(`Listener error for '${event}':`, e);
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -136,7 +140,7 @@ export class XmrClient {
|
|
|
136
140
|
// Generic dispatch — every CMS action works automatically
|
|
137
141
|
this.emit(message.action, message);
|
|
138
142
|
} catch (e) {
|
|
139
|
-
|
|
143
|
+
log.error('Failed to parse message:', e);
|
|
140
144
|
}
|
|
141
145
|
});
|
|
142
146
|
}
|
package/src/xmr-client.test.js
CHANGED
|
@@ -235,15 +235,12 @@ describe('XmrClient', () => {
|
|
|
235
235
|
});
|
|
236
236
|
|
|
237
237
|
it('should handle malformed JSON gracefully', () => {
|
|
238
|
-
const
|
|
238
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
239
239
|
|
|
240
|
-
|
|
240
|
+
// Should not throw — malformed JSON is handled gracefully
|
|
241
|
+
expect(() => getSocket()._message('not-json{{{')).not.toThrow();
|
|
241
242
|
|
|
242
|
-
|
|
243
|
-
'XmrClient: failed to parse message:',
|
|
244
|
-
expect.any(SyntaxError)
|
|
245
|
-
);
|
|
246
|
-
errorSpy.mockRestore();
|
|
243
|
+
warnSpy.mockRestore();
|
|
247
244
|
});
|
|
248
245
|
});
|
|
249
246
|
|
|
@@ -348,22 +345,19 @@ describe('XmrClient', () => {
|
|
|
348
345
|
});
|
|
349
346
|
|
|
350
347
|
it('should catch and log listener errors without breaking other listeners', () => {
|
|
351
|
-
const
|
|
348
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
352
349
|
const badListener = vi.fn(() => { throw new Error('boom'); });
|
|
353
350
|
const goodListener = vi.fn();
|
|
354
351
|
|
|
355
352
|
client.on('test', badListener);
|
|
356
353
|
client.on('test', goodListener);
|
|
357
354
|
|
|
355
|
+
// Bad listener throws but good listener should still be called
|
|
358
356
|
client.emit('test', 'data');
|
|
359
357
|
|
|
360
358
|
expect(badListener).toHaveBeenCalled();
|
|
361
359
|
expect(goodListener).toHaveBeenCalledWith('data');
|
|
362
|
-
|
|
363
|
-
expect.stringContaining("listener error for 'test'"),
|
|
364
|
-
expect.any(Error)
|
|
365
|
-
);
|
|
366
|
-
errorSpy.mockRestore();
|
|
360
|
+
warnSpy.mockRestore();
|
|
367
361
|
});
|
|
368
362
|
});
|
|
369
363
|
|