@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiboplayer/xmr",
3
- "version": "0.3.4",
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.4"
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
  }
@@ -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
- // Report current geo location to CMS
276
- // For now, log the request - actual implementation would use navigator.geolocation
277
- if (this.player.reportGeoLocation) {
278
- await this.player.reportGeoLocation(data);
279
- log.debug('currentGeoLocation completed successfully');
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
- log.warn('Geo location reporting not implemented in player');
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);
@@ -362,20 +362,37 @@ describe('XmrWrapper', () => {
362
362
  consoleErrorSpy.mockRestore();
363
363
  });
364
364
 
365
- it('should handle currentGeoLocation command', async () => {
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 when not implemented', async () => {
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.reportGeoLocation.mockRejectedValue(new Error('Geo location failed'));
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', {});