@kelnishi/satmouse-client 0.18.0 → 0.18.2

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.
@@ -261,6 +261,7 @@ var ExtensionAdapter = class {
261
261
  onClose = null;
262
262
  onError = null;
263
263
  messageHandler = null;
264
+ pendingDeviceFetch = null;
264
265
  static isAvailable() {
265
266
  return !!globalThis.__satmouseExtensionAvailable;
266
267
  }
@@ -292,11 +293,27 @@ var ExtensionAdapter = class {
292
293
  if (msg.type === "deviceStatus" && msg.data) {
293
294
  this.onDeviceStatus?.(msg.data.event, msg.data.device);
294
295
  }
296
+ if (msg.type === "deviceList" && this.pendingDeviceFetch) {
297
+ this.pendingDeviceFetch(Array.isArray(msg.data) ? msg.data : []);
298
+ this.pendingDeviceFetch = null;
299
+ }
295
300
  };
296
301
  globalThis.addEventListener("message", this.messageHandler);
297
302
  globalThis.postMessage({ target: "satmouse-extension", action: "connect" }, "*");
298
303
  });
299
304
  }
305
+ fetchDeviceInfo() {
306
+ return new Promise((resolve) => {
307
+ this.pendingDeviceFetch = resolve;
308
+ globalThis.postMessage({ target: "satmouse-extension", action: "fetchDevices" }, "*");
309
+ setTimeout(() => {
310
+ if (this.pendingDeviceFetch) {
311
+ this.pendingDeviceFetch = null;
312
+ resolve([]);
313
+ }
314
+ }, 3e3);
315
+ });
316
+ }
300
317
  close() {
301
318
  if (this.messageHandler) {
302
319
  globalThis.removeEventListener("message", this.messageHandler);
@@ -358,8 +375,8 @@ var SatMouseConnection = class extends TypedEmitter {
358
375
  if (!wtUrl && !wsUrl) {
359
376
  const tdUrl = this.options.tdUrl;
360
377
  const tdUrls = tdUrl ? [tdUrl] : [
361
- "https://127.0.0.1:18947/td.json",
362
- "http://127.0.0.1:18945/td.json"
378
+ "http://127.0.0.1:18945/td.json",
379
+ "https://127.0.0.1:18947/td.json"
363
380
  ];
364
381
  let resolved = false;
365
382
  for (const url of tdUrls) {
@@ -377,8 +394,7 @@ var SatMouseConnection = class extends TypedEmitter {
377
394
  }
378
395
  if (!resolved) {
379
396
  this.emit("error", new Error("Failed to fetch Thing Description"));
380
- const isSecurePage = typeof globalThis.location !== "undefined" && globalThis.location.protocol === "https:";
381
- wsUrl = isSecurePage ? "wss://127.0.0.1:18947/spatial" : "ws://127.0.0.1:18945/spatial";
397
+ wsUrl = "ws://127.0.0.1:18945/spatial";
382
398
  }
383
399
  }
384
400
  for (const proto of this.options.transports) {
@@ -426,11 +442,20 @@ var SatMouseConnection = class extends TypedEmitter {
426
442
  this.setState("disconnected", "none");
427
443
  }
428
444
  async fetchDeviceInfo() {
429
- if (!this.deviceInfoUrl) return [];
430
- const res = await globalThis.fetch(this.deviceInfoUrl);
431
- if (!res.ok) return [];
432
- const data = await res.json();
433
- return data.devices ?? [];
445
+ if (this.deviceInfoUrl) {
446
+ try {
447
+ const res = await globalThis.fetch(this.deviceInfoUrl);
448
+ if (res.ok) {
449
+ const data = await res.json();
450
+ return data.devices ?? [];
451
+ }
452
+ } catch {
453
+ }
454
+ }
455
+ if (this.transport && "fetchDeviceInfo" in this.transport) {
456
+ return this.transport.fetchDeviceInfo();
457
+ }
458
+ return [];
434
459
  }
435
460
  async tryTransport(adapter) {
436
461
  adapter.onSpatialData = (data) => this.emit("spatialData", data);