@aippy/runtime 0.2.4-dev.3 → 0.2.4-dev.5
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 +34 -11
- package/dist/device/index.js +268 -240
- package/dist/index/index.js +38 -37
- package/dist/runtime-DjBdOttl.js +243 -0
- package/package.json +1 -1
- package/dist/runtime-DOnodF_1.js +0 -165
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-DjBdOttl.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,243 @@
|
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var m = (o, e, n) => e in o ? u(o, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[e] = n;
|
|
3
|
+
var r = (o, e, n) => m(o, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
class d extends Error {
|
|
5
|
+
constructor(n, i = "AIPPY_ERROR", t) {
|
|
6
|
+
super(n);
|
|
7
|
+
r(this, "code");
|
|
8
|
+
r(this, "context");
|
|
9
|
+
this.name = "AippyRuntimeError", this.code = i, this.context = t;
|
|
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 g(o, e = "UNKNOWN_ERROR", n) {
|
|
20
|
+
return new d(o, R[e], n);
|
|
21
|
+
}
|
|
22
|
+
class a {
|
|
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 f {
|
|
35
|
+
constructor() {
|
|
36
|
+
r(this, "listeners", /* @__PURE__ */ new Map());
|
|
37
|
+
}
|
|
38
|
+
addEventListener(e, n) {
|
|
39
|
+
this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(n);
|
|
40
|
+
}
|
|
41
|
+
removeEventListener(e, n) {
|
|
42
|
+
const i = this.listeners.get(e);
|
|
43
|
+
if (i) {
|
|
44
|
+
const t = i.indexOf(n);
|
|
45
|
+
t > -1 && i.splice(t, 1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
emit(e, n) {
|
|
49
|
+
const i = this.listeners.get(e);
|
|
50
|
+
i && i.forEach((t) => t(n));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class y {
|
|
54
|
+
constructor() {
|
|
55
|
+
r(this, "emitter", new f());
|
|
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, n) {
|
|
67
|
+
const i = (t) => {
|
|
68
|
+
n(t);
|
|
69
|
+
};
|
|
70
|
+
return this.emitter.addEventListener(e, i), new a(() => {
|
|
71
|
+
this.emitter.removeEventListener(e, i);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Subscribe to a single message (auto-unsubscribe after first message)
|
|
76
|
+
*/
|
|
77
|
+
once(e, n) {
|
|
78
|
+
const i = this.subscribe(e, (t) => {
|
|
79
|
+
i.cancel(), n(t);
|
|
80
|
+
});
|
|
81
|
+
return i;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class h {
|
|
85
|
+
constructor() {
|
|
86
|
+
r(this, "receiveChannel", new y());
|
|
87
|
+
r(this, "seq", 0);
|
|
88
|
+
r(this, "motionListeners", []);
|
|
89
|
+
r(this, "noListenersWarned", !1);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Unified native data receiver - Routes to specific handlers based on message type
|
|
93
|
+
* Called by native code via: window.aippyRuntime.receiveMessage(message)
|
|
94
|
+
*
|
|
95
|
+
* Supports two message formats:
|
|
96
|
+
* 1. Motion: { command: "navigator.motion", endpoint: "0", data: { motion: {...} } }
|
|
97
|
+
* 2. Tweaks: { "tweakKey": { value: ..., type: ... }, ... }
|
|
98
|
+
*/
|
|
99
|
+
receiveMessage(e) {
|
|
100
|
+
return console.log("📩 [Aippy Runtime] receiveMessage called with:", e), !e || typeof e != "object" ? (console.warn("⚠️ [Aippy Runtime] Invalid message type:", typeof e), Promise.resolve()) : this.isMotionMessage(e) ? (console.log("✅ [Aippy Runtime] Detected MOTION message format, emitting to receive channel"), this.receiveChannel.emit({
|
|
101
|
+
endpoint: e.endpoint,
|
|
102
|
+
payload: e.data
|
|
103
|
+
}), Promise.resolve()) : this.isTweaksMessage(e) ? (console.log("✅ [Aippy Runtime] Detected TWEAKS message format, calling processNativeData"), typeof window < "u" && window.processNativeData && window.processNativeData(e), Promise.resolve()) : (console.warn("⚠️ [Aippy Runtime] Unknown message format:", e), Promise.resolve());
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if message is Motion format
|
|
107
|
+
* Motion: { command: "navigator.motion", endpoint: string, data: object }
|
|
108
|
+
*/
|
|
109
|
+
isMotionMessage(e) {
|
|
110
|
+
return typeof e == "object" && "command" in e && e.command === "navigator.motion" && "endpoint" in e && typeof e.endpoint == "string" && "data" in e && typeof e.data == "object" && e.data !== null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if message is Tweaks format
|
|
114
|
+
* Tweaks: { "key": { value: any, type?: string, ... }, ... }
|
|
115
|
+
*/
|
|
116
|
+
isTweaksMessage(e) {
|
|
117
|
+
if (typeof e != "object" || e === null || "endpoint" in e || "payload" in e)
|
|
118
|
+
return !1;
|
|
119
|
+
const n = Object.keys(e);
|
|
120
|
+
return n.length === 0 ? !1 : n.some((t) => {
|
|
121
|
+
const c = e[t];
|
|
122
|
+
return typeof c == "object" && c !== null && "value" in c;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Create a subscription to native events
|
|
127
|
+
* @param handler - WebKit message handler (e.g., aippyListener)
|
|
128
|
+
* @param subscribePayload - Subscription parameters (e.g., { command: "navigator.motion", type: "motion" })
|
|
129
|
+
* @param callback - Callback to handle received data
|
|
130
|
+
* @returns Cancellable subscription
|
|
131
|
+
*/
|
|
132
|
+
createSubscription(e, n, i) {
|
|
133
|
+
const t = (this.seq++).toString(), c = {
|
|
134
|
+
command: n.command,
|
|
135
|
+
parameters: {
|
|
136
|
+
type: n.type,
|
|
137
|
+
action: "subscribe",
|
|
138
|
+
endpoint: t
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
console.log("📨 [Aippy Runtime] Creating subscription with message:", JSON.stringify(c, null, 2));
|
|
142
|
+
const l = this.receiveChannel.subscribe(t, (s) => {
|
|
143
|
+
if (console.log(`📬 [Aippy Runtime] Received data on endpoint ${t}:`, s), s.error !== void 0) {
|
|
144
|
+
console.warn("⚠️ [Aippy Runtime] Received error, skipping:", s.error);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
i(s);
|
|
148
|
+
});
|
|
149
|
+
try {
|
|
150
|
+
console.log("📤 [Aippy Runtime] Sending postMessage to native iOS:", c), e.postMessage(c), console.log("✅ [Aippy Runtime] postMessage sent successfully");
|
|
151
|
+
} catch (s) {
|
|
152
|
+
console.error("❌ [Aippy Runtime] Failed to send postMessage:", s);
|
|
153
|
+
}
|
|
154
|
+
return new a(() => {
|
|
155
|
+
console.log(`🔌 [Aippy Runtime] Unsubscribing from endpoint ${t}`), l.cancel();
|
|
156
|
+
try {
|
|
157
|
+
const s = {
|
|
158
|
+
command: n.command,
|
|
159
|
+
parameters: {
|
|
160
|
+
type: n.type,
|
|
161
|
+
action: "unsubscribe",
|
|
162
|
+
endpoint: t
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
e.postMessage(s), console.log("✅ [Aippy Runtime] Unsubscribe message sent:", s);
|
|
166
|
+
} catch (s) {
|
|
167
|
+
console.error("❌ [Aippy Runtime] Failed to send unsubscribe message:", s);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Add motion listener (convenience method)
|
|
173
|
+
* @param callback - Callback to handle motion data
|
|
174
|
+
* @returns Cleanup function
|
|
175
|
+
*/
|
|
176
|
+
addMotionListener(e) {
|
|
177
|
+
console.log("🎬 [Aippy Runtime] addMotionListener called"), this.motionListeners.push(e), console.log(`📝 [Aippy Runtime] Total motion listeners: ${this.motionListeners.length}`);
|
|
178
|
+
const n = window.webkit?.messageHandlers?.aippyListener;
|
|
179
|
+
if (!n)
|
|
180
|
+
return console.warn("⚠️ [Aippy Runtime] No webkit message handler found, using fallback mode"), () => {
|
|
181
|
+
const t = this.motionListeners.indexOf(e);
|
|
182
|
+
t > -1 && this.motionListeners.splice(t, 1);
|
|
183
|
+
};
|
|
184
|
+
console.log("✅ [Aippy Runtime] Webkit handler found, creating subscription");
|
|
185
|
+
const i = this.createSubscription(
|
|
186
|
+
n,
|
|
187
|
+
{
|
|
188
|
+
command: "navigator.motion",
|
|
189
|
+
type: "motion"
|
|
190
|
+
},
|
|
191
|
+
(t) => {
|
|
192
|
+
console.log("📥 [Aippy Runtime] Received motion data from native:", t), t.motion && e(t.motion);
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
return () => {
|
|
196
|
+
console.log("🧹 [Aippy Runtime] Cleaning up motion listener"), i.cancel();
|
|
197
|
+
const t = this.motionListeners.indexOf(e);
|
|
198
|
+
t > -1 && this.motionListeners.splice(t, 1);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Broadcast motion data to all registered listeners
|
|
203
|
+
* Called by processMotionData when iOS sends data directly
|
|
204
|
+
* @param data - Motion data from iOS
|
|
205
|
+
*/
|
|
206
|
+
broadcastMotionData(e) {
|
|
207
|
+
if (this.motionListeners.length === 0) {
|
|
208
|
+
this.noListenersWarned || (console.warn("⚠️ [Aippy Runtime] No motion listeners to broadcast to"), this.noListenersWarned = !0);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const n = e.motion || e;
|
|
212
|
+
this.motionListeners.forEach((i) => {
|
|
213
|
+
try {
|
|
214
|
+
i(n);
|
|
215
|
+
} catch (t) {
|
|
216
|
+
console.error("⚠️ [Aippy Runtime] Error in motion listener:", t);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function w(o) {
|
|
222
|
+
if (!o || typeof o != "object") {
|
|
223
|
+
console.warn("⚠️ [Aippy Runtime] Invalid motion data type:", typeof o);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!("motion" in o) || typeof o.motion != "object") {
|
|
227
|
+
console.warn("⚠️ [Aippy Runtime] Motion data missing valid motion field");
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
p.broadcastMotionData(o);
|
|
231
|
+
}
|
|
232
|
+
const p = new h();
|
|
233
|
+
typeof window < "u" && (window.aippyRuntime = p, window.processMotionData = w);
|
|
234
|
+
export {
|
|
235
|
+
d as A,
|
|
236
|
+
a as C,
|
|
237
|
+
R as E,
|
|
238
|
+
y as R,
|
|
239
|
+
h as a,
|
|
240
|
+
p as b,
|
|
241
|
+
g as c,
|
|
242
|
+
w as p
|
|
243
|
+
};
|
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
|
-
};
|