tkadkghdlf commited on
Commit
febbdb9
ยท
verified ยท
1 Parent(s): 60b4cda

Sync DemoService c98fcc7b9b8bb1b2184dd084eadce9dd260a861e

Browse files
docs/WEAR_CONNECTION_V37.md ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ๋ชจ๋ฐ”์ผ v37: ์—ฐ๊ฒฐ ์ƒํƒœ ๊ณ ์ฐฉ ์ˆ˜์ •
2
+
3
+ ## ์›์ธ๊ณผ ๋ณ€๊ฒฝ
4
+
5
+ ๊ธฐ์กด ๋ชจ๋ฐ”์ผ์€ Data Layer ๋…ธ๋“œ๊ฐ€ ํ•˜๋‚˜๋ผ๋„ ์žˆ์œผ๋ฉด `connected=true`๋กœ ๋งŒ๋“ค์—ˆ๋‹ค. ์•ฑ์˜ ping ์‘๋‹ต ์—ฌ๋ถ€์™€ ๋ฌด๊ด€ํ–ˆ๊ณ , capability/์ด์ „ ready ์บ์‹œ๋ฅผ ํ˜„์žฌ ์—ฐ๊ฒฐ์˜ ๊ทผ๊ฑฐ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ์›น์˜ 5์ดˆ ์กฐํšŒ๋งŒ ์žˆ์—ˆ๊ณ  ํœด๋Œ€ํฐ ์—ฐ๊ฒฐ ๋ณ€ํ™” ์ด๋ฒคํŠธ๊ฐ€ ์›น ์ƒํƒœ๋ฅผ ๋ฌดํšจํ™”ํ•˜์ง€ ์•Š์•˜๋‹ค.
6
+
7
+ - `connected`๋Š” ์ด๋ฒˆ ์กฐํšŒ๋ฅผ ์‹œ์ž‘ํ•œ ์ดํ›„ ๋ฐ›์€ ์›Œ์น˜ ready ์‘๋‹ต์œผ๋กœ๋งŒ ํŒ์ •ํ•œ๋‹ค. ์ €์žฅ๋œ 15์ดˆ ready TTL์€ ์ œ๊ฑฐํ–ˆ๋‹ค. capability๋Š” ์„ค์น˜ ์—ฌ๋ถ€์˜ ๋ณด์กฐ ์ •๋ณด์ด๋ฉฐ ์—ฐ๊ฒฐ ์ฆ๋ช…์ด ์•„๋‹ˆ๋‹ค.
8
+ - 2์ดˆ probe ํ›„ ๋…ธ๋“œ ๋ชฉ๋ก์„ ๋‹ค์‹œ ์กฐํšŒํ•˜์—ฌ ์‹œ์ž‘ ์‹œ์ ์˜ ๋…ธ๋“œ ๋ชฉ๋ก์„ ๊ทธ๋Œ€๋กœ ์žฌ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. ๋ฌด์‘๋‹ต ๋…ธ๋“œ๋Š” '์›Œ์น˜ ์‘๋‹ต ํ™•์ธ ์•ˆ ๋จ'์œผ๋กœ ํ‘œ์‹œํ•œ๋‹ค.
9
+ - Bluetooth ์ „์› ๋ณ€ํ™”, OS๊ฐ€ ์ „๋‹ฌํ•œ ACL ๋ณ€ํ™”, Wear capability/peer ๋ณ€ํ™” ์ˆ˜์‹  ์‹œ ์ฆ‰์‹œ ๊ธฐ์กด ํ‘œ์‹œ๋ฅผ ๋ฌดํšจํ™”ํ•˜๊ณ  ์กฐํšŒํ•œ๋‹ค. Bluetooth ACL ์ด๋ฒคํŠธ๋Š” OS ๊ถŒํ•œ/์ „๋‹ฌ ์ •์ฑ…์— ๋”ฐ๋ผ ์˜ค์ง€ ์•Š์„ ์ˆ˜ ์žˆ์–ด capability ์ด๋ฒคํŠธ์™€ ์ฃผ๊ธฐ ์กฐํšŒ๋ฅผ ๋ณ‘ํ–‰ํ•œ๋‹ค.
10
+ - ์กฐํšŒ ๋„์ค‘ ์—ฐ๊ฒฐ ๋ณ€ํ™”๊ฐ€ ์ƒ๊ธฐ๋ฉด generation์ด ๋‹ฌ๋ผ์ง„ ์ด์ „ ์กฐํšŒ ๊ฒฐ๊ณผ๋ฅผ ๋ฒ„๋ฆฌ๊ณ  ๋‹ค์‹œ ์กฐํšŒํ•œ๋‹ค.
11
+ - ํ™”๋ฉด์ด ๋ณด์ผ ๋•Œ 3์ดˆ ํด๋ง, 8์ดˆ ์‘๋‹ต ๋งŒ๋ฃŒ. ๋ธŒ๋ฆฌ์ง€ ์žฌ์—ฐ๊ฒฐ ์‹œ์—๋„ ๊ธฐ์กด ์ƒํƒœ๋ฅผ ์žฌํ™•์ธํ•œ๋‹ค. ์›น์—์„œ๋„ ์ด์ „ ์‹œ๊ฐ์˜ ์ƒํƒœ ํŒจํ‚ท์ด ์ตœ์‹  ์ƒํƒœ๋ฅผ ๋ฎ์–ด์“ฐ์ง€ ๋ชปํ•˜๊ฒŒ ํ•œ๋‹ค.
12
+ - Bluetooth ์ „์›์ด ๊บผ์กŒ๋‹ค๋Š” ์ด๋ฒคํŠธ์™€ ์‹ค์ œ ์›Œ์น˜ ์•ฑ ํ†ต์‹ ์€ ๋ถ„๋ฆฌํ•œ๋‹ค. Wi-Fi ๊ฒฝ์œ  fresh ์‘๋‹ต์ด ์žˆ์œผ๋ฉด '์›Œ์น˜ ์—ฐ๊ฒฐ๋จ ยท Bluetooth ๊บผ์ง'์„ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๋‹ค.
13
+
14
+ OS ์ด๋ฒคํŠธ๋ฅผ ๋ฐ›์€ ๋’ค UI๋ฅผ ์ฆ‰์‹œ ๋ฌดํšจํ™”ํ•˜๋Š” ๊ฒƒ์ด๋ฉฐ, ๋ฌผ๋ฆฌ์  ์—ฐ๊ฒฐ ๋ณ€ํ™” ๊ฐ์ง€์™€ ์‹ค์ œ ์žฌํ™•์ธ๊นŒ์ง€ 0ms๋ผ๊ณ  ๋ณด์žฅํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ๊ฐ€ ๋ˆ„๋ฝ๋˜๋ฉด ์ฃผ๊ธฐ ์กฐํšŒ์™€ ์‘๋‹ต ๋งŒ๋ฃŒ๊ฐ€ ๋ณด์™„ํ•œ๋‹ค. ๋ฌด์‘๋‹ต์€ ์—ฐ๊ฒฐ ํ•ด์ œ๋ฅผ ํ™•์ •ํ•œ ๊ฒƒ๊ณผ ๊ตฌ๋ถ„ํ•œ๋‹ค.
15
+
16
+ ๊ณต์‹ API ์ฐธ๊ณ : [WearableListenerService](https://developers.google.com/android/reference/com/google/android/gms/wearable/WearableListenerService), [BluetoothAdapter.ACTION_STATE_CHANGED](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#ACTION_STATE_CHANGED).
17
+
18
+ ## ์„ค์น˜ ํŒŒ์ผ
19
+
20
+ - DemoService: `releases/android/RunTheShape-v37-debug.apk`
21
+ - package: `space.hf.tkadkghdlf_cd.twa`, versionCode/versionName 37
22
+ - ์ธ์ฆ์„œ SHA-256: `814132ac537a68557268187d92d2c3416d1e9fc0f4f7236d54ce050a179ba54c`
23
+ - APK SHA-256: `75ed9961ca89affdff81b4a435d04211ab414536eaede4506a48992102c4047d`
24
+ - ๋ชจ๋ฐ”์ผ v35/v36์™€ ๋™์ผ ์„œ๋ช…์ด๋ฉฐ ์—…๋ฐ์ดํŠธ ๊ฐ€๋Šฅ. v36 ๋Ÿฌ๋‹ ๋™๊ธฐํ™” ์ˆ˜์ • ํฌํ•จ.
25
+ - ์ด๋ฒˆ ์ˆ˜์ •์€ ์›Œ์น˜ ์†Œ์Šค/ํšŒ์ „ ์„ค์ •/๊ธฐ๊ธฐ ์„ค์น˜๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š”๋‹ค. ์—ฐ๊ฒฐ ํ™•์ธ์€ ๊ธฐ์กด ping/ready ๊ทœ์•ฝ๊ณผ ํ˜ธํ™˜๋œ๋‹ค. ์•ž์„  ๋Ÿฌ๋‹ ๋™๊ธฐํ™” ๊ฐœ์„ ์—๋Š” ์›Œ์น˜ v3๊ฐ€ ๋ณ„๋„๋กœ ํ•„์š”ํ•˜๋‹ค.
26
+
27
+ ## ๊ฒ€์ฆ
28
+
29
+ ๋ชจ๋ฐ”์ผ assembleDebug ๋ฐ apksigner ๊ฒ€์ฆ, TypeScript ๊ฒ€์‚ฌ, ์›น ํ”„๋กœ๋•์…˜ ๋นŒ๋“œ, nativeWearBootstrap/twaNativeContract/nativeAppVisibility/wearConnectionState ํšŒ๊ท€ ํ…Œ์ŠคํŠธ ํ†ต๊ณผ. ํ…Œ์ŠคํŠธ์—๋Š” ์บ์‹œ ๋งŒ๋ฃŒ, ๋ณ€ํ™” ์ค‘ ์กฐํšŒ ๋ฌดํšจํ™”์˜ ์†Œ์Šค ๊ณ„์•ฝ, ๋Šฆ์€ ์—ฐ๊ฒฐ ์‘๋‹ต ๋ฌด์‹œ, Bluetooth off + ์œ ํšจ ์‘๋‹ต ๊ตฌ๋ถ„์ด ํฌํ•จ๋œ๋‹ค. ์‹ค์ œ Bluetooth ๋Š๊ธฐ/์žฌ์—ฐ๊ฒฐ ํ…Œ์ŠคํŠธ๋Š” ์‚ฌ์šฉ์ž ํ™•์ธ ์˜ˆ์ •์ด๋‹ค.
30
+
31
+ ์ตœ์‹  ์›น ๋ฐฐํฌ์™€ ๋ชจ๋ฐ”์ผ v37 ์„ค์น˜ ํ›„:
32
+
33
+ 1. ์•ฑ ๋กœ๋น„์—์„œ ์—ฐ๊ฒฐ ํ‘œ์‹œ ํ™•์ธ.
34
+ 2. Bluetooth ๋„๊ธฐ: ๊ธฐ์กด ํ‘œ์‹œ๊ฐ€ ์žฌํ™•์ธ์œผ๋กœ ์ „ํ™˜๋˜๋Š”์ง€ ํ™•์ธ. Wi-Fi๋กœ ์‘๋‹ตํ•˜๋ฉด ์—ฐ๊ฒฐ ํ‘œ์‹œ ์œ ์ง€๊ฐ€ ์ •์ƒ์ด๋ฉฐ Bluetooth ๊บผ์ง์„ ํ•จ๊ป˜ ํ‘œ์‹œํ•œ๋‹ค.
35
+ 3. ์›Œ์น˜์˜ Bluetooth/Wi-Fi๋ฅผ ๋ชจ๋‘ ๋„๊ฑฐ๋‚˜ ์›Œ์น˜ ์ „์›์„ ๊บผ ์‹ค์ œ ํ†ต์‹  ์ฐจ๋‹จ: ์—ฐ๊ฒฐ๋จ์ด ์œ ์ง€๋˜์ง€ ์•Š๊ณ  ๋ฌด์‘๋‹ต/์—ฐ๊ฒฐ ์•ˆ ๋จ์œผ๋กœ ๋ฐ”๋€Œ์–ด์•ผ ํ•œ๋‹ค.
36
+ 4. ํ†ต์‹  ๋ณต์›: ์ƒˆ๋กœ๊ณ ์นจ ์—†์ด ์ƒˆ๋กœ์šด ์‘๋‹ต์œผ๋กœ ์—ฐ๊ฒฐ๋จ ํ‘œ์‹œ ํšŒ๋ณต.
37
+ 5. ํ™”๋ฉด์„ ์ˆจ๊ฒผ๋‹ค๊ฐ€ ๋Œ์•„์˜ค๊ฑฐ๋‚˜ ์•ฑ ์žฌ์‹คํ–‰: ์˜ค๋ž˜๋œ ํ‘œ์‹œ๊ฐ€ ๊ณ„์† ๋‚จ์ง€ ์•Š๋Š”์ง€ ํ™•์ธ.
38
+
39
+ Git ํ‘ธ์‹œ๋Š” ์›น ๋ฐฐํฌ ์„ฑ๊ณต ๋˜๋Š” APK ๊ธฐ๊ธฐ ์„ค์น˜๋ฅผ ์˜๋ฏธํ•˜์ง€ ์•Š๋Š”๋‹ค.
main/app/_components/WearableConnectionStatus.tsx CHANGED
@@ -30,7 +30,7 @@ export default function WearableConnectionStatus() {
30
  window.addEventListener("focus", refresh);
31
  document.addEventListener("visibilitychange", visible);
32
  refresh();
33
- const retry = window.setInterval(poll, 5000);
34
  const clock = window.setInterval(() => {
35
  if (document.visibilityState === "visible") setNow(Date.now());
36
  }, 1000);
@@ -62,8 +62,8 @@ export default function WearableConnectionStatus() {
62
  permission: ["์›Œ์น˜ ํ™•์ธ ๊ถŒํ•œ ํ•„์š”", "ํœด๋Œ€ํฐ ์„ค์ •์—์„œ Run The Shape์˜ ๊ทผ์ฒ˜ ๊ธฐ๊ธฐ ๊ถŒํ•œ์„ ํ—ˆ์šฉํ•ด ์ฃผ์„ธ์š”."],
63
  "bluetooth-off": ["Bluetooth ๊บผ์ง", "ํœด๋Œ€ํฐ์˜ Bluetooth๋ฅผ ์ผœ๊ณ  ๋‹ค์‹œ ํ™•์ธํ•ด ์ฃผ์„ธ์š”."],
64
  disconnected: ["์›Œ์น˜ ์—ฐ๊ฒฐ ์•ˆ ๋จ", "ํœด๋Œ€ํฐ ์•ฑ์—์„œ ์—ฐ๊ฒฐ๋œ ์›Œ์น˜๋ฅผ ์ฐพ์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. Bluetooth์™€ ์›Œ์น˜ ์•ฑ ์—ฐ๊ฒฐ์„ ํ™•์ธํ•ด ์ฃผ์„ธ์š”."],
65
- paired: ["์›Œ์น˜ ํŽ˜์–ด๋ง๋จ ยท ์•ฑ ์—ฐ๊ฒฐ ํ™•์ธ ์ค‘", `${names || "ํŽ˜์–ด๋ง๋œ ์›Œ์น˜"}์—์„œ Run The Shape ์›Œ์น˜ ์•ฑ์„ ์—ด์–ด ์ฃผ์„ธ์š”.`],
66
- connected: ["์›Œ์น˜ ์—ฐ๊ฒฐ๋จ", `${names || "Wear OS ์›Œ์น˜"}์™€ ํœด๋Œ€ํฐ์˜ Wear OS ํ†ต์‹  ์—ฐ๊ฒฐ์ด ํ™•์ธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.`],
67
  };
68
  const [title, detail] = labels[state];
69
 
 
30
  window.addEventListener("focus", refresh);
31
  document.addEventListener("visibilitychange", visible);
32
  refresh();
33
+ const retry = window.setInterval(poll, 3000);
34
  const clock = window.setInterval(() => {
35
  if (document.visibilityState === "visible") setNow(Date.now());
36
  }, 1000);
 
62
  permission: ["์›Œ์น˜ ํ™•์ธ ๊ถŒํ•œ ํ•„์š”", "ํœด๋Œ€ํฐ ์„ค์ •์—์„œ Run The Shape์˜ ๊ทผ์ฒ˜ ๊ธฐ๊ธฐ ๊ถŒํ•œ์„ ํ—ˆ์šฉํ•ด ์ฃผ์„ธ์š”."],
63
  "bluetooth-off": ["Bluetooth ๊บผ์ง", "ํœด๋Œ€ํฐ์˜ Bluetooth๋ฅผ ์ผœ๊ณ  ๋‹ค์‹œ ํ™•์ธํ•ด ์ฃผ์„ธ์š”."],
64
  disconnected: ["์›Œ์น˜ ์—ฐ๊ฒฐ ์•ˆ ๋จ", "ํœด๋Œ€ํฐ ์•ฑ์—์„œ ์—ฐ๊ฒฐ๋œ ์›Œ์น˜๋ฅผ ์ฐพ์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. Bluetooth์™€ ์›Œ์น˜ ์•ฑ ์—ฐ๊ฒฐ์„ ํ™•์ธํ•ด ์ฃผ์„ธ์š”."],
65
+ paired: ["์›Œ์น˜ ์‘๋‹ต ํ™•์ธ ์•ˆ ๋จ", `${names || "๋“ฑ๋ก๋œ ์›Œ์น˜"}์˜ ์ตœ์‹  ์•ฑ ์‘๋‹ต์„ ๋ฐ›์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. ์—ฐ๊ฒฐ ์ƒํƒœ์™€ ์›Œ์น˜ ์•ฑ์„ ํ™•์ธํ•ด ์ฃผ์„ธ์š”.`],
66
+ connected: [status?.bluetoothEnabled === false ? "์›Œ์น˜ ์—ฐ๊ฒฐ๋จ ยท Bluetooth ๊บผ์ง" : "์›Œ์น˜ ์—ฐ๊ฒฐ๋จ", `${names || "Wear OS ์›Œ์น˜"}์˜ ์ตœ์‹  ์‘๋‹ต์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค. Bluetooth๊ฐ€ ๊บผ์ ธ๋„ Wi-Fi ๊ฒฝ์œ  ํ†ต์‹ ์€ ์œ ์ง€๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.`],
67
  };
68
  const [title, detail] = labels[state];
69
 
main/app/_utils/nativeWearBridge.ts CHANGED
@@ -346,6 +346,8 @@ export const sendNativeWearControl = (
346
  };
347
 
348
  const storeNativeWearDeviceStatus = (status: NativeWearDeviceStatus) => {
 
 
349
  window.localStorage.setItem(
350
  NATIVE_WEAR_DEVICE_STATUS_STORAGE_KEY,
351
  JSON.stringify(status),
 
346
  };
347
 
348
  const storeNativeWearDeviceStatus = (status: NativeWearDeviceStatus) => {
349
+ const previous = readNativeWearDeviceStatus();
350
+ if (previous && previous.updatedAt > status.updatedAt) return;
351
  window.localStorage.setItem(
352
  NATIVE_WEAR_DEVICE_STATUS_STORAGE_KEY,
353
  JSON.stringify(status),
main/app/_utils/wearConnectionState.ts CHANGED
@@ -2,9 +2,10 @@ import type { NativeWearDeviceStatus } from "./nativeWearBridge";
2
 
3
  export function wearConnectionState(status: NativeWearDeviceStatus | null, now: number, requestedAt: number) {
4
  const age = status ? now - status.updatedAt : Infinity;
5
- if (!status || !Number.isFinite(age) || status.updatedAt <= 0 || age < 0 || age > 20000) {
6
  return now - requestedAt < 10000 ? "checking" : "unavailable";
7
  }
 
8
  if (status.queryError) return "query-error";
9
  if (status.connected) return "connected";
10
  if (status.permissionGranted === false) return "permission";
 
2
 
3
  export function wearConnectionState(status: NativeWearDeviceStatus | null, now: number, requestedAt: number) {
4
  const age = status ? now - status.updatedAt : Infinity;
5
+ if (!status || !Number.isFinite(age) || status.updatedAt <= 0 || age < 0 || age > 8000) {
6
  return now - requestedAt < 10000 ? "checking" : "unavailable";
7
  }
8
+ if (status.queryError === "checking") return "checking";
9
  if (status.queryError) return "query-error";
10
  if (status.connected) return "connected";
11
  if (status.permissionGranted === false) return "permission";
main/tests/nativeWearBootstrap.cjs CHANGED
@@ -64,3 +64,11 @@ assert(sent.some(message => message.type === 'tranimal.main.run-state'
64
  emit('android-app://untrusted.example', '', [port]);
65
  assert.equal(window.__tranimalNativeWearPort, latePort);
66
  console.log('PASS: empty Android channel message before/after hydration, origin rejection, handoff, live updates, no run-command replay');
 
 
 
 
 
 
 
 
 
64
  emit('android-app://untrusted.example', '', [port]);
65
  assert.equal(window.__tranimalNativeWearPort, latePort);
66
  console.log('PASS: empty Android channel message before/after hydration, origin rejection, handoff, live updates, no run-command replay');
67
+ const disconnectedAt = Date.now() + 100;
68
+ latePort.onmessage({ data: { type: 'wearDevices.status', payload: {
69
+ source: 'android', connected: false, devices: [], updatedAt: disconnectedAt,
70
+ } } });
71
+ latePort.onmessage({ data: { type: 'wearDevices.status', payload: {
72
+ source: 'android', connected: true, devices: [], updatedAt: disconnectedAt - 1,
73
+ } } });
74
+ assert.equal(context.exports.readNativeWearDeviceStatus().connected, false, 'late cached response must not undo disconnect');
main/tests/twaNativeContract.cjs CHANGED
@@ -20,4 +20,12 @@ assert.match(listener, /WatchControlInbox.enqueue/);
20
  assert.match(inbox, /TTL_MS = 120_000L/);
21
  assert.match(inbox, /items.length\(\) >= 32/);
22
  assert.match(activity, /"tranimal.main.run-state".equals\(type\)/);
 
 
 
 
 
 
 
 
23
  console.log('PASS: native status dispatch, timeout/error, control acknowledgement and bounded inbox source contracts');
 
20
  assert.match(inbox, /TTL_MS = 120_000L/);
21
  assert.match(inbox, /items.length\(\) >= 32/);
22
  assert.match(activity, /"tranimal.main.run-state".equals\(type\)/);
23
+ assert.match(activity, /BluetoothAdapter.ACTION_STATE_CHANGED/);
24
+ assert.match(activity, /BluetoothDevice.ACTION_ACL_DISCONNECTED/);
25
+ assert.match(activity, /generation == wearStatusGeneration/);
26
+ assert.match(activity, /status.put\("connected", responsive\)/);
27
+ assert.doesNotMatch(activity, /status.put\("connected", !watches.isEmpty\(\)\)/);
28
+ assert.match(manager, /readyAt >= probeStartedAt/);
29
+ assert.doesNotMatch(manager, /READY_TTL_MS/);
30
+ assert.match(listener, /onPeerDisconnected/);
31
  console.log('PASS: native status dispatch, timeout/error, control acknowledgement and bounded inbox source contracts');
main/tests/wearConnectionState.cjs CHANGED
@@ -13,6 +13,10 @@ assert.equal(state(null, now, now), 'checking');
13
  assert.equal(state(null, now, now - 10000), 'unavailable');
14
  assert.equal(state(fresh, now, 0), 'connected');
15
  assert.equal(state(fresh, now + 21000, 0), 'unavailable');
 
 
 
 
16
  assert.equal(state({ ...fresh, updatedAt: 0 }, now, 0), 'unavailable');
17
  assert.equal(state({ ...fresh, updatedAt: NaN }, now, 0), 'unavailable');
18
  assert.equal(state({ ...fresh, updatedAt: now + 1000 }, now, 0), 'unavailable');
@@ -20,6 +24,7 @@ assert.equal(state({ ...fresh, connected: false }, now, 0), 'disconnected');
20
  assert.equal(state({ ...fresh, connected: false, devices: [{}] }, now, 0), 'paired');
21
  assert.equal(state({ ...fresh, connected: false, permissionGranted: false }, now, 0), 'permission');
22
  assert.equal(state({ ...fresh, connected: false, bluetoothEnabled: false }, now, 0), 'bluetooth-off');
 
23
  // Fresh replies maintain connected state well beyond the former eight-second polling window.
24
  for (let elapsed = 0; elapsed <= 60000; elapsed += 5000) {
25
  assert.equal(state({ ...fresh, updatedAt: now + elapsed }, now + elapsed, now), 'connected');
 
13
  assert.equal(state(null, now, now - 10000), 'unavailable');
14
  assert.equal(state(fresh, now, 0), 'connected');
15
  assert.equal(state(fresh, now + 21000, 0), 'unavailable');
16
+ assert.equal(state(fresh, now + 8001, 0), 'unavailable', 'old connected reply must expire');
17
+ assert.equal(state({ ...fresh, connected: false, queryError: 'checking' }, now, 0), 'checking');
18
+ assert.equal(state({ ...fresh, queryError: 'checking' }, now, 0), 'checking', 'invalidation beats cached connected flag');
19
+ assert.equal(state({ ...fresh, connected: false, devices: [{ connectionState: 'paired' }] }, now, 0), 'paired');
20
  assert.equal(state({ ...fresh, updatedAt: 0 }, now, 0), 'unavailable');
21
  assert.equal(state({ ...fresh, updatedAt: NaN }, now, 0), 'unavailable');
22
  assert.equal(state({ ...fresh, updatedAt: now + 1000 }, now, 0), 'unavailable');
 
24
  assert.equal(state({ ...fresh, connected: false, devices: [{}] }, now, 0), 'paired');
25
  assert.equal(state({ ...fresh, connected: false, permissionGranted: false }, now, 0), 'permission');
26
  assert.equal(state({ ...fresh, connected: false, bluetoothEnabled: false }, now, 0), 'bluetooth-off');
27
+ assert.equal(state({ ...fresh, bluetoothEnabled: false }, now, 0), 'connected', 'fresh Wi-Fi response is still connected');
28
  // Fresh replies maintain connected state well beyond the former eight-second polling window.
29
  for (let elapsed = 0; elapsed <= 60000; elapsed += 5000) {
30
  assert.equal(state({ ...fresh, updatedAt: now + elapsed }, now + elapsed, now), 'connected');