@xiboplayer/xmr 0.3.4 → 0.3.5
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/test-utils.js +1 -0
- package/src/xmr-wrapper.js +19 -6
- package/src/xmr-wrapper.test.js +35 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiboplayer/xmr",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@xibosignage/xibo-communication-framework": "^0.0.6",
|
|
12
|
-
"@xiboplayer/utils": "0.3.
|
|
12
|
+
"@xiboplayer/utils": "0.3.5"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"vitest": "^2.0.0"
|
package/src/test-utils.js
CHANGED
|
@@ -88,6 +88,7 @@ export function createMockPlayer() {
|
|
|
88
88
|
triggerWebhook: vi.fn(),
|
|
89
89
|
refreshDataConnectors: vi.fn(),
|
|
90
90
|
reportGeoLocation: vi.fn(() => Promise.resolve()),
|
|
91
|
+
requestGeoLocation: vi.fn(() => Promise.resolve({ latitude: 41.3851, longitude: 2.1734 })),
|
|
91
92
|
updateStatus: vi.fn()
|
|
92
93
|
};
|
|
93
94
|
}
|
package/src/xmr-wrapper.js
CHANGED
|
@@ -269,16 +269,29 @@ export class XmrWrapper {
|
|
|
269
269
|
});
|
|
270
270
|
|
|
271
271
|
// CMS command: Current Geo Location
|
|
272
|
+
// Dual-path: if data has coordinates, CMS is telling us our location.
|
|
273
|
+
// If data is empty/no coordinates, CMS is asking us to report our location.
|
|
272
274
|
this.xmr.on('currentGeoLocation', async (data) => {
|
|
273
275
|
log.info('Received currentGeoLocation command:', data);
|
|
274
276
|
try {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
277
|
+
const hasCoordinates = data && data.latitude != null && data.longitude != null;
|
|
278
|
+
|
|
279
|
+
if (hasCoordinates) {
|
|
280
|
+
// CMS is pushing coordinates to us
|
|
281
|
+
if (this.player.reportGeoLocation) {
|
|
282
|
+
this.player.reportGeoLocation(data);
|
|
283
|
+
log.debug('currentGeoLocation: coordinates applied');
|
|
284
|
+
} else {
|
|
285
|
+
log.warn('Geo location reporting not implemented in player');
|
|
286
|
+
}
|
|
280
287
|
} else {
|
|
281
|
-
|
|
288
|
+
// CMS is asking us to report our location via browser API
|
|
289
|
+
if (this.player.requestGeoLocation) {
|
|
290
|
+
await this.player.requestGeoLocation();
|
|
291
|
+
log.debug('currentGeoLocation: browser location requested');
|
|
292
|
+
} else {
|
|
293
|
+
log.warn('Geo location request not implemented in player');
|
|
294
|
+
}
|
|
282
295
|
}
|
|
283
296
|
} catch (error) {
|
|
284
297
|
log.error('currentGeoLocation failed:', error);
|
package/src/xmr-wrapper.test.js
CHANGED
|
@@ -362,20 +362,37 @@ describe('XmrWrapper', () => {
|
|
|
362
362
|
consoleErrorSpy.mockRestore();
|
|
363
363
|
});
|
|
364
364
|
|
|
365
|
-
it('should handle currentGeoLocation
|
|
365
|
+
it('should handle currentGeoLocation with coordinates (CMS push)', async () => {
|
|
366
366
|
const geoData = { latitude: 40.7128, longitude: -74.0060 };
|
|
367
367
|
|
|
368
368
|
xmrInstance.simulateCommand('currentGeoLocation', geoData);
|
|
369
369
|
await vi.runAllTimersAsync();
|
|
370
370
|
|
|
371
371
|
expect(mockPlayer.reportGeoLocation).toHaveBeenCalledWith(geoData);
|
|
372
|
+
expect(mockPlayer.requestGeoLocation).not.toHaveBeenCalled();
|
|
372
373
|
});
|
|
373
374
|
|
|
374
|
-
it('should handle currentGeoLocation
|
|
375
|
+
it('should handle currentGeoLocation without coordinates (CMS request)', async () => {
|
|
376
|
+
xmrInstance.simulateCommand('currentGeoLocation', {});
|
|
377
|
+
await vi.runAllTimersAsync();
|
|
378
|
+
|
|
379
|
+
expect(mockPlayer.requestGeoLocation).toHaveBeenCalled();
|
|
380
|
+
expect(mockPlayer.reportGeoLocation).not.toHaveBeenCalled();
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('should handle currentGeoLocation with null data (CMS request)', async () => {
|
|
384
|
+
xmrInstance.simulateCommand('currentGeoLocation', null);
|
|
385
|
+
await vi.runAllTimersAsync();
|
|
386
|
+
|
|
387
|
+
expect(mockPlayer.requestGeoLocation).toHaveBeenCalled();
|
|
388
|
+
expect(mockPlayer.reportGeoLocation).not.toHaveBeenCalled();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('should handle currentGeoLocation when reportGeoLocation not implemented', async () => {
|
|
375
392
|
delete mockPlayer.reportGeoLocation;
|
|
376
393
|
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
377
394
|
|
|
378
|
-
xmrInstance.simulateCommand('currentGeoLocation', {});
|
|
395
|
+
xmrInstance.simulateCommand('currentGeoLocation', { latitude: 40, longitude: -74 });
|
|
379
396
|
await vi.runAllTimersAsync();
|
|
380
397
|
|
|
381
398
|
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
@@ -385,8 +402,22 @@ describe('XmrWrapper', () => {
|
|
|
385
402
|
consoleWarnSpy.mockRestore();
|
|
386
403
|
});
|
|
387
404
|
|
|
405
|
+
it('should handle currentGeoLocation when requestGeoLocation not implemented', async () => {
|
|
406
|
+
delete mockPlayer.requestGeoLocation;
|
|
407
|
+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
408
|
+
|
|
409
|
+
xmrInstance.simulateCommand('currentGeoLocation', {});
|
|
410
|
+
await vi.runAllTimersAsync();
|
|
411
|
+
|
|
412
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
413
|
+
'[XMR]',
|
|
414
|
+
'Geo location request not implemented in player'
|
|
415
|
+
);
|
|
416
|
+
consoleWarnSpy.mockRestore();
|
|
417
|
+
});
|
|
418
|
+
|
|
388
419
|
it('should handle currentGeoLocation failure gracefully', async () => {
|
|
389
|
-
mockPlayer.
|
|
420
|
+
mockPlayer.requestGeoLocation.mockRejectedValue(new Error('Geo location failed'));
|
|
390
421
|
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
391
422
|
|
|
392
423
|
xmrInstance.simulateCommand('currentGeoLocation', {});
|