@openfitnessprotocol/ofp 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -21,11 +21,8 @@ New devices come with a new version of this package: no code of yours changes.
21
21
 
22
22
  ## Usage
23
23
 
24
- Open Fitness Protocol for JavaScript apps: the OFP core and the four hooks an app wires up. No
25
- dependencies.
26
-
27
24
  ```js
28
- import { Ofp, wasmEngine } from './ofp.js'
25
+ import { Ofp, wasmEngine } from '@openfitnessprotocol/ofp'
29
26
 
30
27
  const ofp = new Ofp({
31
28
  engine: wasmEngine(wasmBytes), // or moduleEngine(...) where there is no WebAssembly
@@ -65,12 +62,12 @@ disconnectButton.onclick = () => ofp.release(id)
65
62
 
66
63
  ## The two forms of the core
67
64
 
68
- Both are built by `scripts/build.sh` into `dist/`, with the registry bundle and this package
69
- (`dist/ofp.js`, `dist/ofp.d.ts`):
70
-
71
65
  | Runtime | Core | Engine |
72
66
  |---|---|---|
73
- | Node, Electron, browsers | `ofp_core.wasm` | `wasmEngine(bytes)` |
74
- | React Native (Hermes has no WebAssembly) | `ofp_core.asm.js`, the same core as plain JavaScript | `moduleEngine(require('./ofp_core.asm.js'))` |
67
+ | Node, Electron, browsers | `@openfitnessprotocol/ofp/core/ofp_core.wasm` | `wasmEngine(bytes)` |
68
+ | React Native (Hermes has no WebAssembly) | `@openfitnessprotocol/ofp/core/js`, the same core as plain JavaScript | `moduleEngine(core)` |
69
+
70
+ Quick starts for Electron and React Native: https://openfitnessprotocol.org/developers. In the repository
71
+ both are built by `scripts/build.sh` into `dist/`.
75
72
 
76
73
  `npm test` runs the same tests against both.
@@ -1,10 +1,10 @@
1
1
  import type { OfpAdvertisement } from '../index'
2
2
 
3
- /** A noble peripheral (from the 'discover' event) as an OFP advertisement, or null when it carries no data. */
3
+ /** A noble peripheral (from the 'discover' event) as an OFP advertisement, or null when it carries no manufacturer data, name or services. */
4
4
  export function advertisementFrom(peripheral: {
5
5
  id: string
6
6
  rssi?: number
7
- advertisement?: { localName?: string; manufacturerData?: Uint8Array | null }
7
+ advertisement?: { localName?: string; manufacturerData?: Uint8Array | null; serviceUuids?: string[]; overflowServiceUuids?: string[] }
8
8
  }): OfpAdvertisement | null
9
9
  /** Arguments for `noble.startScanning`: no service filter, with repeats. */
10
10
  export const SCAN_ARGS: [string[], boolean]
package/adapters/noble.js CHANGED
@@ -1,12 +1,21 @@
1
1
  // OFP ↔ noble (@stoprocent/noble, @abandonware/noble): Node and Electron.
2
2
  // noble hands over the manufacturer data raw, company id first: exactly what OFP wants.
3
3
 
4
- /** A noble peripheral (from the 'discover' event) as an OFP advertisement, or null when it carries no data. */
4
+ /**
5
+ * A noble peripheral (from the 'discover' event) as an OFP advertisement, or null when it carries nothing
6
+ * OFP could match: no manufacturer data, no name and no services. The services are how a device that is
7
+ * connected to (a `notify` table) is recognised; noble lists them without dashes.
8
+ */
5
9
  export function advertisementFrom(peripheral) {
6
10
  const adv = peripheral && peripheral.advertisement;
7
- const data = adv && adv.manufacturerData;
8
- if (!data || data.length < 2) return null;
9
- return { deviceId: peripheral.id, name: adv.localName || null, rssi: peripheral.rssi, manufacturerData: data };
11
+ if (!adv) return null;
12
+ const data = adv.manufacturerData && adv.manufacturerData.length >= 2 ? adv.manufacturerData : null;
13
+ const services = [...(adv.serviceUuids || []), ...(adv.overflowServiceUuids || [])];
14
+ const name = adv.localName || null;
15
+ if (!data && !name && !services.length) return null;
16
+ const a = { deviceId: peripheral.id, name, rssi: peripheral.rssi, manufacturerData: data };
17
+ if (services.length) a.services = services;
18
+ return a;
10
19
  }
11
20
 
12
21
  /** noble must scan with repeats, or it reports each device once: `noble.startScanning([], true)`. */
@@ -36,7 +36,9 @@ export function advertisementsFrom(peripheral, companyIds) {
36
36
  * well enough. Spread them AFTER the app's own options: on iOS they replace two of them.
37
37
  *
38
38
  * Android: its filters are alternatives (a device passes if it matches any), and the library takes one
39
- * company id, so that id is added beside the app's services.
39
+ * company id, so that id is added beside the app's services: the first of `companyIds` (the lowest, today the
40
+ * Keiser M3i's). A broadcast device with another company id (a CORE as a beacon) is not let through on
41
+ * Android by this filter.
40
42
  *
41
43
  * iOS (`platform` 'ios'): there is no company-id filter, so the scan is opened to every device (an empty
42
44
  * service list) and repeats are asked for (without them iOS reports a device once, and for a broadcast-only
@@ -0,0 +1,2 @@
1
+ /** The OFP core as plain JavaScript, for runtimes with no WebAssembly: pass it to moduleEngine(). */
2
+ export {}