|
16 | 16 | // Store state in a global `obs` object for reuse later in your application. |
17 | 17 | window.obs = window.obs || {}; |
18 | 18 |
|
19 | | - // Optional logging driven by configuration. |
20 | | - // Set before loading obj.js, e.g.: |
21 | | - // window.obs = { config: { log: true } } |
22 | | - const obsConfig = (window.obs && window.obs.config) || {}; |
23 | | - const shouldLog = !!obsConfig.log; |
24 | | - |
25 | | - // Simple logger: prints current values on `window.obs` (except `config`). |
26 | | - const logObs = () => { |
27 | | - if (!shouldLog) return; |
28 | | - try { |
29 | | - for (const [key, value] of Object.entries(window.obs)) { |
30 | | - if (key === 'config') continue; |
31 | | - console.log('[obs]', key, value); |
32 | | - } |
33 | | - } catch (e) { |
34 | | - for (const key in window.obs) { |
35 | | - if (Object.prototype.hasOwnProperty.call(window.obs, key) && key !== 'config') { |
36 | | - console.log('[obs]', key, window.obs[key]); |
37 | | - } |
38 | | - } |
39 | | - } |
40 | | - }; |
41 | | - |
42 | 19 | // Helper function: |
43 | 20 | // Bucket RTT into the nearest upper 25ms. E.g. an RTT of 108ms would be put |
44 | 21 | // into the 125ms bucket. Think of 125ms as being 100–125ms. |
|
116 | 93 | if ('downlinkMax' in connection) { |
117 | 94 | window.obs.downlinkMax = connection.downlinkMax; |
118 | 95 | } |
119 | | - |
120 | 96 | }; |
121 | 97 |
|
122 | 98 | // Run the connection function immediately. |
|
153 | 129 | const isCharging = !!charging; |
154 | 130 | window.obs.batteryCharging = isCharging; |
155 | 131 | html.classList.toggle('has-battery-charging', isCharging); |
156 | | - |
157 | | - // Once Battery has returned, log everything we have. |
158 | | - logObs(); |
159 | | - |
160 | 132 | }; |
161 | 133 |
|
162 | 134 | // Battery metrics (best‑effort and privacy‑respecting). |
|
180 | 152 | // Fail silently. |
181 | 153 | .catch(() => { /* no‑op */ }); |
182 | 154 | } |
183 | | - |
184 | 155 | })(); |
0 commit comments