@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 +6 -9
- package/adapters/noble.d.ts +2 -2
- package/adapters/noble.js +13 -4
- package/adapters/react-native-ble-manager.js +3 -1
- package/core/ofp_core.asm.d.ts +2 -0
- package/core/ofp_core.asm.js +10985 -10985
- package/core/ofp_core.wasm +0 -0
- package/index.js +5 -2
- package/package.json +15 -8
- package/registry.bundle.json +1 -1
- package/registry.d.ts +3 -0
- package/registry.js +1 -1
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 '
|
|
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 |
|
|
74
|
-
| React Native (Hermes has no WebAssembly) |
|
|
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.
|
package/adapters/noble.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|