@tokamakdev/plugin-location 0.1.0-beta.106 → 0.1.0-beta.112
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 +32 -14
- package/android/Bindings.kt +997 -0
- package/android/LocationPlugin.kt +3 -124
- package/android/bindings.ts +4150 -0
- package/apple/Bindings.swift +1057 -0
- package/apple/LocationPlugin.swift +28 -167
- package/apple/LocationRegions.swift +3 -1
- package/apple/bindings.ts +1314 -0
- package/events/index.ts +5 -5
- package/package.json +5 -3
- package/src/android.ts +138 -0
- package/src/apple.ts +117 -0
- package/src/errors.ts +34 -0
- package/src/index.ts +89 -64
- package/src/types.ts +12 -0
- package/tokamak-plugin.json +69 -2
- package/web/client.ts +11 -0
- package/src/checks.ts +0 -65
- package/src/options.ts +0 -54
package/README.md
CHANGED
|
@@ -8,11 +8,20 @@ and continuous tracking, all of which reach the app's Worker off screen.
|
|
|
8
8
|
npm install @tokamakdev/plugin-location
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Pages import the generated `/client` SDK. In `src/tokamak.ts`, import the
|
|
12
|
+
package root and call its factory with the handler's `ctx`. The main worker
|
|
13
|
+
uses its generated `env.TOKAMAK_LOCATION` service binding when present.
|
|
14
|
+
|
|
11
15
|
```ts
|
|
12
|
-
import
|
|
16
|
+
import location from "@tokamakdev/plugin-location/client";
|
|
17
|
+
import { decodeValues } from "@tokamakdev/plugin/streams";
|
|
18
|
+
import type { Position } from "@tokamakdev/plugin-location";
|
|
13
19
|
|
|
14
20
|
const position = await location.getCurrentPosition();
|
|
15
|
-
const
|
|
21
|
+
for await (const next of decodeValues<Position>(location.watchPosition())) {
|
|
22
|
+
console.log(next.coords);
|
|
23
|
+
break; // Cancels the watch.
|
|
24
|
+
}
|
|
16
25
|
|
|
17
26
|
await location.requestPermission({ background: true });
|
|
18
27
|
await location.addRegion({ id: "home", latitude: 51.5, longitude: -0.12, radius: 150 });
|
|
@@ -24,8 +33,8 @@ import { location } from "@tokamakdev/plugin-location";
|
|
|
24
33
|
import { onLocationUpdate, onRegionTransition } from "@tokamakdev/plugin-location/events";
|
|
25
34
|
import { onStart } from "@tokamakdev/tok/events";
|
|
26
35
|
|
|
27
|
-
onStart(async () => {
|
|
28
|
-
await location.setup({ significantChanges: true, visits: true });
|
|
36
|
+
onStart(async (_event, _env, ctx) => {
|
|
37
|
+
await location(ctx).setup({ significantChanges: true, visits: true });
|
|
29
38
|
});
|
|
30
39
|
onLocationUpdate(async ({ positions }) => {
|
|
31
40
|
await fetch("https://example.com/whereabouts", { method: "POST", body: JSON.stringify(positions) });
|
|
@@ -41,8 +50,8 @@ milliseconds, 0 by default, or takes a new one, and rejects with
|
|
|
41
50
|
`TimeoutError` when none arrives within `timeout` milliseconds, unlimited by
|
|
42
51
|
default. The timeout starts once the user allows location.
|
|
43
52
|
|
|
44
|
-
`watchPosition(
|
|
45
|
-
|
|
53
|
+
`watchPosition()` returns a byte stream of JSON positions. `decodeValues<Position>`
|
|
54
|
+
decodes them. Cancelling the stream ends the native watch; errors terminate it.
|
|
46
55
|
|
|
47
56
|
Both ask for in-use permission when the user has not answered. Off screen
|
|
48
57
|
without background permission, the platforms stop locating the app, so
|
|
@@ -135,16 +144,17 @@ device is still.
|
|
|
135
144
|
|
|
136
145
|
The plugin's `onLocationUpdate`, `onRegionTransition`, `onVisit` and
|
|
137
146
|
`onLocationError` methods receive the same events while the listening page or
|
|
138
|
-
|
|
147
|
+
Tokamak worker runs. They return byte streams consumed with `decodeValues<T>`;
|
|
148
|
+
cancelling a stream removes its native subscription.
|
|
139
149
|
|
|
140
150
|
## Long-term awareness
|
|
141
151
|
|
|
142
152
|
`setup(config)` keeps the app aware of where the device is over days, with
|
|
143
153
|
little power and no indicator. Call it from `onStart` in `src/tokamak.ts`, so
|
|
144
154
|
it applies at every launch; the plugin also keeps it and applies it again
|
|
145
|
-
itself. The configuration replaces the previous one
|
|
146
|
-
|
|
147
|
-
|
|
155
|
+
itself. The configuration replaces the previous one; a field it leaves out is
|
|
156
|
+
off. Apple platforms reject with `NotSupportedError` where the device cannot
|
|
157
|
+
monitor significant changes.
|
|
148
158
|
|
|
149
159
|
- `significantChanges` delivers moves of 500 metres or more, at most every 5
|
|
150
160
|
minutes, to `onLocationUpdate`, located from cellular and Wi-Fi rather than
|
|
@@ -177,7 +187,8 @@ plugin keeps them across launches and restarts.
|
|
|
177
187
|
macOS 27). It tunes when updates pause and how coordinates follow roads.
|
|
178
188
|
- Updates pause while the device is still and resume when it moves.
|
|
179
189
|
- If iOS ends the app while updates run, it launches the app for the next
|
|
180
|
-
update, and the plugin resumes them
|
|
190
|
+
update, and the plugin resumes them until `stopUpdates()`. With Always
|
|
191
|
+
permission, swiping the app away does not stop them either.
|
|
181
192
|
- Off screen, updates need Always permission, or the `background-updates`
|
|
182
193
|
build setting, whose background activity session shows the pill.
|
|
183
194
|
`startUpdates` rejects with `NeedsUIError` off screen on iOS.
|
|
@@ -232,8 +243,15 @@ and background permission off screen.
|
|
|
232
243
|
|
|
233
244
|
The web uses `navigator.geolocation`. `permission()` reports `inUse` from the
|
|
234
245
|
Permissions API, and the other additions reject with `NotSupportedError`,
|
|
235
|
-
|
|
236
|
-
|
|
246
|
+
including the event-stream methods. Native support is provided on Apple and Android.
|
|
247
|
+
|
|
248
|
+
## Platform bindings
|
|
249
|
+
|
|
250
|
+
`@tokamakdev/plugin-location/apple` is Core Location, and
|
|
251
|
+
`@tokamakdev/plugin-location/android` is `android.location` with the
|
|
252
|
+
`Context`, `CancellationSignal`, `SystemClock`, `Executor` and `Consumer`
|
|
253
|
+
types it uses, for Worker code that needs what this API does not offer.
|
|
254
|
+
`getCurrentPosition` and `watchPosition` are built on them.
|
|
237
255
|
|
|
238
256
|
## Errors
|
|
239
257
|
|
|
@@ -241,4 +259,4 @@ Rejections and `onLocationError` events are `DOMException` names:
|
|
|
241
259
|
`NotAllowedError` (no permission, or none for the background),
|
|
242
260
|
`NotReadableError` (location unavailable, or services off), `NeedsUIError` (a
|
|
243
261
|
prompt or a start off screen), `NotSupportedError`, `QuotaExceededError`,
|
|
244
|
-
`TimeoutError
|
|
262
|
+
`TimeoutError`, and `TypeError` for an argument the native code cannot read.
|