@bricks-soft/capacitor-location-tracking 0.0.0-stage → 8.0.0
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/LICENSE +21 -0
- package/README.md +2759 -2
- package/android/build.gradle +106 -0
- package/android/consumer-rules.pro +42 -0
- package/android/src/main/AndroidManifest.xml +52 -0
- package/android/src/main/java/com/brickssoft/locationtracking/LocationTrackingPlugin.kt +431 -0
- package/android/src/main/java/com/brickssoft/locationtracking/api/LocationTrackingListener.kt +52 -0
- package/android/src/main/java/com/brickssoft/locationtracking/api/LocationTrackingNative.kt +267 -0
- package/android/src/main/java/com/brickssoft/locationtracking/api/NativeListeners.kt +270 -0
- package/android/src/main/java/com/brickssoft/locationtracking/api/NativeThread.kt +57 -0
- package/android/src/main/java/com/brickssoft/locationtracking/bridge/BridgeServices.kt +64 -0
- package/android/src/main/java/com/brickssoft/locationtracking/bridge/CallResponder.kt +41 -0
- package/android/src/main/java/com/brickssoft/locationtracking/bridge/OptionParsers.kt +281 -0
- package/android/src/main/java/com/brickssoft/locationtracking/bridge/PluginHandlers.kt +541 -0
- package/android/src/main/java/com/brickssoft/locationtracking/bridge/PluginPermissionHost.kt +76 -0
- package/android/src/main/java/com/brickssoft/locationtracking/bridge/WatchRegistry.kt +84 -0
- package/android/src/main/java/com/brickssoft/locationtracking/config/Config.kt +231 -0
- package/android/src/main/java/com/brickssoft/locationtracking/config/ConfigJson.kt +574 -0
- package/android/src/main/java/com/brickssoft/locationtracking/config/ConfigStore.kt +31 -0
- package/android/src/main/java/com/brickssoft/locationtracking/config/ConfigValidator.kt +170 -0
- package/android/src/main/java/com/brickssoft/locationtracking/config/RuntimeStateJson.kt +73 -0
- package/android/src/main/java/com/brickssoft/locationtracking/config/SharedPrefsConfigStore.kt +135 -0
- package/android/src/main/java/com/brickssoft/locationtracking/config/State.kt +45 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/AppDispatchers.kt +21 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/Clock.kt +41 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/Components.kt +217 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/Constants.kt +78 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/Errors.kt +27 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/EventBus.kt +39 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/ForceStopProbe.kt +63 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/Iso8601.kt +63 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/Logger.kt +68 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/RecordHooks.kt +47 -0
- package/android/src/main/java/com/brickssoft/locationtracking/core/TrackingEvent.kt +64 -0
- package/android/src/main/java/com/brickssoft/locationtracking/data/SqlSupport.kt +79 -0
- package/android/src/main/java/com/brickssoft/locationtracking/data/SqliteGeofenceStore.kt +144 -0
- package/android/src/main/java/com/brickssoft/locationtracking/data/SqliteLocationStore.kt +215 -0
- package/android/src/main/java/com/brickssoft/locationtracking/data/Stores.kt +45 -0
- package/android/src/main/java/com/brickssoft/locationtracking/data/TrackingDatabase.kt +111 -0
- package/android/src/main/java/com/brickssoft/locationtracking/device/DefaultDeviceInfoProvider.kt +104 -0
- package/android/src/main/java/com/brickssoft/locationtracking/device/DefaultDeviceMonitor.kt +335 -0
- package/android/src/main/java/com/brickssoft/locationtracking/device/DeviceMonitor.kt +36 -0
- package/android/src/main/java/com/brickssoft/locationtracking/device/DeviceStateMapping.kt +69 -0
- package/android/src/main/java/com/brickssoft/locationtracking/engine/DefaultTrackingEngine.kt +1281 -0
- package/android/src/main/java/com/brickssoft/locationtracking/engine/ElasticDistance.kt +68 -0
- package/android/src/main/java/com/brickssoft/locationtracking/engine/LocationRequests.kt +74 -0
- package/android/src/main/java/com/brickssoft/locationtracking/engine/MotionStateMachine.kt +291 -0
- package/android/src/main/java/com/brickssoft/locationtracking/engine/StationaryRegion.kt +41 -0
- package/android/src/main/java/com/brickssoft/locationtracking/engine/TrackingEngine.kt +60 -0
- package/android/src/main/java/com/brickssoft/locationtracking/engine/TrackingTimers.kt +90 -0
- package/android/src/main/java/com/brickssoft/locationtracking/geofence/DefaultGeofenceManager.kt +899 -0
- package/android/src/main/java/com/brickssoft/locationtracking/geofence/DwellTracker.kt +80 -0
- package/android/src/main/java/com/brickssoft/locationtracking/geofence/GeofenceManager.kt +33 -0
- package/android/src/main/java/com/brickssoft/locationtracking/geofence/PolygonMath.kt +194 -0
- package/android/src/main/java/com/brickssoft/locationtracking/heartbeat/DefaultHeartbeatScheduler.kt +713 -0
- package/android/src/main/java/com/brickssoft/locationtracking/heartbeat/HeartbeatAlarmReceiver.kt +69 -0
- package/android/src/main/java/com/brickssoft/locationtracking/heartbeat/HeartbeatAlarms.kt +100 -0
- package/android/src/main/java/com/brickssoft/locationtracking/heartbeat/HeartbeatScheduler.kt +25 -0
- package/android/src/main/java/com/brickssoft/locationtracking/heartbeat/HeartbeatWindow.kt +179 -0
- package/android/src/main/java/com/brickssoft/locationtracking/http/AuthorizationManager.kt +213 -0
- package/android/src/main/java/com/brickssoft/locationtracking/http/BodyBuilder.kt +73 -0
- package/android/src/main/java/com/brickssoft/locationtracking/http/HttpSupport.kt +118 -0
- package/android/src/main/java/com/brickssoft/locationtracking/http/HttpSyncer.kt +18 -0
- package/android/src/main/java/com/brickssoft/locationtracking/http/OkHttpSyncer.kt +551 -0
- package/android/src/main/java/com/brickssoft/locationtracking/http/StrictJson.kt +135 -0
- package/android/src/main/java/com/brickssoft/locationtracking/http/SyncPolicy.kt +109 -0
- package/android/src/main/java/com/brickssoft/locationtracking/http/TemplateRenderer.kt +143 -0
- package/android/src/main/java/com/brickssoft/locationtracking/logging/FileLogger.kt +461 -0
- package/android/src/main/java/com/brickssoft/locationtracking/logging/LogFileProvider.kt +9 -0
- package/android/src/main/java/com/brickssoft/locationtracking/logging/LogFormatter.kt +148 -0
- package/android/src/main/java/com/brickssoft/locationtracking/logging/LogStore.kt +30 -0
- package/android/src/main/java/com/brickssoft/locationtracking/model/DeviceModels.kt +176 -0
- package/android/src/main/java/com/brickssoft/locationtracking/model/GeofenceSpec.kt +25 -0
- package/android/src/main/java/com/brickssoft/locationtracking/model/ModelJson.kt +550 -0
- package/android/src/main/java/com/brickssoft/locationtracking/model/Record.kt +106 -0
- package/android/src/main/java/com/brickssoft/locationtracking/model/TrackedLocation.kt +53 -0
- package/android/src/main/java/com/brickssoft/locationtracking/permission/BackgroundRationaleDialog.kt +85 -0
- package/android/src/main/java/com/brickssoft/locationtracking/permission/CurrentActivityTracker.kt +72 -0
- package/android/src/main/java/com/brickssoft/locationtracking/permission/DefaultPermissionManager.kt +333 -0
- package/android/src/main/java/com/brickssoft/locationtracking/permission/PermissionManager.kt +54 -0
- package/android/src/main/java/com/brickssoft/locationtracking/position/DefaultPositionService.kt +277 -0
- package/android/src/main/java/com/brickssoft/locationtracking/position/PositionService.kt +39 -0
- package/android/src/main/java/com/brickssoft/locationtracking/position/PositionWatch.kt +115 -0
- package/android/src/main/java/com/brickssoft/locationtracking/processing/DefaultLocationProcessor.kt +93 -0
- package/android/src/main/java/com/brickssoft/locationtracking/processing/DefaultOdometer.kt +99 -0
- package/android/src/main/java/com/brickssoft/locationtracking/processing/DefaultRecordFactory.kt +166 -0
- package/android/src/main/java/com/brickssoft/locationtracking/processing/Geo.kt +56 -0
- package/android/src/main/java/com/brickssoft/locationtracking/processing/KalmanFilter.kt +72 -0
- package/android/src/main/java/com/brickssoft/locationtracking/processing/Processing.kt +48 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/Backends.kt +187 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/DefaultProviderFactory.kt +169 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/ProviderPackaging.kt +135 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/android/AndroidActivityBackend.kt +25 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/android/AndroidGeofenceBackend.kt +181 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/android/AndroidGeofenceReceiver.kt +115 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/android/AndroidLocationBackend.kt +265 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/android/AndroidProviderBundle.kt +31 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/android/LocationProviders.kt +98 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsActivityBackend.kt +80 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsActivityReceiver.kt +62 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsErrors.kt +72 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsGeofenceBackend.kt +152 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsGeofenceReceiver.kt +78 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsLocationBackend.kt +176 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsProviderBundle.kt +62 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsReceiverSupport.kt +88 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/gms/GmsTasks.kt +55 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsActivityBackend.kt +71 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsActivityReceiver.kt +57 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsErrors.kt +76 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsGeofenceBackend.kt +116 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsGeofenceReceiver.kt +67 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsIntents.kt +83 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsLocationBackend.kt +197 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsProviderBundle.kt +55 -0
- package/android/src/main/java/com/brickssoft/locationtracking/provider/hms/HmsTasks.kt +44 -0
- package/android/src/main/java/com/brickssoft/locationtracking/record/RecordSink.kt +95 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/BootCountStore.kt +44 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/BootReceiver.kt +175 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/DefaultServiceController.kt +196 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/LocationTrackingService.kt +319 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/NotificationActionReceiver.kt +42 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/NotificationFactory.kt +338 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/ServiceCommands.kt +204 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/ServiceController.kt +22 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/ServiceDeps.kt +61 -0
- package/android/src/main/java/com/brickssoft/locationtracking/service/WhileInUseStartCheck.kt +115 -0
- package/android/src/main/java/com/brickssoft/locationtracking/settings/DefaultDeviceSettings.kt +79 -0
- package/android/src/main/java/com/brickssoft/locationtracking/settings/DeviceSettings.kt +21 -0
- package/android/src/main/java/com/brickssoft/locationtracking/settings/OemPowerManagers.kt +198 -0
- package/android/src/main/res/drawable/lt_ic_notification.xml +11 -0
- package/android/src/main/res/values/lt_strings.xml +11 -0
- package/android/src/main/res/xml/lt_file_paths.xml +5 -0
- package/dist/esm/definitions.d.ts +719 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/events.d.ts +50 -0
- package/dist/esm/events.js +52 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/plugin.d.ts +3 -0
- package/dist/esm/plugin.js +10 -0
- package/dist/esm/plugin.js.map +1 -0
- package/dist/esm/web/config.d.ts +19 -0
- package/dist/esm/web/config.js +243 -0
- package/dist/esm/web/config.js.map +1 -0
- package/dist/esm/web/device.d.ts +9 -0
- package/dist/esm/web/device.js +90 -0
- package/dist/esm/web/device.js.map +1 -0
- package/dist/esm/web/errors.d.ts +14 -0
- package/dist/esm/web/errors.js +19 -0
- package/dist/esm/web/errors.js.map +1 -0
- package/dist/esm/web/geolocation.d.ts +26 -0
- package/dist/esm/web/geolocation.js +117 -0
- package/dist/esm/web/geolocation.js.map +1 -0
- package/dist/esm/web/location.d.ts +7 -0
- package/dist/esm/web/location.js +70 -0
- package/dist/esm/web/location.js.map +1 -0
- package/dist/esm/web.d.ts +164 -0
- package/dist/esm/web.js +328 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +945 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +948 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +59 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../../src/web/device.ts"],"names":[],"mappings":"AAGA,4GAA4G;AAC5G,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,+FAA+F;AAC/F,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAQtE,2GAA2G;AAC3G,SAAS,YAAY,CAAC,MAAgB;IACpC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACxD,MAAM,IAAI,GACR,CAAC,KAAK;YACN,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;YAC/B,8BAA8B,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,qBAAqB;YACnE,kBAAkB,CAAC,IAAI,CAAC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CAAC;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,SAAiB,EAAE,QAAiB;IAChE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9B,OAAO;QACL,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,EAAE,CAAC,YAAY;QAC7B,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,QAAQ,IAAI,SAAS;QACxC,KAAK,EAAE,YAAY,CAAC,SAAS,CAAC;QAC9B,SAAS,EAAE,EAAE,CAAC,SAAS;QACvB,MAAM,EAAE,CAAC,CAAC;QACV,aAAa,EAAE,cAAc;QAC7B,YAAY,EAAE,KAAK;QACnB,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,KAAK;QACd,iBAAiB,EAAE,EAAE;KACtB,CAAC;AACJ,CAAC","sourcesContent":["// Owned by Unit 1 (TS wrapper + web).\nimport type { DeviceInfo } from '../definitions';\n\n/** Keep in sync with `package.json` (a test checks this) and `PLUGIN_VERSION` in `android/build.gradle`. */\nexport const PLUGIN_VERSION = '8.0.0';\n\n/** Tokens after `Android x` that do not name a device ('K' is Chrome's reduced user agent). */\nconst NOT_A_MODEL = ['K', 'U', 'wv', 'Mobile', 'Tablet', 'HarmonyOS'];\n\ninterface OsInfo {\n osVersion: string;\n manufacturer: string;\n model: string | undefined;\n}\n\n/** The device model among the `;`-separated tokens that follow `Android x` in the user agent's comment. */\nfunction androidModel(tokens: string[]): string | undefined {\n for (const token of tokens) {\n const model = token.replace(/\\s*Build\\/.*$/, '').trim();\n const skip =\n !model ||\n NOT_A_MODEL.indexOf(model) >= 0 ||\n /^[a-z]{2}(?:[-_][a-z]{2})?$/i.test(model) || // locale, e.g. en-us\n /^(?:rv:|HMSCore)/.test(model);\n if (!skip) {\n return model;\n }\n }\n return undefined;\n}\n\nfunction parseOs(ua: string): OsInfo {\n let match = /\\(([^)]*?)Android\\s*([\\d.]*)([^)]*)\\)/.exec(ua);\n if (match) {\n return {\n osVersion: match[2] ? `Android ${match[2]}` : 'Android',\n manufacturer: 'unknown',\n model: androidModel(match[3].split(';')),\n };\n }\n match = /(iPhone|iPad|iPod).*?OS (\\d+(?:_\\d+)*)/.exec(ua);\n if (match) {\n return { osVersion: `iOS ${match[2].replace(/_/g, '.')}`, manufacturer: 'Apple', model: match[1] };\n }\n match = /Mac OS X (\\d+(?:[_.]\\d+)*)/.exec(ua);\n if (match) {\n return { osVersion: `macOS ${match[1].replace(/_/g, '.')}`, manufacturer: 'Apple', model: 'Macintosh' };\n }\n match = /Windows NT (\\d+(?:\\.\\d+)*)/.exec(ua);\n if (match) {\n return { osVersion: `Windows ${match[1]}`, manufacturer: 'unknown', model: undefined };\n }\n match = /CrOS \\S+ (\\d+(?:\\.\\d+)*)/.exec(ua);\n if (match) {\n return { osVersion: `ChromeOS ${match[1]}`, manufacturer: 'unknown', model: undefined };\n }\n if (/Linux/.test(ua)) {\n return { osVersion: 'Linux', manufacturer: 'unknown', model: undefined };\n }\n return { osVersion: 'unknown', manufacturer: 'unknown', model: undefined };\n}\n\n/** Browser name and major version, e.g. `Chrome 120`. Order matters: many browsers also claim Chrome or Safari. */\nfunction parseBrowser(ua: string): string {\n const browsers: [string, RegExp][] = [\n ['Edge', /Edg(?:e|A|iOS)?\\/(\\d+)/],\n ['Opera', /(?:OPR|Opera)\\/(\\d+)/],\n ['Samsung Internet', /SamsungBrowser\\/(\\d+)/],\n ['Huawei Browser', /HuaweiBrowser\\/(\\d+)/],\n ['Firefox', /(?:Firefox|FxiOS)\\/(\\d+)/],\n ['Chrome', /(?:Chrome|CriOS)\\/(\\d+)/],\n ['Safari', /Version\\/(\\d+)[\\d.]*.*Safari\\//],\n ['Node.js', /Node\\.js\\/(\\d+)/],\n ];\n for (const [name, pattern] of browsers) {\n const match = pattern.exec(ua);\n if (match) {\n return `${name} ${match[1]}`;\n }\n }\n return 'unknown';\n}\n\n/**\n * Best-effort `DeviceInfo` for a browser, parsed from `navigator.userAgent`.\n * `brand` is the browser, `model` the device when the user agent names one (else `navigator.platform`),\n * `osVersion` includes the OS name, and `sdkInt` is -1 because there is no Android API level.\n */\nexport function webDeviceInfo(userAgent: string, platform?: string): DeviceInfo {\n const os = parseOs(userAgent);\n return {\n platform: 'web',\n manufacturer: os.manufacturer,\n model: os.model || platform || 'unknown',\n brand: parseBrowser(userAgent),\n osVersion: os.osVersion,\n sdkInt: -1,\n pluginVersion: PLUGIN_VERSION,\n gmsAvailable: false,\n hmsAvailable: false,\n backend: 'web',\n packagedProviders: [],\n };\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CapacitorException } from '@capacitor/core';
|
|
2
|
+
import type { ErrorCode } from '../definitions';
|
|
3
|
+
/** The `{ code, message }` shape passed to a watch callback on error. */
|
|
4
|
+
export interface WebErrorInfo {
|
|
5
|
+
code: ErrorCode;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
/** A rejection shaped like the native bridge's: a `CapacitorException` whose `code` is an `ErrorCode`. */
|
|
9
|
+
export declare function webError(code: ErrorCode, message: string): CapacitorException;
|
|
10
|
+
/** `GeolocationPositionError.code`: 1 = PERMISSION_DENIED, 2 = POSITION_UNAVAILABLE, 3 = TIMEOUT. */
|
|
11
|
+
export declare function positionErrorInfo(error: {
|
|
12
|
+
code?: number;
|
|
13
|
+
message?: string;
|
|
14
|
+
} | null | undefined): WebErrorInfo;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Owned by Unit 1 (TS wrapper + web).
|
|
2
|
+
import { CapacitorException } from '@capacitor/core';
|
|
3
|
+
/** A rejection shaped like the native bridge's: a `CapacitorException` whose `code` is an `ErrorCode`. */
|
|
4
|
+
export function webError(code, message) {
|
|
5
|
+
return new CapacitorException(message, code);
|
|
6
|
+
}
|
|
7
|
+
/** `GeolocationPositionError.code`: 1 = PERMISSION_DENIED, 2 = POSITION_UNAVAILABLE, 3 = TIMEOUT. */
|
|
8
|
+
export function positionErrorInfo(error) {
|
|
9
|
+
const raw = error && typeof error.code === 'number' ? error.code : 0;
|
|
10
|
+
const code = raw === 1 ? 'PERMISSION_DENIED' : raw === 3 ? 'TIMEOUT' : 'UNAVAILABLE';
|
|
11
|
+
const fallback = code === 'PERMISSION_DENIED'
|
|
12
|
+
? 'Location permission denied.'
|
|
13
|
+
: code === 'TIMEOUT'
|
|
14
|
+
? 'Timed out waiting for a location.'
|
|
15
|
+
: 'Location unavailable.';
|
|
16
|
+
const message = error && typeof error.message === 'string' && error.message ? error.message : fallback;
|
|
17
|
+
return { code, message };
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/web/errors.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAWrD,0GAA0G;AAC1G,MAAM,UAAU,QAAQ,CAAC,IAAe,EAAE,OAAe;IACvD,OAAO,IAAI,kBAAkB,CAAC,OAAO,EAAE,IAAgC,CAAC,CAAC;AAC3E,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,iBAAiB,CAAC,KAA6D;IAC7F,MAAM,GAAG,GAAG,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,MAAM,IAAI,GAAc,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC;IAChG,MAAM,QAAQ,GACZ,IAAI,KAAK,mBAAmB;QAC1B,CAAC,CAAC,6BAA6B;QAC/B,CAAC,CAAC,IAAI,KAAK,SAAS;YAClB,CAAC,CAAC,mCAAmC;YACrC,CAAC,CAAC,uBAAuB,CAAC;IAChC,MAAM,OAAO,GAAG,KAAK,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;IACvG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["// Owned by Unit 1 (TS wrapper + web).\nimport { CapacitorException } from '@capacitor/core';\nimport type { ExceptionCode } from '@capacitor/core';\n\nimport type { ErrorCode } from '../definitions';\n\n/** The `{ code, message }` shape passed to a watch callback on error. */\nexport interface WebErrorInfo {\n code: ErrorCode;\n message: string;\n}\n\n/** A rejection shaped like the native bridge's: a `CapacitorException` whose `code` is an `ErrorCode`. */\nexport function webError(code: ErrorCode, message: string): CapacitorException {\n return new CapacitorException(message, code as unknown as ExceptionCode);\n}\n\n/** `GeolocationPositionError.code`: 1 = PERMISSION_DENIED, 2 = POSITION_UNAVAILABLE, 3 = TIMEOUT. */\nexport function positionErrorInfo(error: { code?: number; message?: string } | null | undefined): WebErrorInfo {\n const raw = error && typeof error.code === 'number' ? error.code : 0;\n const code: ErrorCode = raw === 1 ? 'PERMISSION_DENIED' : raw === 3 ? 'TIMEOUT' : 'UNAVAILABLE';\n const fallback =\n code === 'PERMISSION_DENIED'\n ? 'Location permission denied.'\n : code === 'TIMEOUT'\n ? 'Timed out waiting for a location.'\n : 'Location unavailable.';\n const message = error && typeof error.message === 'string' && error.message ? error.message : fallback;\n return { code, message };\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PermissionState } from '@capacitor/core';
|
|
2
|
+
export interface SampleOptions {
|
|
3
|
+
/** Number of fixes to take, at least 1. */
|
|
4
|
+
samples: number;
|
|
5
|
+
/** Overall deadline for all samples, ms. */
|
|
6
|
+
timeout: number;
|
|
7
|
+
/** Passed to the first request only, so the browser may answer it from its cache; later samples are fresh. */
|
|
8
|
+
maximumAge: number;
|
|
9
|
+
enableHighAccuracy: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** Returns `navigator.geolocation`, or `undefined` when the browser has none. */
|
|
12
|
+
export declare function browserGeolocation(): Geolocation | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Takes up to `samples` fixes with consecutive `getCurrentPosition` calls and resolves the most accurate one.
|
|
15
|
+
* The whole run shares one deadline (`timeout`). When the deadline passes, or a later call fails, it resolves the
|
|
16
|
+
* best fix taken so far; with no fix it rejects with `TIMEOUT`, `PERMISSION_DENIED` or `UNAVAILABLE`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function sampleBestPosition(geolocation: Geolocation, options: SampleOptions): Promise<GeolocationPosition>;
|
|
19
|
+
/**
|
|
20
|
+
* Asks for one fix so the browser shows its permission prompt, and waits for the user's answer.
|
|
21
|
+
* Resolves `'denied'` on PERMISSION_DENIED and `'granted'` otherwise: the browser reports TIMEOUT and
|
|
22
|
+
* POSITION_UNAVAILABLE only after permission was granted. Resolves `'prompt'` if nothing happens within a minute.
|
|
23
|
+
*/
|
|
24
|
+
export declare function probeLocationPermission(geolocation: Geolocation): Promise<PermissionState>;
|
|
25
|
+
/** State of the browser's `geolocation` permission, or `undefined` when the Permissions API cannot tell. */
|
|
26
|
+
export declare function queryLocationPermission(): Promise<PermissionState | undefined>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { positionErrorInfo, webError } from './errors';
|
|
2
|
+
/** Largest delay `setTimeout` accepts; longer delays would fire immediately. */
|
|
3
|
+
const MAX_TIMER_MS = 2147483647;
|
|
4
|
+
/** How long the permission probe waits for a fix once the user has answered the prompt. */
|
|
5
|
+
const PROBE_TIMEOUT_MS = 10000;
|
|
6
|
+
/** Overall limit for the permission probe: some browsers never call back when their prompt is dismissed. */
|
|
7
|
+
const PROBE_DEADLINE_MS = 60000;
|
|
8
|
+
/** Returns `navigator.geolocation`, or `undefined` when the browser has none. */
|
|
9
|
+
export function browserGeolocation() {
|
|
10
|
+
return typeof navigator !== 'undefined' && navigator && navigator.geolocation ? navigator.geolocation : undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Takes up to `samples` fixes with consecutive `getCurrentPosition` calls and resolves the most accurate one.
|
|
14
|
+
* The whole run shares one deadline (`timeout`). When the deadline passes, or a later call fails, it resolves the
|
|
15
|
+
* best fix taken so far; with no fix it rejects with `TIMEOUT`, `PERMISSION_DENIED` or `UNAVAILABLE`.
|
|
16
|
+
*/
|
|
17
|
+
export function sampleBestPosition(geolocation, options) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const deadline = Date.now() + options.timeout;
|
|
20
|
+
let best = null;
|
|
21
|
+
let taken = 0;
|
|
22
|
+
let done = false;
|
|
23
|
+
let timer;
|
|
24
|
+
const finish = (error) => {
|
|
25
|
+
if (done) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
done = true;
|
|
29
|
+
if (timer !== undefined) {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
}
|
|
32
|
+
if (best) {
|
|
33
|
+
resolve(best);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
reject(error || webError('TIMEOUT', `No location within ${options.timeout} ms.`));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const next = () => {
|
|
40
|
+
if (done) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
geolocation.getCurrentPosition((position) => {
|
|
45
|
+
if (done) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
taken++;
|
|
49
|
+
if (!best || position.coords.accuracy <= best.coords.accuracy) {
|
|
50
|
+
best = position;
|
|
51
|
+
}
|
|
52
|
+
if (taken >= options.samples) {
|
|
53
|
+
finish();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
next();
|
|
57
|
+
}
|
|
58
|
+
}, (error) => {
|
|
59
|
+
const info = positionErrorInfo(error);
|
|
60
|
+
finish(webError(info.code, info.message));
|
|
61
|
+
}, {
|
|
62
|
+
enableHighAccuracy: options.enableHighAccuracy,
|
|
63
|
+
maximumAge: taken === 0 ? options.maximumAge : 0,
|
|
64
|
+
timeout: Math.max(0, deadline - Date.now()),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
finish(webError('UNAVAILABLE', e instanceof Error ? e.message : String(e)));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
// The browser's own timeout does not run while its permission prompt is open; this deadline does.
|
|
72
|
+
if (options.timeout <= MAX_TIMER_MS) {
|
|
73
|
+
timer = setTimeout(() => finish(), options.timeout);
|
|
74
|
+
}
|
|
75
|
+
next();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Asks for one fix so the browser shows its permission prompt, and waits for the user's answer.
|
|
80
|
+
* Resolves `'denied'` on PERMISSION_DENIED and `'granted'` otherwise: the browser reports TIMEOUT and
|
|
81
|
+
* POSITION_UNAVAILABLE only after permission was granted. Resolves `'prompt'` if nothing happens within a minute.
|
|
82
|
+
*/
|
|
83
|
+
export function probeLocationPermission(geolocation) {
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
let done = false;
|
|
86
|
+
const finish = (state) => {
|
|
87
|
+
if (!done) {
|
|
88
|
+
done = true;
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
resolve(state);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const timer = setTimeout(() => finish('prompt'), PROBE_DEADLINE_MS);
|
|
94
|
+
try {
|
|
95
|
+
geolocation.getCurrentPosition(() => finish('granted'), (error) => finish(positionErrorInfo(error).code === 'PERMISSION_DENIED' ? 'denied' : 'granted'), { enableHighAccuracy: false, maximumAge: Infinity, timeout: PROBE_TIMEOUT_MS });
|
|
96
|
+
}
|
|
97
|
+
catch (_a) {
|
|
98
|
+
finish('prompt');
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/** State of the browser's `geolocation` permission, or `undefined` when the Permissions API cannot tell. */
|
|
103
|
+
export async function queryLocationPermission() {
|
|
104
|
+
const permissions = typeof navigator !== 'undefined' && navigator ? navigator.permissions : undefined;
|
|
105
|
+
if (!permissions || typeof permissions.query !== 'function') {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const status = await permissions.query({ name: 'geolocation' });
|
|
110
|
+
const state = status.state;
|
|
111
|
+
return state === 'granted' || state === 'denied' || state === 'prompt' ? state : 'prompt';
|
|
112
|
+
}
|
|
113
|
+
catch (_a) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=geolocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation.js","sourceRoot":"","sources":["../../../src/web/geolocation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEvD,gFAAgF;AAChF,MAAM,YAAY,GAAG,UAAU,CAAC;AAEhC,2FAA2F;AAC3F,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,4GAA4G;AAC5G,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAYhC,iFAAiF;AACjF,MAAM,UAAU,kBAAkB;IAChC,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,IAAI,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;AACpH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAwB,EAAE,OAAsB;IACjF,OAAO,IAAI,OAAO,CAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAC9C,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nimport type { CapacitorException } from '@capacitor/core';\nimport type { PermissionState } from '@capacitor/core';\n\nimport { positionErrorInfo, webError } from './errors';\n\n/** Largest delay `setTimeout` accepts; longer delays would fire immediately. */\nconst MAX_TIMER_MS = 2147483647;\n\n/** How long the permission probe waits for a fix once the user has answered the prompt. */\nconst PROBE_TIMEOUT_MS = 10000;\n\n/** Overall limit for the permission probe: some browsers never call back when their prompt is dismissed. */\nconst PROBE_DEADLINE_MS = 60000;\n\nexport interface SampleOptions {\n /** Number of fixes to take, at least 1. */\n samples: number;\n /** Overall deadline for all samples, ms. */\n timeout: number;\n /** Passed to the first request only, so the browser may answer it from its cache; later samples are fresh. */\n maximumAge: number;\n enableHighAccuracy: boolean;\n}\n\n/** Returns `navigator.geolocation`, or `undefined` when the browser has none. */\nexport function browserGeolocation(): Geolocation | undefined {\n return typeof navigator !== 'undefined' && navigator && navigator.geolocation ? navigator.geolocation : undefined;\n}\n\n/**\n * Takes up to `samples` fixes with consecutive `getCurrentPosition` calls and resolves the most accurate one.\n * The whole run shares one deadline (`timeout`). When the deadline passes, or a later call fails, it resolves the\n * best fix taken so far; with no fix it rejects with `TIMEOUT`, `PERMISSION_DENIED` or `UNAVAILABLE`.\n */\nexport function sampleBestPosition(geolocation: Geolocation, options: SampleOptions): Promise<GeolocationPosition> {\n return new Promise<GeolocationPosition>((resolve, reject) => {\n const deadline = Date.now() + options.timeout;\n let best: GeolocationPosition | null = null;\n let taken = 0;\n let done = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const finish = (error?: CapacitorException): void => {\n if (done) {\n return;\n }\n done = true;\n if (timer !== undefined) {\n clearTimeout(timer);\n }\n if (best) {\n resolve(best);\n } else {\n reject(error || webError('TIMEOUT', `No location within ${options.timeout} ms.`));\n }\n };\n\n const next = (): void => {\n if (done) {\n return;\n }\n try {\n geolocation.getCurrentPosition(\n (position) => {\n if (done) {\n return;\n }\n taken++;\n if (!best || position.coords.accuracy <= best.coords.accuracy) {\n best = position;\n }\n if (taken >= options.samples) {\n finish();\n } else {\n next();\n }\n },\n (error) => {\n const info = positionErrorInfo(error);\n finish(webError(info.code, info.message));\n },\n {\n enableHighAccuracy: options.enableHighAccuracy,\n maximumAge: taken === 0 ? options.maximumAge : 0,\n timeout: Math.max(0, deadline - Date.now()),\n },\n );\n } catch (e) {\n finish(webError('UNAVAILABLE', e instanceof Error ? e.message : String(e)));\n }\n };\n\n // The browser's own timeout does not run while its permission prompt is open; this deadline does.\n if (options.timeout <= MAX_TIMER_MS) {\n timer = setTimeout(() => finish(), options.timeout);\n }\n next();\n });\n}\n\n/**\n * Asks for one fix so the browser shows its permission prompt, and waits for the user's answer.\n * Resolves `'denied'` on PERMISSION_DENIED and `'granted'` otherwise: the browser reports TIMEOUT and\n * POSITION_UNAVAILABLE only after permission was granted. Resolves `'prompt'` if nothing happens within a minute.\n */\nexport function probeLocationPermission(geolocation: Geolocation): Promise<PermissionState> {\n return new Promise<PermissionState>((resolve) => {\n let done = false;\n const finish = (state: PermissionState): void => {\n if (!done) {\n done = true;\n clearTimeout(timer);\n resolve(state);\n }\n };\n const timer = setTimeout(() => finish('prompt'), PROBE_DEADLINE_MS);\n try {\n geolocation.getCurrentPosition(\n () => finish('granted'),\n (error) => finish(positionErrorInfo(error).code === 'PERMISSION_DENIED' ? 'denied' : 'granted'),\n { enableHighAccuracy: false, maximumAge: Infinity, timeout: PROBE_TIMEOUT_MS },\n );\n } catch {\n finish('prompt');\n }\n });\n}\n\n/** State of the browser's `geolocation` permission, or `undefined` when the Permissions API cannot tell. */\nexport async function queryLocationPermission(): Promise<PermissionState | undefined> {\n const permissions = typeof navigator !== 'undefined' && navigator ? navigator.permissions : undefined;\n if (!permissions || typeof permissions.query !== 'function') {\n return undefined;\n }\n try {\n const status = await permissions.query({ name: 'geolocation' });\n const state = status.state;\n return state === 'granted' || state === 'denied' || state === 'prompt' ? state : 'prompt';\n } catch {\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Location, RecordEvent } from '../definitions';
|
|
2
|
+
/** A version 4 UUID: `crypto.randomUUID()`, else built from `crypto.getRandomValues()`, else from `Math.random()`. */
|
|
3
|
+
export declare function uuid(): string;
|
|
4
|
+
/** ISO-8601 UTC with milliseconds (`yyyy-MM-ddTHH:mm:ss.SSSZ`). Invalid input falls back to now. */
|
|
5
|
+
export declare function isoTime(epochMs: number): string;
|
|
6
|
+
/** Maps a browser fix to the plugin's `Location` record shape. `extras` is left out when empty. */
|
|
7
|
+
export declare function toLocation(position: GeolocationPosition, event: RecordEvent, extras?: Record<string, unknown>): Location;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** A version 4 UUID: `crypto.randomUUID()`, else built from `crypto.getRandomValues()`, else from `Math.random()`. */
|
|
2
|
+
export function uuid() {
|
|
3
|
+
const webCrypto = typeof crypto !== 'undefined' ? crypto : undefined;
|
|
4
|
+
if (webCrypto && typeof webCrypto.randomUUID === 'function') {
|
|
5
|
+
return webCrypto.randomUUID();
|
|
6
|
+
}
|
|
7
|
+
const bytes = new Uint8Array(16);
|
|
8
|
+
if (webCrypto && typeof webCrypto.getRandomValues === 'function') {
|
|
9
|
+
webCrypto.getRandomValues(bytes);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
13
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
17
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
18
|
+
let hex = '';
|
|
19
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
20
|
+
hex += (bytes[i] + 0x100).toString(16).slice(1);
|
|
21
|
+
}
|
|
22
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
23
|
+
}
|
|
24
|
+
/** ISO-8601 UTC with milliseconds (`yyyy-MM-ddTHH:mm:ss.SSSZ`). Invalid input falls back to now. */
|
|
25
|
+
export function isoTime(epochMs) {
|
|
26
|
+
const ms = typeof epochMs === 'number' && isFinite(epochMs) ? Math.round(epochMs) : Date.now();
|
|
27
|
+
return new Date(ms).toISOString();
|
|
28
|
+
}
|
|
29
|
+
/** Monotonic milliseconds since the page's time origin: the closest web equivalent of `elapsedRealtime`. */
|
|
30
|
+
function elapsedMs() {
|
|
31
|
+
const hasClock = typeof performance !== 'undefined' && typeof performance.now === 'function';
|
|
32
|
+
return hasClock ? Math.round(performance.now()) : 0;
|
|
33
|
+
}
|
|
34
|
+
function numberOrNull(value) {
|
|
35
|
+
return typeof value === 'number' && isFinite(value) ? value : null;
|
|
36
|
+
}
|
|
37
|
+
/** Maps a browser fix to the plugin's `Location` record shape. `extras` is left out when empty. */
|
|
38
|
+
export function toLocation(position, event, extras) {
|
|
39
|
+
const coords = position.coords;
|
|
40
|
+
const location = {
|
|
41
|
+
uuid: uuid(),
|
|
42
|
+
event,
|
|
43
|
+
timestamp: isoTime(position.timestamp),
|
|
44
|
+
recorded_at: isoTime(Date.now()),
|
|
45
|
+
elapsed_realtime_ms: elapsedMs(),
|
|
46
|
+
boot_count: -1,
|
|
47
|
+
is_moving: false,
|
|
48
|
+
odometer: 0,
|
|
49
|
+
mock: false,
|
|
50
|
+
coords: {
|
|
51
|
+
latitude: coords.latitude,
|
|
52
|
+
longitude: coords.longitude,
|
|
53
|
+
accuracy: coords.accuracy,
|
|
54
|
+
altitude: numberOrNull(coords.altitude),
|
|
55
|
+
altitude_accuracy: numberOrNull(coords.altitudeAccuracy),
|
|
56
|
+
speed: numberOrNull(coords.speed),
|
|
57
|
+
speed_accuracy: null,
|
|
58
|
+
heading: numberOrNull(coords.heading),
|
|
59
|
+
heading_accuracy: null,
|
|
60
|
+
},
|
|
61
|
+
activity: { type: 'unknown', confidence: 0 },
|
|
62
|
+
battery: { level: -1, is_charging: false },
|
|
63
|
+
backend: 'web',
|
|
64
|
+
};
|
|
65
|
+
if (extras && Object.keys(extras).length > 0) {
|
|
66
|
+
location.extras = extras;
|
|
67
|
+
}
|
|
68
|
+
return location;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.js","sourceRoot":"","sources":["../../../src/web/location.ts"],"names":[],"mappings":"AAGA,sHAAsH;AACtH,MAAM,UAAU,IAAI;IAClB,MAAM,SAAS,GAAuB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACzF,IAAI,SAAS,IAAI,OAAO,SAAS,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC5D,OAAO,SAAS,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,IAAI,SAAS,IAAI,OAAO,SAAS,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QACjE,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IACD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACpC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACpC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,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Q,CAAC;AAClB,CAAC","sourcesContent":["// Owned by Unit 1 (TS wrapper + web).\nimport type { Location, RecordEvent } from '../definitions';\n\n/** A version 4 UUID: `crypto.randomUUID()`, else built from `crypto.getRandomValues()`, else from `Math.random()`. */\nexport function uuid(): string {\n const webCrypto: Crypto | undefined = typeof crypto !== 'undefined' ? crypto : undefined;\n if (webCrypto && typeof webCrypto.randomUUID === 'function') {\n return webCrypto.randomUUID();\n }\n const bytes = new Uint8Array(16);\n if (webCrypto && typeof webCrypto.getRandomValues === 'function') {\n webCrypto.getRandomValues(bytes);\n } else {\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Math.floor(Math.random() * 256);\n }\n }\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += (bytes[i] + 0x100).toString(16).slice(1);\n }\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\n/** ISO-8601 UTC with milliseconds (`yyyy-MM-ddTHH:mm:ss.SSSZ`). Invalid input falls back to now. */\nexport function isoTime(epochMs: number): string {\n const ms = typeof epochMs === 'number' && isFinite(epochMs) ? Math.round(epochMs) : Date.now();\n return new Date(ms).toISOString();\n}\n\n/** Monotonic milliseconds since the page's time origin: the closest web equivalent of `elapsedRealtime`. */\nfunction elapsedMs(): number {\n const hasClock = typeof performance !== 'undefined' && typeof performance.now === 'function';\n return hasClock ? Math.round(performance.now()) : 0;\n}\n\nfunction numberOrNull(value: number | null | undefined): number | null {\n return typeof value === 'number' && isFinite(value) ? value : null;\n}\n\n/** Maps a browser fix to the plugin's `Location` record shape. `extras` is left out when empty. */\nexport function toLocation(\n position: GeolocationPosition,\n event: RecordEvent,\n extras?: Record<string, unknown>,\n): Location {\n const coords = position.coords;\n const location: Location = {\n uuid: uuid(),\n event,\n timestamp: isoTime(position.timestamp),\n recorded_at: isoTime(Date.now()),\n elapsed_realtime_ms: elapsedMs(),\n boot_count: -1,\n is_moving: false,\n odometer: 0,\n mock: false,\n coords: {\n latitude: coords.latitude,\n longitude: coords.longitude,\n accuracy: coords.accuracy,\n altitude: numberOrNull(coords.altitude),\n altitude_accuracy: numberOrNull(coords.altitudeAccuracy),\n speed: numberOrNull(coords.speed),\n speed_accuracy: null,\n heading: numberOrNull(coords.heading),\n heading_accuracy: null,\n },\n activity: { type: 'unknown', confidence: 0 },\n battery: { level: -1, is_charging: false },\n backend: 'web',\n };\n if (extras && Object.keys(extras).length > 0) {\n location.extras = extras;\n }\n return location;\n}\n"]}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { BatteryOptimizationStatus, CallbackID, Config, CurrentPositionOptions, DeviceInfo, Geofence, HeartbeatStatus, InsertLocationInput, Location, LocationTrackingPlugin, LogLevel, LogQuery, PermissionStatus, PermissionType, PowerManagerInfo, ProviderState, ReadyOptions, Sensors, State, WatchPositionCallback, WatchPositionOptions } from './definitions';
|
|
3
|
+
/**
|
|
4
|
+
* Web implementation. It covers `getCurrentPosition`, `watchPosition` and `clearWatch` (via `navigator.geolocation`),
|
|
5
|
+
* an in-memory config and state, permissions and device info. Nothing is persisted or uploaded, and tracking cannot
|
|
6
|
+
* be started. Every other method rejects with `UNIMPLEMENTED`.
|
|
7
|
+
*
|
|
8
|
+
* Like the Android bridge, methods other than `ready`, `getState`, `checkPermissions`, `requestPermissions` and
|
|
9
|
+
* `getDeviceInfo` reject with `NOT_READY` until `ready()` has resolved.
|
|
10
|
+
*/
|
|
11
|
+
export declare class LocationTrackingWeb extends WebPlugin implements LocationTrackingPlugin {
|
|
12
|
+
private config;
|
|
13
|
+
private isReady;
|
|
14
|
+
private lastPosition;
|
|
15
|
+
private watchSeq;
|
|
16
|
+
private readonly watches;
|
|
17
|
+
ready(options?: ReadyOptions): Promise<State>;
|
|
18
|
+
setConfig(options: {
|
|
19
|
+
config: Config;
|
|
20
|
+
}): Promise<State>;
|
|
21
|
+
reset(options?: {
|
|
22
|
+
config?: Config;
|
|
23
|
+
}): Promise<State>;
|
|
24
|
+
getState(): Promise<State>;
|
|
25
|
+
start(): Promise<State>;
|
|
26
|
+
startGeofences(): Promise<State>;
|
|
27
|
+
stop(): Promise<State>;
|
|
28
|
+
changePace(_options: {
|
|
29
|
+
isMoving: boolean;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Takes `samples` fixes within `timeout` and resolves the most accurate one. With `maximumAge > 0`, a fix this
|
|
33
|
+
* plugin received at most that long ago is returned right away. Like a persisted record on Android, the result is
|
|
34
|
+
* also emitted as a `location` event unless `persist` is false.
|
|
35
|
+
*/
|
|
36
|
+
getCurrentPosition(options?: CurrentPositionOptions): Promise<Location>;
|
|
37
|
+
/**
|
|
38
|
+
* Starts `navigator.geolocation.watchPosition` and resolves its id. The callback gets each fix as a
|
|
39
|
+
* `watch_position` Location, or `(null, { code, message })` on error. `interval` is ignored: the browser decides
|
|
40
|
+
* how often fixes arrive. With `persist: true` each fix is also emitted as a `location` event.
|
|
41
|
+
*/
|
|
42
|
+
watchPosition(options: WatchPositionOptions, callback: WatchPositionCallback): Promise<CallbackID>;
|
|
43
|
+
/** Stops a watch. Unknown ids are ignored. */
|
|
44
|
+
clearWatch(options: {
|
|
45
|
+
id: CallbackID;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
getOdometer(): Promise<{
|
|
48
|
+
odometer: number;
|
|
49
|
+
}>;
|
|
50
|
+
setOdometer(_options: {
|
|
51
|
+
odometer: number;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
odometer: number;
|
|
54
|
+
}>;
|
|
55
|
+
resetOdometer(): Promise<{
|
|
56
|
+
odometer: number;
|
|
57
|
+
}>;
|
|
58
|
+
getLocations(_options?: {
|
|
59
|
+
limit?: number;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
locations: Location[];
|
|
62
|
+
}>;
|
|
63
|
+
getCount(): Promise<{
|
|
64
|
+
count: number;
|
|
65
|
+
}>;
|
|
66
|
+
insertLocation(_options: {
|
|
67
|
+
location: InsertLocationInput;
|
|
68
|
+
}): Promise<{
|
|
69
|
+
uuid: string;
|
|
70
|
+
}>;
|
|
71
|
+
destroyLocations(): Promise<{
|
|
72
|
+
count: number;
|
|
73
|
+
}>;
|
|
74
|
+
destroyLocation(_options: {
|
|
75
|
+
uuid: string;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
deleted: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
sync(): Promise<{
|
|
80
|
+
locations: Location[];
|
|
81
|
+
}>;
|
|
82
|
+
addGeofence(_options: {
|
|
83
|
+
geofence: Geofence;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
addGeofences(_options: {
|
|
86
|
+
geofences: Geofence[];
|
|
87
|
+
}): Promise<void>;
|
|
88
|
+
removeGeofence(_options: {
|
|
89
|
+
identifier: string;
|
|
90
|
+
}): Promise<void>;
|
|
91
|
+
removeGeofences(_options?: {
|
|
92
|
+
identifiers?: string[];
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
getGeofences(): Promise<{
|
|
95
|
+
geofences: Geofence[];
|
|
96
|
+
}>;
|
|
97
|
+
getGeofence(_options: {
|
|
98
|
+
identifier: string;
|
|
99
|
+
}): Promise<{
|
|
100
|
+
geofence: Geofence | null;
|
|
101
|
+
}>;
|
|
102
|
+
geofenceExists(_options: {
|
|
103
|
+
identifier: string;
|
|
104
|
+
}): Promise<{
|
|
105
|
+
exists: boolean;
|
|
106
|
+
}>;
|
|
107
|
+
getHeartbeatStatus(): Promise<HeartbeatStatus>;
|
|
108
|
+
getProviderState(): Promise<ProviderState>;
|
|
109
|
+
isPowerSaveMode(): Promise<{
|
|
110
|
+
isPowerSaveMode: boolean;
|
|
111
|
+
}>;
|
|
112
|
+
getBatteryOptimizationStatus(): Promise<BatteryOptimizationStatus>;
|
|
113
|
+
openBatteryOptimizationSettings(): Promise<{
|
|
114
|
+
opened: boolean;
|
|
115
|
+
}>;
|
|
116
|
+
getPowerManagerInfo(): Promise<PowerManagerInfo>;
|
|
117
|
+
openPowerManagerSettings(): Promise<{
|
|
118
|
+
opened: boolean;
|
|
119
|
+
}>;
|
|
120
|
+
openLocationSettings(): Promise<{
|
|
121
|
+
opened: boolean;
|
|
122
|
+
}>;
|
|
123
|
+
openAppSettings(): Promise<{
|
|
124
|
+
opened: boolean;
|
|
125
|
+
}>;
|
|
126
|
+
/** Best-effort values parsed from `navigator.userAgent`; `platform` is `'web'`. */
|
|
127
|
+
getDeviceInfo(): Promise<DeviceInfo>;
|
|
128
|
+
getSensors(): Promise<Sensors>;
|
|
129
|
+
/** `location` comes from the Permissions API (`'prompt'` when it cannot tell); the other three are `'granted'`. */
|
|
130
|
+
checkPermissions(): Promise<PermissionStatus>;
|
|
131
|
+
/** When `location` is requested and still undecided, asks for a fix so the browser prompts, then reports. */
|
|
132
|
+
requestPermissions(options?: {
|
|
133
|
+
permissions?: PermissionType[];
|
|
134
|
+
}): Promise<PermissionStatus>;
|
|
135
|
+
log(_options: {
|
|
136
|
+
level: Exclude<LogLevel, 'off'>;
|
|
137
|
+
message: string;
|
|
138
|
+
}): Promise<void>;
|
|
139
|
+
getLog(_options?: LogQuery): Promise<{
|
|
140
|
+
log: string;
|
|
141
|
+
}>;
|
|
142
|
+
destroyLog(): Promise<void>;
|
|
143
|
+
uploadLog(_options: {
|
|
144
|
+
url: string;
|
|
145
|
+
headers?: Record<string, string>;
|
|
146
|
+
params?: Record<string, unknown>;
|
|
147
|
+
}): Promise<{
|
|
148
|
+
success: boolean;
|
|
149
|
+
status: number;
|
|
150
|
+
}>;
|
|
151
|
+
emailLog(_options: {
|
|
152
|
+
email: string;
|
|
153
|
+
subject?: string;
|
|
154
|
+
}): Promise<void>;
|
|
155
|
+
private requireReady;
|
|
156
|
+
private requireGeolocation;
|
|
157
|
+
/** `persistence.extras` merged with the call's extras (the call wins), like records created on Android. */
|
|
158
|
+
private recordExtras;
|
|
159
|
+
/**
|
|
160
|
+
* Like `notifyListeners`, but each listener gets its own copy of the payload (as on native, where every listener
|
|
161
|
+
* receives deserialized data), and a throwing listener neither skips the others nor fails the calling method.
|
|
162
|
+
*/
|
|
163
|
+
private emit;
|
|
164
|
+
}
|