@aippy/runtime 0.2.4-dev.7 โ 0.2.4-dev.9
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
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, p as g } 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-DjBdOttl.js";
|
|
2
2
|
const s = {
|
|
3
3
|
mode: "development",
|
|
4
4
|
debug: !1,
|
|
@@ -22,7 +22,7 @@ function c(e) {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
const r = "0.2.4-dev.
|
|
25
|
+
const r = "0.2.4-dev.9", a = {
|
|
26
26
|
version: r
|
|
27
27
|
}, i = a.version, t = "@aippy/runtime";
|
|
28
28
|
function p() {
|
package/dist/core/runtime.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare class AippyRuntime {
|
|
|
39
39
|
receiveChannel: ReceiveChannel;
|
|
40
40
|
private seq;
|
|
41
41
|
private motionListeners;
|
|
42
|
+
private noListenersWarned;
|
|
42
43
|
/**
|
|
43
44
|
* Unified native data receiver - Routes to specific handlers based on message type
|
|
44
45
|
* Called by native code via: window.aippyRuntime.receiveMessage(message)
|
package/dist/device/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { c as s, b as
|
|
5
|
-
class
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var k = (n, e, t) => e in n ? L(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var R = (n, e, t) => k(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { c as s, b as T } from "../runtime-DjBdOttl.js";
|
|
5
|
+
class _ {
|
|
6
6
|
constructor() {
|
|
7
|
-
|
|
7
|
+
R(this, "stream", null);
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Check if camera is supported
|
|
@@ -15,21 +15,21 @@ class P {
|
|
|
15
15
|
/**
|
|
16
16
|
* Get camera stream
|
|
17
17
|
*/
|
|
18
|
-
async getStream(
|
|
18
|
+
async getStream(e = {}) {
|
|
19
19
|
if (!this.isSupported())
|
|
20
20
|
throw s("Camera API is not supported", "NOT_SUPPORTED");
|
|
21
21
|
try {
|
|
22
|
-
const
|
|
22
|
+
const t = {
|
|
23
23
|
video: {
|
|
24
|
-
width:
|
|
25
|
-
height:
|
|
26
|
-
facingMode:
|
|
24
|
+
width: e.width,
|
|
25
|
+
height: e.height,
|
|
26
|
+
facingMode: e.facingMode || "environment"
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
return this.stream = await navigator.mediaDevices.getUserMedia(
|
|
30
|
-
} catch (
|
|
29
|
+
return this.stream = await navigator.mediaDevices.getUserMedia(t), this.stream;
|
|
30
|
+
} catch (t) {
|
|
31
31
|
throw s(
|
|
32
|
-
`Failed to access camera: ${
|
|
32
|
+
`Failed to access camera: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
33
33
|
"PERMISSION_DENIED"
|
|
34
34
|
);
|
|
35
35
|
}
|
|
@@ -37,30 +37,30 @@ class P {
|
|
|
37
37
|
/**
|
|
38
38
|
* Capture photo from stream
|
|
39
39
|
*/
|
|
40
|
-
async capturePhoto(
|
|
40
|
+
async capturePhoto(e = {}) {
|
|
41
41
|
if (!this.stream)
|
|
42
42
|
throw s("No camera stream available", "NOT_SUPPORTED");
|
|
43
43
|
try {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
44
|
+
const t = document.createElement("video");
|
|
45
|
+
t.srcObject = this.stream, t.play();
|
|
46
|
+
const o = document.createElement("canvas"), i = o.getContext("2d");
|
|
47
|
+
if (!i)
|
|
48
48
|
throw s("Failed to get canvas context", "UNKNOWN_ERROR");
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, `image/${
|
|
54
|
-
}),
|
|
49
|
+
o.width = e.width || t.videoWidth, o.height = e.height || t.videoHeight, i.drawImage(t, 0, 0, o.width, o.height);
|
|
50
|
+
const r = e.format || "jpeg", c = e.quality === "high" ? 0.9 : e.quality === "medium" ? 0.7 : 0.5, a = await new Promise((u, m) => {
|
|
51
|
+
o.toBlob((l) => {
|
|
52
|
+
l ? u(l) : m(new Error("Failed to create blob"));
|
|
53
|
+
}, `image/${r}`, c);
|
|
54
|
+
}), d = o.toDataURL(`image/${r}`, c);
|
|
55
55
|
return {
|
|
56
|
-
blob:
|
|
57
|
-
dataUrl:
|
|
58
|
-
width:
|
|
59
|
-
height:
|
|
56
|
+
blob: a,
|
|
57
|
+
dataUrl: d,
|
|
58
|
+
width: o.width,
|
|
59
|
+
height: o.height
|
|
60
60
|
};
|
|
61
|
-
} catch (
|
|
61
|
+
} catch (t) {
|
|
62
62
|
throw s(
|
|
63
|
-
`Failed to capture photo: ${
|
|
63
|
+
`Failed to capture photo: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
64
64
|
"UNKNOWN_ERROR"
|
|
65
65
|
);
|
|
66
66
|
}
|
|
@@ -69,11 +69,11 @@ class P {
|
|
|
69
69
|
* Stop camera stream
|
|
70
70
|
*/
|
|
71
71
|
stopStream() {
|
|
72
|
-
this.stream && (this.stream.getTracks().forEach((
|
|
72
|
+
this.stream && (this.stream.getTracks().forEach((e) => e.stop()), this.stream = null);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
const
|
|
76
|
-
class
|
|
75
|
+
const C = new _();
|
|
76
|
+
class F {
|
|
77
77
|
/**
|
|
78
78
|
* Check if geolocation is supported
|
|
79
79
|
*/
|
|
@@ -83,244 +83,258 @@ class O {
|
|
|
83
83
|
/**
|
|
84
84
|
* Get current position
|
|
85
85
|
*/
|
|
86
|
-
async getCurrentPosition(
|
|
86
|
+
async getCurrentPosition(e = {}) {
|
|
87
87
|
if (!this.isSupported())
|
|
88
88
|
throw s("Geolocation API is not supported", "NOT_SUPPORTED");
|
|
89
|
-
return new Promise((
|
|
90
|
-
const
|
|
91
|
-
enableHighAccuracy:
|
|
92
|
-
timeout:
|
|
93
|
-
maximumAge:
|
|
89
|
+
return new Promise((t, o) => {
|
|
90
|
+
const i = {
|
|
91
|
+
enableHighAccuracy: e.enableHighAccuracy ?? !0,
|
|
92
|
+
timeout: e.timeout ?? 1e4,
|
|
93
|
+
maximumAge: e.maximumAge ?? 6e4
|
|
94
94
|
};
|
|
95
95
|
navigator.geolocation.getCurrentPosition(
|
|
96
|
-
(
|
|
97
|
-
const
|
|
98
|
-
latitude:
|
|
99
|
-
longitude:
|
|
100
|
-
accuracy:
|
|
101
|
-
altitude:
|
|
102
|
-
altitudeAccuracy:
|
|
103
|
-
heading:
|
|
104
|
-
speed:
|
|
105
|
-
timestamp:
|
|
96
|
+
(r) => {
|
|
97
|
+
const c = {
|
|
98
|
+
latitude: r.coords.latitude,
|
|
99
|
+
longitude: r.coords.longitude,
|
|
100
|
+
accuracy: r.coords.accuracy,
|
|
101
|
+
altitude: r.coords.altitude ?? void 0,
|
|
102
|
+
altitudeAccuracy: r.coords.altitudeAccuracy ?? void 0,
|
|
103
|
+
heading: r.coords.heading ?? void 0,
|
|
104
|
+
speed: r.coords.speed ?? void 0,
|
|
105
|
+
timestamp: r.timestamp
|
|
106
106
|
};
|
|
107
|
-
|
|
107
|
+
t(c);
|
|
108
108
|
},
|
|
109
|
-
(
|
|
110
|
-
let
|
|
111
|
-
switch (
|
|
112
|
-
case
|
|
113
|
-
|
|
109
|
+
(r) => {
|
|
110
|
+
let c = "UNKNOWN_ERROR", a = "Unknown geolocation error";
|
|
111
|
+
switch (r.code) {
|
|
112
|
+
case r.PERMISSION_DENIED:
|
|
113
|
+
c = "PERMISSION_DENIED", a = "Geolocation permission denied";
|
|
114
114
|
break;
|
|
115
|
-
case
|
|
116
|
-
|
|
115
|
+
case r.POSITION_UNAVAILABLE:
|
|
116
|
+
a = "Position unavailable";
|
|
117
117
|
break;
|
|
118
|
-
case
|
|
119
|
-
|
|
118
|
+
case r.TIMEOUT:
|
|
119
|
+
a = "Geolocation timeout";
|
|
120
120
|
break;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
o(s(a, c));
|
|
123
123
|
},
|
|
124
|
-
|
|
124
|
+
i
|
|
125
125
|
);
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
129
|
* Watch position changes
|
|
130
130
|
*/
|
|
131
|
-
watchPosition(
|
|
131
|
+
watchPosition(e, t = {}) {
|
|
132
132
|
if (!this.isSupported())
|
|
133
133
|
throw s("Geolocation API is not supported", "NOT_SUPPORTED");
|
|
134
|
-
const
|
|
135
|
-
enableHighAccuracy:
|
|
136
|
-
timeout:
|
|
137
|
-
maximumAge:
|
|
134
|
+
const o = {
|
|
135
|
+
enableHighAccuracy: t.enableHighAccuracy ?? !0,
|
|
136
|
+
timeout: t.timeout ?? 1e4,
|
|
137
|
+
maximumAge: t.maximumAge ?? 6e4
|
|
138
138
|
};
|
|
139
139
|
return navigator.geolocation.watchPosition(
|
|
140
|
-
(
|
|
141
|
-
const
|
|
142
|
-
latitude:
|
|
143
|
-
longitude:
|
|
144
|
-
accuracy:
|
|
145
|
-
altitude:
|
|
146
|
-
altitudeAccuracy:
|
|
147
|
-
heading:
|
|
148
|
-
speed:
|
|
149
|
-
timestamp:
|
|
140
|
+
(i) => {
|
|
141
|
+
const r = {
|
|
142
|
+
latitude: i.coords.latitude,
|
|
143
|
+
longitude: i.coords.longitude,
|
|
144
|
+
accuracy: i.coords.accuracy,
|
|
145
|
+
altitude: i.coords.altitude ?? void 0,
|
|
146
|
+
altitudeAccuracy: i.coords.altitudeAccuracy ?? void 0,
|
|
147
|
+
heading: i.coords.heading ?? void 0,
|
|
148
|
+
speed: i.coords.speed ?? void 0,
|
|
149
|
+
timestamp: i.timestamp
|
|
150
150
|
};
|
|
151
|
-
|
|
151
|
+
e(r);
|
|
152
152
|
},
|
|
153
|
-
(
|
|
154
|
-
console.error("Geolocation watch error:",
|
|
153
|
+
(i) => {
|
|
154
|
+
console.error("Geolocation watch error:", i);
|
|
155
155
|
},
|
|
156
|
-
|
|
156
|
+
o
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
160
|
* Clear position watch
|
|
161
161
|
*/
|
|
162
|
-
clearWatch(
|
|
163
|
-
navigator.geolocation.clearWatch(
|
|
162
|
+
clearWatch(e) {
|
|
163
|
+
navigator.geolocation.clearWatch(e);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
const
|
|
167
|
-
function
|
|
166
|
+
const X = new F();
|
|
167
|
+
function P() {
|
|
168
168
|
return "DeviceMotionEvent" in window;
|
|
169
169
|
}
|
|
170
|
-
function
|
|
170
|
+
function I() {
|
|
171
171
|
return "DeviceOrientationEvent" in window;
|
|
172
172
|
}
|
|
173
|
-
function
|
|
174
|
-
const
|
|
173
|
+
function b() {
|
|
174
|
+
const n = typeof window < "u", e = n && !!window.webkit, t = e && !!window.webkit?.messageHandlers, o = t && !!window.webkit?.messageHandlers?.aippyListener;
|
|
175
175
|
return console.log("๐ [Aippy Sensors] hasNativeBridge check:", {
|
|
176
|
-
hasWindow:
|
|
177
|
-
hasWebkit:
|
|
178
|
-
hasMessageHandlers:
|
|
179
|
-
hasAippyListener:
|
|
180
|
-
result:
|
|
181
|
-
}),
|
|
176
|
+
hasWindow: n,
|
|
177
|
+
hasWebkit: e,
|
|
178
|
+
hasMessageHandlers: t,
|
|
179
|
+
hasAippyListener: o,
|
|
180
|
+
result: o
|
|
181
|
+
}), o;
|
|
182
|
+
}
|
|
183
|
+
function D() {
|
|
184
|
+
return typeof window < "u" && typeof window.orientation < "u" ? window.orientation : typeof window < "u" && window.screen?.orientation?.angle !== void 0 ? window.screen.orientation.angle : 0;
|
|
182
185
|
}
|
|
183
|
-
|
|
184
|
-
|
|
186
|
+
function f(n, e, t) {
|
|
187
|
+
switch (t) {
|
|
188
|
+
case 0:
|
|
189
|
+
return [n, e];
|
|
190
|
+
case 180:
|
|
191
|
+
return [-n, -e];
|
|
192
|
+
case 90:
|
|
193
|
+
return [e, -n];
|
|
194
|
+
case -90:
|
|
195
|
+
return [-e, n];
|
|
196
|
+
default:
|
|
197
|
+
return [n, e];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async function U() {
|
|
201
|
+
if (console.log("๐ [Aippy Sensors] requestMotionPermission called"), b())
|
|
185
202
|
return console.log("โ
[Aippy Sensors] Native bridge available, skipping permission request"), !0;
|
|
186
|
-
if (!
|
|
203
|
+
if (!P())
|
|
187
204
|
return console.warn("โ [Aippy Sensors] Device motion not supported"), !1;
|
|
188
|
-
const
|
|
189
|
-
if (console.log("๐ [Aippy Sensors] Permission API available:",
|
|
205
|
+
const n = typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function";
|
|
206
|
+
if (console.log("๐ [Aippy Sensors] Permission API available:", n), n)
|
|
190
207
|
try {
|
|
191
208
|
console.log("๐ [Aippy Sensors] Requesting device motion permission...");
|
|
192
|
-
const
|
|
193
|
-
return console.log("๐ [Aippy Sensors] Permission result:",
|
|
194
|
-
} catch (
|
|
195
|
-
return console.
|
|
209
|
+
const e = await DeviceMotionEvent.requestPermission();
|
|
210
|
+
return console.log("๐ [Aippy Sensors] Permission result:", e), e === "granted";
|
|
211
|
+
} catch (e) {
|
|
212
|
+
return console.warn("โ [Aippy Sensors] Permission request failed:", e), !1;
|
|
196
213
|
}
|
|
197
214
|
return console.log("โ
[Aippy Sensors] No permission needed (granted by default)"), !0;
|
|
198
215
|
}
|
|
199
|
-
function
|
|
216
|
+
function x(n) {
|
|
200
217
|
console.log("๐ง [Aippy Sensors] watchMotionNative - Setting up native bridge listener");
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
const i = {
|
|
218
|
+
const e = T.addMotionListener((t) => {
|
|
219
|
+
const o = D(), i = t.gravity?.x ?? 0, r = t.gravity?.y ?? 0, c = t.gravity?.z ?? 0, a = t.acceleration?.x ?? 0, d = t.acceleration?.y ?? 0, u = t.acceleration?.z ?? 0, [m, l] = f(i, r, o), [h, v] = f(a, d, o), g = -m, y = -l, E = {
|
|
204
220
|
gravity: {
|
|
205
|
-
x:
|
|
206
|
-
y
|
|
207
|
-
z:
|
|
221
|
+
x: g,
|
|
222
|
+
y,
|
|
223
|
+
z: c
|
|
224
|
+
// Z่ฝดไธๅๅฑๅนๆ่ฝฌๅฝฑๅ
|
|
208
225
|
},
|
|
209
226
|
acceleration: {
|
|
210
|
-
x:
|
|
211
|
-
y:
|
|
212
|
-
z:
|
|
227
|
+
x: h,
|
|
228
|
+
y: v,
|
|
229
|
+
z: u
|
|
230
|
+
// Z่ฝดไธๅๅฑๅนๆ่ฝฌๅฝฑๅ
|
|
213
231
|
},
|
|
214
232
|
accelerationIncludingGravity: {
|
|
215
|
-
x:
|
|
216
|
-
y:
|
|
217
|
-
z:
|
|
233
|
+
x: g + h,
|
|
234
|
+
y: y + v,
|
|
235
|
+
z: c + u
|
|
218
236
|
},
|
|
219
237
|
rotation: {
|
|
220
|
-
alpha:
|
|
221
|
-
beta:
|
|
222
|
-
gamma:
|
|
238
|
+
alpha: t.rotation?.alpha ?? 0,
|
|
239
|
+
beta: t.rotation?.beta ?? 0,
|
|
240
|
+
gamma: t.rotation?.gamma ?? 0
|
|
223
241
|
},
|
|
224
242
|
timestamp: Date.now()
|
|
225
243
|
};
|
|
226
|
-
|
|
244
|
+
n(E);
|
|
227
245
|
});
|
|
228
|
-
return console.log("โ
[Aippy Sensors] watchMotionNative - Listener setup complete"),
|
|
246
|
+
return console.log("โ
[Aippy Sensors] watchMotionNative - Listener setup complete"), e;
|
|
229
247
|
}
|
|
230
|
-
function
|
|
231
|
-
if (!
|
|
248
|
+
function G(n, e = !0) {
|
|
249
|
+
if (!P())
|
|
232
250
|
throw s("Device motion API is not supported", "NOT_SUPPORTED");
|
|
233
|
-
let
|
|
234
|
-
const
|
|
235
|
-
if (!
|
|
236
|
-
const
|
|
251
|
+
let t = !1, o = null;
|
|
252
|
+
const i = (a) => {
|
|
253
|
+
if (!t) return;
|
|
254
|
+
const d = D();
|
|
255
|
+
let u, m, l;
|
|
256
|
+
if (a.acceleration) {
|
|
257
|
+
const w = a.accelerationIncludingGravity, p = a.acceleration;
|
|
258
|
+
u = (w?.x ?? 0) - (p?.x ?? 0), m = (w?.y ?? 0) - (p?.y ?? 0), l = (w?.z ?? 0) - (p?.z ?? 0);
|
|
259
|
+
} else {
|
|
260
|
+
const w = a.accelerationIncludingGravity, p = 9.8;
|
|
261
|
+
u = (w?.x ?? 0) / p, m = (w?.y ?? 0) / p, l = (w?.z ?? 0) / p;
|
|
262
|
+
}
|
|
263
|
+
const h = a.acceleration?.x ?? 0, v = a.acceleration?.y ?? 0, g = a.acceleration?.z ?? 0, [y, E] = f(u, m, d), [O, S] = f(h, v, d), A = -y, N = -E, M = {
|
|
237
264
|
gravity: {
|
|
238
|
-
x:
|
|
239
|
-
y:
|
|
240
|
-
z:
|
|
265
|
+
x: A,
|
|
266
|
+
y: N,
|
|
267
|
+
z: l
|
|
268
|
+
// Z่ฝดไธๅๅฑๅนๆ่ฝฌๅฝฑๅ
|
|
241
269
|
},
|
|
242
270
|
acceleration: {
|
|
243
|
-
x:
|
|
244
|
-
y:
|
|
245
|
-
z:
|
|
271
|
+
x: O,
|
|
272
|
+
y: S,
|
|
273
|
+
z: g
|
|
274
|
+
// Z่ฝดไธๅๅฑๅนๆ่ฝฌๅฝฑๅ
|
|
246
275
|
},
|
|
247
276
|
accelerationIncludingGravity: {
|
|
248
|
-
x:
|
|
249
|
-
y:
|
|
250
|
-
z:
|
|
277
|
+
x: A + O,
|
|
278
|
+
y: N + S,
|
|
279
|
+
z: l + g
|
|
251
280
|
},
|
|
252
281
|
rotation: {
|
|
253
|
-
alpha:
|
|
254
|
-
beta:
|
|
255
|
-
gamma:
|
|
282
|
+
alpha: a.rotationRate?.alpha ?? 0,
|
|
283
|
+
beta: a.rotationRate?.beta ?? 0,
|
|
284
|
+
gamma: a.rotationRate?.gamma ?? 0
|
|
256
285
|
},
|
|
257
286
|
timestamp: Date.now()
|
|
258
287
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
x: (l?.x ?? 0) - (u?.x ?? 0),
|
|
263
|
-
y: (l?.y ?? 0) - (u?.y ?? 0),
|
|
264
|
-
z: (l?.z ?? 0) - (u?.z ?? 0)
|
|
265
|
-
};
|
|
266
|
-
} else {
|
|
267
|
-
const l = r.accelerationIncludingGravity, u = 9.8;
|
|
268
|
-
c.gravity = {
|
|
269
|
-
x: (l?.x ?? 0) / u,
|
|
270
|
-
y: (l?.y ?? 0) / u,
|
|
271
|
-
z: (l?.z ?? 0) / u
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
a(c);
|
|
275
|
-
}, n = async () => {
|
|
276
|
-
t && !await y() || (e = !0, window.addEventListener("devicemotion", o));
|
|
288
|
+
n(M);
|
|
289
|
+
}, r = async () => {
|
|
290
|
+
e && !await U() || (t = !0, window.addEventListener("devicemotion", i));
|
|
277
291
|
};
|
|
278
292
|
return (async () => {
|
|
279
|
-
if (typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function" &&
|
|
280
|
-
const
|
|
281
|
-
|
|
293
|
+
if (typeof DeviceMotionEvent < "u" && typeof DeviceMotionEvent.requestPermission == "function" && e) {
|
|
294
|
+
const d = async () => {
|
|
295
|
+
o = null, await r();
|
|
282
296
|
};
|
|
283
|
-
window.addEventListener("click",
|
|
284
|
-
window.removeEventListener("click",
|
|
297
|
+
window.addEventListener("click", d, { once: !0 }), window.addEventListener("touchstart", d, { once: !0 }), o = () => {
|
|
298
|
+
window.removeEventListener("click", d), window.removeEventListener("touchstart", d);
|
|
285
299
|
};
|
|
286
300
|
} else
|
|
287
|
-
await
|
|
301
|
+
await r();
|
|
288
302
|
})(), () => {
|
|
289
|
-
|
|
303
|
+
t = !1, window.removeEventListener("devicemotion", i), o && (o(), o = null);
|
|
290
304
|
};
|
|
291
305
|
}
|
|
292
|
-
function
|
|
293
|
-
const
|
|
294
|
-
return console.log(`๐ฏ [Aippy Sensors] watchMotion - Using ${
|
|
306
|
+
function Y(n, e = !0) {
|
|
307
|
+
const t = b();
|
|
308
|
+
return console.log(`๐ฏ [Aippy Sensors] watchMotion - Using ${t ? "NATIVE BRIDGE" : "WEB API"} mode`), t ? (console.log("๐ฑ [Aippy Sensors] Starting native bridge motion listener"), x(n)) : (console.log("๐ [Aippy Sensors] Starting Web API motion listener (may require permission)"), G(n, e));
|
|
295
309
|
}
|
|
296
|
-
function
|
|
297
|
-
if (!
|
|
310
|
+
function B(n) {
|
|
311
|
+
if (!I())
|
|
298
312
|
throw s("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
299
|
-
const
|
|
300
|
-
const
|
|
301
|
-
alpha:
|
|
302
|
-
beta:
|
|
303
|
-
gamma:
|
|
313
|
+
const e = (t) => {
|
|
314
|
+
const o = {
|
|
315
|
+
alpha: t.alpha ?? 0,
|
|
316
|
+
beta: t.beta ?? 0,
|
|
317
|
+
gamma: t.gamma ?? 0,
|
|
304
318
|
timestamp: Date.now()
|
|
305
319
|
};
|
|
306
|
-
|
|
320
|
+
n(o);
|
|
307
321
|
};
|
|
308
|
-
return window.addEventListener("deviceorientation",
|
|
309
|
-
window.removeEventListener("deviceorientation",
|
|
322
|
+
return window.addEventListener("deviceorientation", e), () => {
|
|
323
|
+
window.removeEventListener("deviceorientation", e);
|
|
310
324
|
};
|
|
311
325
|
}
|
|
312
|
-
class
|
|
326
|
+
class z {
|
|
313
327
|
/**
|
|
314
328
|
* Check if device orientation is supported
|
|
315
329
|
*/
|
|
316
330
|
isOrientationSupported() {
|
|
317
|
-
return
|
|
331
|
+
return I();
|
|
318
332
|
}
|
|
319
333
|
/**
|
|
320
334
|
* Check if device motion is supported
|
|
321
335
|
*/
|
|
322
336
|
isMotionSupported() {
|
|
323
|
-
return
|
|
337
|
+
return P();
|
|
324
338
|
}
|
|
325
339
|
/**
|
|
326
340
|
* Get device orientation data
|
|
@@ -328,17 +342,17 @@ class A {
|
|
|
328
342
|
async getOrientation() {
|
|
329
343
|
if (!this.isOrientationSupported())
|
|
330
344
|
throw s("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
331
|
-
return new Promise((
|
|
332
|
-
const
|
|
333
|
-
window.removeEventListener("deviceorientation",
|
|
334
|
-
x:
|
|
335
|
-
y:
|
|
336
|
-
z:
|
|
345
|
+
return new Promise((e, t) => {
|
|
346
|
+
const o = (i) => {
|
|
347
|
+
window.removeEventListener("deviceorientation", o), e({
|
|
348
|
+
x: i.alpha ?? 0,
|
|
349
|
+
y: i.beta ?? 0,
|
|
350
|
+
z: i.gamma ?? 0,
|
|
337
351
|
timestamp: Date.now()
|
|
338
352
|
});
|
|
339
353
|
};
|
|
340
|
-
window.addEventListener("deviceorientation",
|
|
341
|
-
window.removeEventListener("deviceorientation",
|
|
354
|
+
window.addEventListener("deviceorientation", o), setTimeout(() => {
|
|
355
|
+
window.removeEventListener("deviceorientation", o), t(s("Device orientation timeout", "UNKNOWN_ERROR"));
|
|
342
356
|
}, 5e3);
|
|
343
357
|
});
|
|
344
358
|
}
|
|
@@ -346,19 +360,19 @@ class A {
|
|
|
346
360
|
* Watch device orientation changes
|
|
347
361
|
* @deprecated Use watchOrientation() function instead
|
|
348
362
|
*/
|
|
349
|
-
watchOrientation(
|
|
363
|
+
watchOrientation(e) {
|
|
350
364
|
if (!this.isOrientationSupported())
|
|
351
365
|
throw s("Device orientation API is not supported", "NOT_SUPPORTED");
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
x:
|
|
355
|
-
y:
|
|
356
|
-
z:
|
|
366
|
+
const t = (o) => {
|
|
367
|
+
e({
|
|
368
|
+
x: o.alpha ?? 0,
|
|
369
|
+
y: o.beta ?? 0,
|
|
370
|
+
z: o.gamma ?? 0,
|
|
357
371
|
timestamp: Date.now()
|
|
358
372
|
});
|
|
359
373
|
};
|
|
360
|
-
return window.addEventListener("deviceorientation",
|
|
361
|
-
window.removeEventListener("deviceorientation",
|
|
374
|
+
return window.addEventListener("deviceorientation", t), () => {
|
|
375
|
+
window.removeEventListener("deviceorientation", t);
|
|
362
376
|
};
|
|
363
377
|
}
|
|
364
378
|
/**
|
|
@@ -367,17 +381,17 @@ class A {
|
|
|
367
381
|
async getMotion() {
|
|
368
382
|
if (!this.isMotionSupported())
|
|
369
383
|
throw s("Device motion API is not supported", "NOT_SUPPORTED");
|
|
370
|
-
return new Promise((
|
|
371
|
-
const
|
|
372
|
-
window.removeEventListener("devicemotion",
|
|
373
|
-
x:
|
|
374
|
-
y:
|
|
375
|
-
z:
|
|
384
|
+
return new Promise((e, t) => {
|
|
385
|
+
const o = (i) => {
|
|
386
|
+
window.removeEventListener("devicemotion", o), e({
|
|
387
|
+
x: i.acceleration?.x ?? 0,
|
|
388
|
+
y: i.acceleration?.y ?? 0,
|
|
389
|
+
z: i.acceleration?.z ?? 0,
|
|
376
390
|
timestamp: Date.now()
|
|
377
391
|
});
|
|
378
392
|
};
|
|
379
|
-
window.addEventListener("devicemotion",
|
|
380
|
-
window.removeEventListener("devicemotion",
|
|
393
|
+
window.addEventListener("devicemotion", o), setTimeout(() => {
|
|
394
|
+
window.removeEventListener("devicemotion", o), t(s("Device motion timeout", "UNKNOWN_ERROR"));
|
|
381
395
|
}, 5e3);
|
|
382
396
|
});
|
|
383
397
|
}
|
|
@@ -385,30 +399,30 @@ class A {
|
|
|
385
399
|
* Watch device motion changes
|
|
386
400
|
* @deprecated Use watchMotion() function instead
|
|
387
401
|
*/
|
|
388
|
-
watchMotion(
|
|
402
|
+
watchMotion(e) {
|
|
389
403
|
if (!this.isMotionSupported())
|
|
390
404
|
throw s("Device motion API is not supported", "NOT_SUPPORTED");
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
x:
|
|
394
|
-
y:
|
|
395
|
-
z:
|
|
405
|
+
const t = (o) => {
|
|
406
|
+
e({
|
|
407
|
+
x: o.acceleration?.x ?? 0,
|
|
408
|
+
y: o.acceleration?.y ?? 0,
|
|
409
|
+
z: o.acceleration?.z ?? 0,
|
|
396
410
|
timestamp: Date.now()
|
|
397
411
|
});
|
|
398
412
|
};
|
|
399
|
-
return window.addEventListener("devicemotion",
|
|
400
|
-
window.removeEventListener("devicemotion",
|
|
413
|
+
return window.addEventListener("devicemotion", t), () => {
|
|
414
|
+
window.removeEventListener("devicemotion", t);
|
|
401
415
|
};
|
|
402
416
|
}
|
|
403
417
|
/**
|
|
404
418
|
* Request permission for motion sensors (iOS 13+)
|
|
405
419
|
*/
|
|
406
420
|
async requestPermission() {
|
|
407
|
-
return
|
|
421
|
+
return U();
|
|
408
422
|
}
|
|
409
423
|
}
|
|
410
|
-
const
|
|
411
|
-
class
|
|
424
|
+
const K = new z();
|
|
425
|
+
class W {
|
|
412
426
|
/**
|
|
413
427
|
* Check if file system access is supported
|
|
414
428
|
*/
|
|
@@ -424,28 +438,28 @@ class R {
|
|
|
424
438
|
/**
|
|
425
439
|
* Open file picker (modern API)
|
|
426
440
|
*/
|
|
427
|
-
async openFilePicker(
|
|
441
|
+
async openFilePicker(e = {}) {
|
|
428
442
|
if (!this.isSupported())
|
|
429
443
|
throw s("File System Access API is not supported", "NOT_SUPPORTED");
|
|
430
444
|
try {
|
|
431
|
-
const
|
|
432
|
-
types:
|
|
445
|
+
const t = {
|
|
446
|
+
types: e.accept ? [{
|
|
433
447
|
description: "Files",
|
|
434
448
|
accept: Object.fromEntries(
|
|
435
|
-
|
|
449
|
+
e.accept.map((r) => [r, [r]])
|
|
436
450
|
)
|
|
437
451
|
}] : void 0,
|
|
438
|
-
multiple:
|
|
439
|
-
},
|
|
440
|
-
|
|
452
|
+
multiple: e.multiple ?? !1
|
|
453
|
+
}, o = await window.showOpenFilePicker(t), i = await Promise.all(
|
|
454
|
+
o.map(async (r) => r.getFile())
|
|
441
455
|
);
|
|
442
456
|
return {
|
|
443
|
-
files:
|
|
444
|
-
paths:
|
|
457
|
+
files: i,
|
|
458
|
+
paths: i.map((r) => r.name)
|
|
445
459
|
};
|
|
446
|
-
} catch (
|
|
447
|
-
throw
|
|
448
|
-
`Failed to open file picker: ${
|
|
460
|
+
} catch (t) {
|
|
461
|
+
throw t instanceof Error && t.name === "AbortError" ? s("File picker was cancelled", "PERMISSION_DENIED") : s(
|
|
462
|
+
`Failed to open file picker: ${t instanceof Error ? t.message : "Unknown error"}`,
|
|
449
463
|
"PERMISSION_DENIED"
|
|
450
464
|
);
|
|
451
465
|
}
|
|
@@ -453,38 +467,38 @@ class R {
|
|
|
453
467
|
/**
|
|
454
468
|
* Open file picker (legacy fallback)
|
|
455
469
|
*/
|
|
456
|
-
async openFilePickerLegacy(
|
|
470
|
+
async openFilePickerLegacy(e = {}) {
|
|
457
471
|
if (!this.isLegacySupported())
|
|
458
472
|
throw s("File input is not supported", "NOT_SUPPORTED");
|
|
459
|
-
return new Promise((
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
files:
|
|
465
|
-
paths:
|
|
473
|
+
return new Promise((t, o) => {
|
|
474
|
+
const i = document.createElement("input");
|
|
475
|
+
i.type = "file", i.multiple = e.multiple ?? !1, i.accept = e.accept?.join(",") ?? "", i.onchange = (r) => {
|
|
476
|
+
const c = r.target, a = Array.from(c.files || []);
|
|
477
|
+
t({
|
|
478
|
+
files: a,
|
|
479
|
+
paths: a.map((d) => d.name)
|
|
466
480
|
});
|
|
467
|
-
},
|
|
468
|
-
|
|
469
|
-
},
|
|
481
|
+
}, i.oncancel = () => {
|
|
482
|
+
o(s("File picker was cancelled", "PERMISSION_DENIED"));
|
|
483
|
+
}, i.click();
|
|
470
484
|
});
|
|
471
485
|
}
|
|
472
486
|
/**
|
|
473
487
|
* Open file picker with fallback
|
|
474
488
|
*/
|
|
475
|
-
async openFile(
|
|
476
|
-
return this.isSupported() ? await this.openFilePicker(
|
|
489
|
+
async openFile(e = {}) {
|
|
490
|
+
return this.isSupported() ? await this.openFilePicker(e) : await this.openFilePickerLegacy(e);
|
|
477
491
|
}
|
|
478
492
|
/**
|
|
479
493
|
* Save file
|
|
480
494
|
*/
|
|
481
|
-
async saveFile(
|
|
495
|
+
async saveFile(e, t) {
|
|
482
496
|
try {
|
|
483
|
-
const
|
|
484
|
-
|
|
485
|
-
} catch (
|
|
497
|
+
const o = URL.createObjectURL(e), i = document.createElement("a");
|
|
498
|
+
i.href = o, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i), URL.revokeObjectURL(o);
|
|
499
|
+
} catch (o) {
|
|
486
500
|
throw s(
|
|
487
|
-
`Failed to save file: ${
|
|
501
|
+
`Failed to save file: ${o instanceof Error ? o.message : "Unknown error"}`,
|
|
488
502
|
"UNKNOWN_ERROR"
|
|
489
503
|
);
|
|
490
504
|
}
|
|
@@ -492,51 +506,51 @@ class R {
|
|
|
492
506
|
/**
|
|
493
507
|
* Read file as text
|
|
494
508
|
*/
|
|
495
|
-
async readAsText(
|
|
496
|
-
return new Promise((
|
|
497
|
-
const
|
|
498
|
-
|
|
509
|
+
async readAsText(e) {
|
|
510
|
+
return new Promise((t, o) => {
|
|
511
|
+
const i = new FileReader();
|
|
512
|
+
i.onload = () => t(i.result), i.onerror = () => o(s("Failed to read file", "UNKNOWN_ERROR")), i.readAsText(e);
|
|
499
513
|
});
|
|
500
514
|
}
|
|
501
515
|
/**
|
|
502
516
|
* Read file as data URL
|
|
503
517
|
*/
|
|
504
|
-
async readAsDataURL(
|
|
505
|
-
return new Promise((
|
|
506
|
-
const
|
|
507
|
-
|
|
518
|
+
async readAsDataURL(e) {
|
|
519
|
+
return new Promise((t, o) => {
|
|
520
|
+
const i = new FileReader();
|
|
521
|
+
i.onload = () => t(i.result), i.onerror = () => o(s("Failed to read file", "UNKNOWN_ERROR")), i.readAsDataURL(e);
|
|
508
522
|
});
|
|
509
523
|
}
|
|
510
524
|
}
|
|
511
|
-
const
|
|
512
|
-
function
|
|
513
|
-
return new Promise((
|
|
525
|
+
const $ = new W();
|
|
526
|
+
function j(n) {
|
|
527
|
+
return new Promise((e) => {
|
|
514
528
|
if ("vibrate" in navigator)
|
|
515
|
-
navigator.vibrate(
|
|
529
|
+
navigator.vibrate(n), e();
|
|
516
530
|
else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.aippyListener) {
|
|
517
|
-
const
|
|
531
|
+
const t = {
|
|
518
532
|
command: "navigator.vibrate",
|
|
519
|
-
parameters:
|
|
533
|
+
parameters: n
|
|
520
534
|
};
|
|
521
|
-
window.webkit.messageHandlers.aippyListener.postMessage(
|
|
535
|
+
window.webkit.messageHandlers.aippyListener.postMessage(t), e();
|
|
522
536
|
} else
|
|
523
|
-
console.warn("Vibration not supported in this environment"),
|
|
537
|
+
console.warn("Vibration not supported in this environment"), e();
|
|
524
538
|
});
|
|
525
539
|
}
|
|
526
540
|
export {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
541
|
+
_ as CameraAPI,
|
|
542
|
+
W as FileSystemAPI,
|
|
543
|
+
F as GeolocationAPI,
|
|
544
|
+
z as SensorsAPI,
|
|
545
|
+
C as camera,
|
|
546
|
+
$ as fileSystem,
|
|
547
|
+
X as geolocation,
|
|
548
|
+
b as hasNativeBridge,
|
|
549
|
+
P as isMotionSupported,
|
|
550
|
+
I as isOrientationSupported,
|
|
551
|
+
U as requestMotionPermission,
|
|
552
|
+
K as sensors,
|
|
553
|
+
j as vibrate,
|
|
554
|
+
Y as watchMotion,
|
|
555
|
+
B as watchOrientation
|
|
542
556
|
};
|
package/dist/index/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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-
|
|
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
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
4
|
import { c as T, a as V, P as _, b as k, p as G, d as H } from "../pwa-8DGmPqLV.js";
|
|
5
5
|
import { a as q, b as B } from "../useTweaks-QxMRmg7i.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
var u = Object.defineProperty;
|
|
2
|
-
var m = (o, e,
|
|
3
|
-
var
|
|
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
4
|
class d extends Error {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.name = "AippyRuntimeError", this.code = i, this.context =
|
|
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
10
|
}
|
|
11
11
|
}
|
|
12
12
|
const R = {
|
|
@@ -16,12 +16,12 @@ const R = {
|
|
|
16
16
|
NETWORK_ERROR: "NETWORK_ERROR",
|
|
17
17
|
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
18
18
|
};
|
|
19
|
-
function
|
|
20
|
-
return new d(o, R[e],
|
|
19
|
+
function g(o, e = "UNKNOWN_ERROR", n) {
|
|
20
|
+
return new d(o, R[e], n);
|
|
21
21
|
}
|
|
22
22
|
class a {
|
|
23
23
|
constructor(e) {
|
|
24
|
-
|
|
24
|
+
r(this, "cancelled", !1);
|
|
25
25
|
this.cancelFn = e;
|
|
26
26
|
}
|
|
27
27
|
cancel() {
|
|
@@ -31,28 +31,28 @@ class a {
|
|
|
31
31
|
return this.cancelled;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
class
|
|
34
|
+
class f {
|
|
35
35
|
constructor() {
|
|
36
|
-
|
|
36
|
+
r(this, "listeners", /* @__PURE__ */ new Map());
|
|
37
37
|
}
|
|
38
|
-
addEventListener(e,
|
|
39
|
-
this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(
|
|
38
|
+
addEventListener(e, n) {
|
|
39
|
+
this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(n);
|
|
40
40
|
}
|
|
41
|
-
removeEventListener(e,
|
|
41
|
+
removeEventListener(e, n) {
|
|
42
42
|
const i = this.listeners.get(e);
|
|
43
43
|
if (i) {
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const t = i.indexOf(n);
|
|
45
|
+
t > -1 && i.splice(t, 1);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
emit(e,
|
|
48
|
+
emit(e, n) {
|
|
49
49
|
const i = this.listeners.get(e);
|
|
50
|
-
i && i.forEach((
|
|
50
|
+
i && i.forEach((t) => t(n));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
class
|
|
53
|
+
class y {
|
|
54
54
|
constructor() {
|
|
55
|
-
|
|
55
|
+
r(this, "emitter", new f());
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Emit a message to subscribers
|
|
@@ -63,9 +63,9 @@ class f {
|
|
|
63
63
|
/**
|
|
64
64
|
* Subscribe to messages on a specific endpoint
|
|
65
65
|
*/
|
|
66
|
-
subscribe(e,
|
|
67
|
-
const i = (
|
|
68
|
-
t
|
|
66
|
+
subscribe(e, n) {
|
|
67
|
+
const i = (t) => {
|
|
68
|
+
n(t);
|
|
69
69
|
};
|
|
70
70
|
return this.emitter.addEventListener(e, i), new a(() => {
|
|
71
71
|
this.emitter.removeEventListener(e, i);
|
|
@@ -74,18 +74,19 @@ class f {
|
|
|
74
74
|
/**
|
|
75
75
|
* Subscribe to a single message (auto-unsubscribe after first message)
|
|
76
76
|
*/
|
|
77
|
-
once(e,
|
|
78
|
-
const i = this.subscribe(e, (
|
|
79
|
-
i.cancel(), t
|
|
77
|
+
once(e, n) {
|
|
78
|
+
const i = this.subscribe(e, (t) => {
|
|
79
|
+
i.cancel(), n(t);
|
|
80
80
|
});
|
|
81
81
|
return i;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
class h {
|
|
85
85
|
constructor() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
r(this, "receiveChannel", new y());
|
|
87
|
+
r(this, "seq", 0);
|
|
88
|
+
r(this, "motionListeners", []);
|
|
89
|
+
r(this, "noListenersWarned", !1);
|
|
89
90
|
}
|
|
90
91
|
/**
|
|
91
92
|
* Unified native data receiver - Routes to specific handlers based on message type
|
|
@@ -115,10 +116,10 @@ class h {
|
|
|
115
116
|
isTweaksMessage(e) {
|
|
116
117
|
if (typeof e != "object" || e === null || "endpoint" in e || "payload" in e)
|
|
117
118
|
return !1;
|
|
118
|
-
const
|
|
119
|
-
return
|
|
120
|
-
const
|
|
121
|
-
return typeof
|
|
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;
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
125
|
/**
|
|
@@ -128,37 +129,37 @@ class h {
|
|
|
128
129
|
* @param callback - Callback to handle received data
|
|
129
130
|
* @returns Cancellable subscription
|
|
130
131
|
*/
|
|
131
|
-
createSubscription(e,
|
|
132
|
-
const
|
|
133
|
-
command:
|
|
132
|
+
createSubscription(e, n, i) {
|
|
133
|
+
const t = (this.seq++).toString(), c = {
|
|
134
|
+
command: n.command,
|
|
134
135
|
parameters: {
|
|
135
|
-
type:
|
|
136
|
+
type: n.type,
|
|
136
137
|
action: "subscribe",
|
|
137
|
-
endpoint:
|
|
138
|
+
endpoint: t
|
|
138
139
|
}
|
|
139
140
|
};
|
|
140
|
-
console.log("๐จ [Aippy Runtime] Creating subscription with message:", JSON.stringify(
|
|
141
|
-
const
|
|
142
|
-
if (console.log(`๐ฌ [Aippy Runtime] Received data on endpoint ${
|
|
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) {
|
|
143
144
|
console.warn("โ ๏ธ [Aippy Runtime] Received error, skipping:", s.error);
|
|
144
145
|
return;
|
|
145
146
|
}
|
|
146
147
|
i(s);
|
|
147
148
|
});
|
|
148
149
|
try {
|
|
149
|
-
console.log("๐ค [Aippy Runtime] Sending postMessage to native iOS:",
|
|
150
|
+
console.log("๐ค [Aippy Runtime] Sending postMessage to native iOS:", c), e.postMessage(c), console.log("โ
[Aippy Runtime] postMessage sent successfully");
|
|
150
151
|
} catch (s) {
|
|
151
152
|
console.error("โ [Aippy Runtime] Failed to send postMessage:", s);
|
|
152
153
|
}
|
|
153
154
|
return new a(() => {
|
|
154
|
-
console.log(`๐ [Aippy Runtime] Unsubscribing from endpoint ${
|
|
155
|
+
console.log(`๐ [Aippy Runtime] Unsubscribing from endpoint ${t}`), l.cancel();
|
|
155
156
|
try {
|
|
156
157
|
const s = {
|
|
157
|
-
command:
|
|
158
|
+
command: n.command,
|
|
158
159
|
parameters: {
|
|
159
|
-
type:
|
|
160
|
+
type: n.type,
|
|
160
161
|
action: "unsubscribe",
|
|
161
|
-
endpoint:
|
|
162
|
+
endpoint: t
|
|
162
163
|
}
|
|
163
164
|
};
|
|
164
165
|
e.postMessage(s), console.log("โ
[Aippy Runtime] Unsubscribe message sent:", s);
|
|
@@ -174,27 +175,27 @@ class h {
|
|
|
174
175
|
*/
|
|
175
176
|
addMotionListener(e) {
|
|
176
177
|
console.log("๐ฌ [Aippy Runtime] addMotionListener called"), this.motionListeners.push(e), console.log(`๐ [Aippy Runtime] Total motion listeners: ${this.motionListeners.length}`);
|
|
177
|
-
const
|
|
178
|
-
if (!
|
|
178
|
+
const n = window.webkit?.messageHandlers?.aippyListener;
|
|
179
|
+
if (!n)
|
|
179
180
|
return console.warn("โ ๏ธ [Aippy Runtime] No webkit message handler found, using fallback mode"), () => {
|
|
180
|
-
const
|
|
181
|
-
|
|
181
|
+
const t = this.motionListeners.indexOf(e);
|
|
182
|
+
t > -1 && this.motionListeners.splice(t, 1);
|
|
182
183
|
};
|
|
183
184
|
console.log("โ
[Aippy Runtime] Webkit handler found, creating subscription");
|
|
184
185
|
const i = this.createSubscription(
|
|
185
|
-
|
|
186
|
+
n,
|
|
186
187
|
{
|
|
187
188
|
command: "navigator.motion",
|
|
188
189
|
type: "motion"
|
|
189
190
|
},
|
|
190
|
-
(
|
|
191
|
-
console.log("๐ฅ [Aippy Runtime] Received motion data from native:",
|
|
191
|
+
(t) => {
|
|
192
|
+
console.log("๐ฅ [Aippy Runtime] Received motion data from native:", t), t.motion && e(t.motion);
|
|
192
193
|
}
|
|
193
194
|
);
|
|
194
195
|
return () => {
|
|
195
196
|
console.log("๐งน [Aippy Runtime] Cleaning up motion listener"), i.cancel();
|
|
196
|
-
const
|
|
197
|
-
|
|
197
|
+
const t = this.motionListeners.indexOf(e);
|
|
198
|
+
t > -1 && this.motionListeners.splice(t, 1);
|
|
198
199
|
};
|
|
199
200
|
}
|
|
200
201
|
/**
|
|
@@ -203,22 +204,22 @@ class h {
|
|
|
203
204
|
* @param data - Motion data from iOS
|
|
204
205
|
*/
|
|
205
206
|
broadcastMotionData(e) {
|
|
206
|
-
if (
|
|
207
|
-
console.warn("โ ๏ธ [Aippy Runtime] No motion listeners to broadcast to");
|
|
207
|
+
if (this.motionListeners.length === 0) {
|
|
208
|
+
this.noListenersWarned || (console.warn("โ ๏ธ [Aippy Runtime] No motion listeners to broadcast to"), this.noListenersWarned = !0);
|
|
208
209
|
return;
|
|
209
210
|
}
|
|
210
|
-
const
|
|
211
|
-
|
|
211
|
+
const n = e.motion || e;
|
|
212
|
+
this.motionListeners.forEach((i) => {
|
|
212
213
|
try {
|
|
213
|
-
|
|
214
|
-
} catch (
|
|
215
|
-
console.error(
|
|
214
|
+
i(n);
|
|
215
|
+
} catch (t) {
|
|
216
|
+
console.error("โ ๏ธ [Aippy Runtime] Error in motion listener:", t);
|
|
216
217
|
}
|
|
217
218
|
});
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
|
-
function
|
|
221
|
-
if (
|
|
221
|
+
function w(o) {
|
|
222
|
+
if (!o || typeof o != "object") {
|
|
222
223
|
console.warn("โ ๏ธ [Aippy Runtime] Invalid motion data type:", typeof o);
|
|
223
224
|
return;
|
|
224
225
|
}
|
|
@@ -226,17 +227,17 @@ function g(o) {
|
|
|
226
227
|
console.warn("โ ๏ธ [Aippy Runtime] Motion data missing valid motion field");
|
|
227
228
|
return;
|
|
228
229
|
}
|
|
229
|
-
|
|
230
|
+
p.broadcastMotionData(o);
|
|
230
231
|
}
|
|
231
|
-
const
|
|
232
|
-
typeof window < "u" && (window.aippyRuntime =
|
|
232
|
+
const p = new h();
|
|
233
|
+
typeof window < "u" && (window.aippyRuntime = p, window.processMotionData = w);
|
|
233
234
|
export {
|
|
234
235
|
d as A,
|
|
235
236
|
a as C,
|
|
236
237
|
R as E,
|
|
237
|
-
|
|
238
|
+
y as R,
|
|
238
239
|
h as a,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
p as b,
|
|
241
|
+
g as c,
|
|
242
|
+
w as p
|
|
242
243
|
};
|