@aippy/runtime 0.2.4-dev.3 → 0.2.4-dev.4
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/dist/core/index.js +7 -6
- package/dist/core/runtime.d.ts +31 -5
- package/dist/device/index.js +6 -6
- package/dist/index/index.js +38 -37
- package/dist/runtime-Boz38wSz.js +227 -0
- package/package.json +1 -1
- package/dist/runtime-DOnodF_1.js +0 -165
package/dist/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as d, A as f, C as u, E as A, R as _, b as m, c as R } from "../runtime-
|
|
1
|
+
import { a as d, A as f, C as u, E as A, R as _, b as m, c as R, p as g } from "../runtime-Boz38wSz.js";
|
|
2
2
|
const s = {
|
|
3
3
|
mode: "development",
|
|
4
4
|
debug: !1,
|
|
@@ -22,13 +22,13 @@ function c(e) {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
const r = "0.2.4-dev.
|
|
25
|
+
const r = "0.2.4-dev.4", a = {
|
|
26
26
|
version: r
|
|
27
|
-
},
|
|
27
|
+
}, i = a.version, t = "@aippy/runtime";
|
|
28
28
|
function p() {
|
|
29
29
|
return {
|
|
30
30
|
name: t,
|
|
31
|
-
version:
|
|
31
|
+
version: i,
|
|
32
32
|
buildTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
33
33
|
};
|
|
34
34
|
}
|
|
@@ -40,10 +40,11 @@ export {
|
|
|
40
40
|
A as ERROR_CODES,
|
|
41
41
|
_ as ReceiveChannel,
|
|
42
42
|
t as SDK_NAME,
|
|
43
|
-
|
|
43
|
+
i as VERSION,
|
|
44
44
|
m as aippyRuntime,
|
|
45
45
|
R as createError,
|
|
46
46
|
o as getConfigFromEnv,
|
|
47
47
|
p as getVersionInfo,
|
|
48
|
-
c as mergeConfig
|
|
48
|
+
c as mergeConfig,
|
|
49
|
+
g as processMotionData
|
|
49
50
|
};
|
package/dist/core/runtime.d.ts
CHANGED
|
@@ -38,14 +38,26 @@ export declare class ReceiveChannel {
|
|
|
38
38
|
export declare class AippyRuntime {
|
|
39
39
|
receiveChannel: ReceiveChannel;
|
|
40
40
|
private seq;
|
|
41
|
+
private motionListeners;
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
+
* Unified native data receiver - Routes to specific handlers based on message type
|
|
43
44
|
* Called by native code via: window.aippyRuntime.receiveMessage(message)
|
|
45
|
+
*
|
|
46
|
+
* Supports two message formats:
|
|
47
|
+
* 1. Motion: { endpoint: "0", payload: { motion: {...} } }
|
|
48
|
+
* 2. Tweaks: { "tweakKey": { value: ..., type: ... }, ... }
|
|
44
49
|
*/
|
|
45
|
-
receiveMessage(message:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
receiveMessage(message: any): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Check if message is Motion format
|
|
53
|
+
* Motion: { endpoint: string, payload: object }
|
|
54
|
+
*/
|
|
55
|
+
private isMotionMessage;
|
|
56
|
+
/**
|
|
57
|
+
* Check if message is Tweaks format
|
|
58
|
+
* Tweaks: { "key": { value: any, type?: string, ... }, ... }
|
|
59
|
+
*/
|
|
60
|
+
private isTweaksMessage;
|
|
49
61
|
/**
|
|
50
62
|
* Create a subscription to native events
|
|
51
63
|
* @param handler - WebKit message handler (e.g., deviceMotionHandler)
|
|
@@ -64,7 +76,21 @@ export declare class AippyRuntime {
|
|
|
64
76
|
* @returns Cleanup function
|
|
65
77
|
*/
|
|
66
78
|
addMotionListener(callback: (data: any) => void): () => void;
|
|
79
|
+
/**
|
|
80
|
+
* Broadcast motion data to all registered listeners
|
|
81
|
+
* Called by processMotionData when iOS sends data directly
|
|
82
|
+
* @param data - Motion data from iOS
|
|
83
|
+
*/
|
|
84
|
+
broadcastMotionData(data: any): void;
|
|
67
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Process Motion data from iOS native layer
|
|
88
|
+
* Called by native code via: window.processMotionData(data)
|
|
89
|
+
*
|
|
90
|
+
* @param data - Motion data in simplified format
|
|
91
|
+
* Expected format: { motion: { gravity: {x, y, z}, acceleration: {...}, rotation: {...} } }
|
|
92
|
+
*/
|
|
93
|
+
export declare function processMotionData(data: any): void;
|
|
68
94
|
/**
|
|
69
95
|
* Global runtime instance - Singleton pattern
|
|
70
96
|
*/
|
package/dist/device/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var v = Object.defineProperty;
|
|
2
2
|
var f = (c, t, e) => t in c ? v(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
|
|
3
3
|
var p = (c, t, e) => f(c, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { c as a, b as E } from "../runtime-
|
|
4
|
+
import { c as a, b as E } from "../runtime-Boz38wSz.js";
|
|
5
5
|
class P {
|
|
6
6
|
constructor() {
|
|
7
7
|
p(this, "stream", null);
|
|
@@ -171,7 +171,7 @@ function h() {
|
|
|
171
171
|
return "DeviceOrientationEvent" in window;
|
|
172
172
|
}
|
|
173
173
|
function g() {
|
|
174
|
-
return typeof window < "u" && !!window.webkit?.messageHandlers?.
|
|
174
|
+
return typeof window < "u" && !!window.webkit?.messageHandlers?.aippyListener;
|
|
175
175
|
}
|
|
176
176
|
async function y() {
|
|
177
177
|
if (g())
|
|
@@ -276,10 +276,10 @@ function N(c, t = !0) {
|
|
|
276
276
|
e = !1, window.removeEventListener("devicemotion", o), i && (i(), i = null);
|
|
277
277
|
};
|
|
278
278
|
}
|
|
279
|
-
function
|
|
279
|
+
function L(c, t = !0) {
|
|
280
280
|
return g() ? R(c) : N(c, t);
|
|
281
281
|
}
|
|
282
|
-
function
|
|
282
|
+
function x(c) {
|
|
283
283
|
if (!h())
|
|
284
284
|
throw a("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
285
285
|
const t = (e) => {
|
|
@@ -523,6 +523,6 @@ export {
|
|
|
523
523
|
y as requestMotionPermission,
|
|
524
524
|
M as sensors,
|
|
525
525
|
k as vibrate,
|
|
526
|
-
|
|
527
|
-
|
|
526
|
+
L as watchMotion,
|
|
527
|
+
x as watchOrientation
|
|
528
528
|
};
|
package/dist/index/index.js
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
import { DEFAULT_CONFIG as o, SDK_NAME as
|
|
2
|
-
import { a as m, A as c, C as d, E as f, R as u, b as l, c as A } from "../runtime-
|
|
3
|
-
import { CameraAPI as
|
|
4
|
-
import { c as
|
|
5
|
-
import { a as
|
|
6
|
-
import { c as
|
|
7
|
-
import { reportScore as
|
|
1
|
+
import { DEFAULT_CONFIG as o, SDK_NAME as t, VERSION as r, getConfigFromEnv as i, getVersionInfo as s, mergeConfig as n } from "../core/index.js";
|
|
2
|
+
import { a as m, A as c, C as d, E as f, R as u, b as l, c as A, p as S } from "../runtime-Boz38wSz.js";
|
|
3
|
+
import { CameraAPI as C, FileSystemAPI as R, GeolocationAPI as x, SensorsAPI as M, camera as P, fileSystem as I, geolocation as g, hasNativeBridge as y, isMotionSupported as O, isOrientationSupported as b, requestMotionPermission as v, sensors as D, vibrate as h, watchMotion as w, watchOrientation as F } from "../device/index.js";
|
|
4
|
+
import { c as T, a as V, P as _, b as k, p as G, d as H } from "../pwa-8DGmPqLV.js";
|
|
5
|
+
import { a as q, b as B } from "../useTweaks-QxMRmg7i.js";
|
|
6
|
+
import { c as L, a as W, b as j, i as z, p as J, u as Q } from "../useAudioContext-CNQQSTab.js";
|
|
7
|
+
import { reportScore as Y, sendEvent as Z, updateScore as $ } from "../leaderboard/index.js";
|
|
8
8
|
export {
|
|
9
9
|
m as AippyRuntime,
|
|
10
10
|
c as AippyRuntimeError,
|
|
11
|
-
|
|
11
|
+
C as CameraAPI,
|
|
12
12
|
d as Cancellable,
|
|
13
13
|
o as DEFAULT_CONFIG,
|
|
14
14
|
f as ERROR_CODES,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
R as FileSystemAPI,
|
|
16
|
+
x as GeolocationAPI,
|
|
17
|
+
T as PWAUtils,
|
|
18
|
+
V as PerformanceMonitor,
|
|
19
|
+
_ as PlatformDetector,
|
|
20
20
|
u as ReceiveChannel,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
t as SDK_NAME,
|
|
22
|
+
M as SensorsAPI,
|
|
23
|
+
r as VERSION,
|
|
24
24
|
l as aippyRuntime,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
q as aippyTweaks,
|
|
26
|
+
B as aippyTweaksRuntime,
|
|
27
27
|
P as camera,
|
|
28
28
|
A as createError,
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
L as createHiddenMediaElement,
|
|
30
|
+
W as createHiddenVideoElement,
|
|
31
31
|
I as fileSystem,
|
|
32
|
-
|
|
32
|
+
g as geolocation,
|
|
33
33
|
i as getConfigFromEnv,
|
|
34
34
|
s as getVersionInfo,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
y as hasNativeBridge,
|
|
36
|
+
j as isIOSDevice,
|
|
37
|
+
z as isMediaStreamAudioSupported,
|
|
38
|
+
O as isMotionSupported,
|
|
39
|
+
b as isOrientationSupported,
|
|
40
40
|
n as mergeConfig,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
J as patchAudioContext,
|
|
42
|
+
k as performanceMonitor,
|
|
43
|
+
G as platform,
|
|
44
|
+
S as processMotionData,
|
|
45
|
+
H as pwa,
|
|
46
|
+
Y as reportScore,
|
|
47
|
+
v as requestMotionPermission,
|
|
48
|
+
Z as sendEvent,
|
|
49
|
+
D as sensors,
|
|
50
|
+
$ as updateScore,
|
|
51
|
+
Q as useAudioContext,
|
|
51
52
|
h as vibrate,
|
|
52
53
|
w as watchMotion,
|
|
53
|
-
|
|
54
|
+
F as watchOrientation
|
|
54
55
|
};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
var l = Object.defineProperty;
|
|
2
|
+
var u = (o, e, t) => e in o ? l(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var s = (o, e, t) => u(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
class d extends Error {
|
|
5
|
+
constructor(t, n = "AIPPY_ERROR", i) {
|
|
6
|
+
super(t);
|
|
7
|
+
s(this, "code");
|
|
8
|
+
s(this, "context");
|
|
9
|
+
this.name = "AippyRuntimeError", this.code = n, this.context = i;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const f = {
|
|
13
|
+
NOT_SUPPORTED: "NOT_SUPPORTED",
|
|
14
|
+
PERMISSION_DENIED: "PERMISSION_DENIED",
|
|
15
|
+
INVALID_CONFIG: "INVALID_CONFIG",
|
|
16
|
+
NETWORK_ERROR: "NETWORK_ERROR",
|
|
17
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
18
|
+
};
|
|
19
|
+
function E(o, e = "UNKNOWN_ERROR", t) {
|
|
20
|
+
return new d(o, f[e], t);
|
|
21
|
+
}
|
|
22
|
+
class a {
|
|
23
|
+
constructor(e) {
|
|
24
|
+
s(this, "cancelled", !1);
|
|
25
|
+
this.cancelFn = e;
|
|
26
|
+
}
|
|
27
|
+
cancel() {
|
|
28
|
+
this.cancelled || (this.cancelled = !0, this.cancelFn?.());
|
|
29
|
+
}
|
|
30
|
+
get isCancelled() {
|
|
31
|
+
return this.cancelled;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class h {
|
|
35
|
+
constructor() {
|
|
36
|
+
s(this, "listeners", /* @__PURE__ */ new Map());
|
|
37
|
+
}
|
|
38
|
+
addEventListener(e, t) {
|
|
39
|
+
this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(t);
|
|
40
|
+
}
|
|
41
|
+
removeEventListener(e, t) {
|
|
42
|
+
const n = this.listeners.get(e);
|
|
43
|
+
if (n) {
|
|
44
|
+
const i = n.indexOf(t);
|
|
45
|
+
i > -1 && n.splice(i, 1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
emit(e, t) {
|
|
49
|
+
const n = this.listeners.get(e);
|
|
50
|
+
n && n.forEach((i) => i(t));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class m {
|
|
54
|
+
constructor() {
|
|
55
|
+
s(this, "emitter", new h());
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Emit a message to subscribers
|
|
59
|
+
*/
|
|
60
|
+
emit(e) {
|
|
61
|
+
this.emitter.emit(e.endpoint, e.payload);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Subscribe to messages on a specific endpoint
|
|
65
|
+
*/
|
|
66
|
+
subscribe(e, t) {
|
|
67
|
+
const n = (i) => {
|
|
68
|
+
t(i);
|
|
69
|
+
};
|
|
70
|
+
return this.emitter.addEventListener(e, n), new a(() => {
|
|
71
|
+
this.emitter.removeEventListener(e, n);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Subscribe to a single message (auto-unsubscribe after first message)
|
|
76
|
+
*/
|
|
77
|
+
once(e, t) {
|
|
78
|
+
const n = this.subscribe(e, (i) => {
|
|
79
|
+
n.cancel(), t(i);
|
|
80
|
+
});
|
|
81
|
+
return n;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class R {
|
|
85
|
+
constructor() {
|
|
86
|
+
s(this, "receiveChannel", new m());
|
|
87
|
+
s(this, "seq", 0);
|
|
88
|
+
s(this, "motionListeners", []);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Unified native data receiver - Routes to specific handlers based on message type
|
|
92
|
+
* Called by native code via: window.aippyRuntime.receiveMessage(message)
|
|
93
|
+
*
|
|
94
|
+
* Supports two message formats:
|
|
95
|
+
* 1. Motion: { endpoint: "0", payload: { motion: {...} } }
|
|
96
|
+
* 2. Tweaks: { "tweakKey": { value: ..., type: ... }, ... }
|
|
97
|
+
*/
|
|
98
|
+
receiveMessage(e) {
|
|
99
|
+
return !e || typeof e != "object" ? (console.warn("⚠️ [Aippy Runtime] Invalid message type:", typeof e), Promise.resolve()) : this.isMotionMessage(e) ? (this.receiveChannel.emit(e), Promise.resolve()) : this.isTweaksMessage(e) ? (typeof window < "u" && window.processNativeData && window.processNativeData(e), Promise.resolve()) : (console.warn("⚠️ [Aippy Runtime] Unknown message format:", e), Promise.resolve());
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if message is Motion format
|
|
103
|
+
* Motion: { endpoint: string, payload: object }
|
|
104
|
+
*/
|
|
105
|
+
isMotionMessage(e) {
|
|
106
|
+
return typeof e == "object" && "endpoint" in e && typeof e.endpoint == "string" && "payload" in e && typeof e.payload == "object" && e.payload !== null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if message is Tweaks format
|
|
110
|
+
* Tweaks: { "key": { value: any, type?: string, ... }, ... }
|
|
111
|
+
*/
|
|
112
|
+
isTweaksMessage(e) {
|
|
113
|
+
if (typeof e != "object" || e === null || "endpoint" in e || "payload" in e)
|
|
114
|
+
return !1;
|
|
115
|
+
const t = Object.keys(e);
|
|
116
|
+
return t.length === 0 ? !1 : t.some((i) => {
|
|
117
|
+
const r = e[i];
|
|
118
|
+
return typeof r == "object" && r !== null && "value" in r;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a subscription to native events
|
|
123
|
+
* @param handler - WebKit message handler (e.g., deviceMotionHandler)
|
|
124
|
+
* @param subscribePayload - Subscription parameters (e.g., { type: "motion" })
|
|
125
|
+
* @param callback - Callback to handle received data
|
|
126
|
+
* @returns Cancellable subscription
|
|
127
|
+
*/
|
|
128
|
+
createSubscription(e, t, n) {
|
|
129
|
+
const i = this.makeSubscriptionMessage(t), r = this.receiveChannel.subscribe(i.endpoint, (c) => {
|
|
130
|
+
c.error === void 0 && n(c);
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
e.postMessage(i);
|
|
134
|
+
} catch {
|
|
135
|
+
}
|
|
136
|
+
return new a(() => {
|
|
137
|
+
r.cancel();
|
|
138
|
+
try {
|
|
139
|
+
e.postMessage({
|
|
140
|
+
endpoint: i.endpoint,
|
|
141
|
+
payload: "unsubscribe"
|
|
142
|
+
});
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Make a subscription message with unique endpoint
|
|
149
|
+
*/
|
|
150
|
+
makeSubscriptionMessage(e) {
|
|
151
|
+
return {
|
|
152
|
+
endpoint: (this.seq++).toString(),
|
|
153
|
+
payload: {
|
|
154
|
+
subscribe: e
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Add motion listener (convenience method)
|
|
160
|
+
* @param callback - Callback to handle motion data
|
|
161
|
+
* @returns Cleanup function
|
|
162
|
+
*/
|
|
163
|
+
addMotionListener(e) {
|
|
164
|
+
this.motionListeners.push(e);
|
|
165
|
+
const t = window.webkit?.messageHandlers?.aippyListener;
|
|
166
|
+
if (!t)
|
|
167
|
+
return () => {
|
|
168
|
+
const i = this.motionListeners.indexOf(e);
|
|
169
|
+
i > -1 && this.motionListeners.splice(i, 1);
|
|
170
|
+
};
|
|
171
|
+
const n = this.createSubscription(
|
|
172
|
+
t,
|
|
173
|
+
{
|
|
174
|
+
command: "navigator.motion",
|
|
175
|
+
type: "motion"
|
|
176
|
+
},
|
|
177
|
+
(i) => {
|
|
178
|
+
i.motion && e(i.motion);
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
return () => {
|
|
182
|
+
n.cancel();
|
|
183
|
+
const i = this.motionListeners.indexOf(e);
|
|
184
|
+
i > -1 && this.motionListeners.splice(i, 1);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Broadcast motion data to all registered listeners
|
|
189
|
+
* Called by processMotionData when iOS sends data directly
|
|
190
|
+
* @param data - Motion data from iOS
|
|
191
|
+
*/
|
|
192
|
+
broadcastMotionData(e) {
|
|
193
|
+
if (this.motionListeners.length === 0)
|
|
194
|
+
return;
|
|
195
|
+
const t = e.motion || e;
|
|
196
|
+
this.motionListeners.forEach((n) => {
|
|
197
|
+
try {
|
|
198
|
+
n(t);
|
|
199
|
+
} catch (i) {
|
|
200
|
+
console.error("⚠️ [Aippy Runtime] Error in motion listener:", i);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function y(o) {
|
|
206
|
+
if (!o || typeof o != "object") {
|
|
207
|
+
console.warn("⚠️ [Aippy Runtime] Invalid motion data type:", typeof o);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (!("motion" in o) || typeof o.motion != "object") {
|
|
211
|
+
console.warn("⚠️ [Aippy Runtime] Motion data missing valid motion field");
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
p.broadcastMotionData(o);
|
|
215
|
+
}
|
|
216
|
+
const p = new R();
|
|
217
|
+
typeof window < "u" && (window.aippyRuntime = p, window.processMotionData = y);
|
|
218
|
+
export {
|
|
219
|
+
d as A,
|
|
220
|
+
a as C,
|
|
221
|
+
f as E,
|
|
222
|
+
m as R,
|
|
223
|
+
R as a,
|
|
224
|
+
p as b,
|
|
225
|
+
E as c,
|
|
226
|
+
y as p
|
|
227
|
+
};
|
package/package.json
CHANGED
package/dist/runtime-DOnodF_1.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
var l = Object.defineProperty;
|
|
2
|
-
var p = (i, e, t) => e in i ? l(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
-
var r = (i, e, t) => p(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
class u extends Error {
|
|
5
|
-
constructor(t, s = "AIPPY_ERROR", n) {
|
|
6
|
-
super(t);
|
|
7
|
-
r(this, "code");
|
|
8
|
-
r(this, "context");
|
|
9
|
-
this.name = "AippyRuntimeError", this.code = s, this.context = n;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
const R = {
|
|
13
|
-
NOT_SUPPORTED: "NOT_SUPPORTED",
|
|
14
|
-
PERMISSION_DENIED: "PERMISSION_DENIED",
|
|
15
|
-
INVALID_CONFIG: "INVALID_CONFIG",
|
|
16
|
-
NETWORK_ERROR: "NETWORK_ERROR",
|
|
17
|
-
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
18
|
-
};
|
|
19
|
-
function O(i, e = "UNKNOWN_ERROR", t) {
|
|
20
|
-
return new u(i, R[e], t);
|
|
21
|
-
}
|
|
22
|
-
class o {
|
|
23
|
-
constructor(e) {
|
|
24
|
-
r(this, "cancelled", !1);
|
|
25
|
-
this.cancelFn = e;
|
|
26
|
-
}
|
|
27
|
-
cancel() {
|
|
28
|
-
this.cancelled || (this.cancelled = !0, this.cancelFn?.());
|
|
29
|
-
}
|
|
30
|
-
get isCancelled() {
|
|
31
|
-
return this.cancelled;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
class d {
|
|
35
|
-
constructor() {
|
|
36
|
-
r(this, "listeners", /* @__PURE__ */ new Map());
|
|
37
|
-
}
|
|
38
|
-
addEventListener(e, t) {
|
|
39
|
-
this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(t);
|
|
40
|
-
}
|
|
41
|
-
removeEventListener(e, t) {
|
|
42
|
-
const s = this.listeners.get(e);
|
|
43
|
-
if (s) {
|
|
44
|
-
const n = s.indexOf(t);
|
|
45
|
-
n > -1 && s.splice(n, 1);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
emit(e, t) {
|
|
49
|
-
const s = this.listeners.get(e);
|
|
50
|
-
s && s.forEach((n) => n(t));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
class h {
|
|
54
|
-
constructor() {
|
|
55
|
-
r(this, "emitter", new d());
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Emit a message to subscribers
|
|
59
|
-
*/
|
|
60
|
-
emit(e) {
|
|
61
|
-
this.emitter.emit(e.endpoint, e.payload);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Subscribe to messages on a specific endpoint
|
|
65
|
-
*/
|
|
66
|
-
subscribe(e, t) {
|
|
67
|
-
const s = (n) => {
|
|
68
|
-
t(n);
|
|
69
|
-
};
|
|
70
|
-
return this.emitter.addEventListener(e, s), new o(() => {
|
|
71
|
-
this.emitter.removeEventListener(e, s);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Subscribe to a single message (auto-unsubscribe after first message)
|
|
76
|
-
*/
|
|
77
|
-
once(e, t) {
|
|
78
|
-
const s = this.subscribe(e, (n) => {
|
|
79
|
-
s.cancel(), t(n);
|
|
80
|
-
});
|
|
81
|
-
return s;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
class E {
|
|
85
|
-
constructor() {
|
|
86
|
-
r(this, "receiveChannel", new h());
|
|
87
|
-
r(this, "seq", 0);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Receive message from native layer
|
|
91
|
-
* Called by native code via: window.aippyRuntime.receiveMessage(message)
|
|
92
|
-
*/
|
|
93
|
-
receiveMessage(e) {
|
|
94
|
-
return this.receiveChannel.emit(e), Promise.resolve();
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Create a subscription to native events
|
|
98
|
-
* @param handler - WebKit message handler (e.g., deviceMotionHandler)
|
|
99
|
-
* @param subscribePayload - Subscription parameters (e.g., { type: "motion" })
|
|
100
|
-
* @param callback - Callback to handle received data
|
|
101
|
-
* @returns Cancellable subscription
|
|
102
|
-
*/
|
|
103
|
-
createSubscription(e, t, s) {
|
|
104
|
-
const n = this.makeSubscriptionMessage(t), a = this.receiveChannel.subscribe(n.endpoint, (c) => {
|
|
105
|
-
c.error === void 0 && s(c);
|
|
106
|
-
});
|
|
107
|
-
try {
|
|
108
|
-
e.postMessage(n);
|
|
109
|
-
} catch {
|
|
110
|
-
}
|
|
111
|
-
return new o(() => {
|
|
112
|
-
a.cancel();
|
|
113
|
-
try {
|
|
114
|
-
e.postMessage({
|
|
115
|
-
endpoint: n.endpoint,
|
|
116
|
-
payload: "unsubscribe"
|
|
117
|
-
});
|
|
118
|
-
} catch {
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Make a subscription message with unique endpoint
|
|
124
|
-
*/
|
|
125
|
-
makeSubscriptionMessage(e) {
|
|
126
|
-
return {
|
|
127
|
-
endpoint: (this.seq++).toString(),
|
|
128
|
-
payload: {
|
|
129
|
-
subscribe: e
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Add motion listener (convenience method)
|
|
135
|
-
* @param callback - Callback to handle motion data
|
|
136
|
-
* @returns Cleanup function
|
|
137
|
-
*/
|
|
138
|
-
addMotionListener(e) {
|
|
139
|
-
const t = window.webkit?.messageHandlers?.deviceMotionHandler;
|
|
140
|
-
if (!t)
|
|
141
|
-
return () => {
|
|
142
|
-
};
|
|
143
|
-
const s = this.createSubscription(
|
|
144
|
-
t,
|
|
145
|
-
{ type: "motion" },
|
|
146
|
-
(n) => {
|
|
147
|
-
n.motion && e(n.motion);
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
return () => {
|
|
151
|
-
s.cancel();
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const m = new E();
|
|
156
|
-
typeof window < "u" && (window.aippyRuntime = m);
|
|
157
|
-
export {
|
|
158
|
-
u as A,
|
|
159
|
-
o as C,
|
|
160
|
-
R as E,
|
|
161
|
-
h as R,
|
|
162
|
-
E as a,
|
|
163
|
-
m as b,
|
|
164
|
-
O as c
|
|
165
|
-
};
|