@aippy/runtime 0.2.0-dev.2 → 0.2.0-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/audio/index.js
CHANGED
package/dist/core/index.js
CHANGED
package/dist/index/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { A, E, c } from "../errors-DAz5_jDJ.js";
|
|
|
3
3
|
import { CameraAPI, FileSystemAPI, GeolocationAPI, SensorsAPI, camera, fileSystem, geolocation, sensors, vibrate } from "../device/index.js";
|
|
4
4
|
import { c as c2, a, P, b, p, d } from "../pwa-BkviTQoN.js";
|
|
5
5
|
import { a as a2, b as b2 } from "../useTweaks-mK5PAWOs.js";
|
|
6
|
-
import { c as c3, a as a3, i, b as b3, p as p2, u } from "../useAudioContext-
|
|
6
|
+
import { c as c3, a as a3, i, b as b3, p as p2, u } from "../useAudioContext-DLWWSFAX.js";
|
|
7
7
|
export {
|
|
8
8
|
A as AippyRuntimeError,
|
|
9
9
|
CameraAPI,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef, useEffect } from "react";
|
|
1
|
+
import { useState, useRef, useEffect } from "react";
|
|
2
2
|
function isIOSDevice() {
|
|
3
3
|
const userAgent = navigator.userAgent;
|
|
4
4
|
if (/iPad|iPhone|iPod/.test(userAgent)) {
|
|
@@ -214,6 +214,9 @@ function patchAudioContext(audioContext, options = {}) {
|
|
|
214
214
|
}
|
|
215
215
|
const originalDestination = audioContext.destination;
|
|
216
216
|
const streamDestination = audioContext.createMediaStreamDestination();
|
|
217
|
+
const gainNode = audioContext.createGain();
|
|
218
|
+
gainNode.gain.value = 1;
|
|
219
|
+
gainNode.connect(streamDestination);
|
|
217
220
|
const mediaElement = createHiddenMediaElement(mediaElementType, debug);
|
|
218
221
|
mediaElement.srcObject = streamDestination.stream;
|
|
219
222
|
document.body.appendChild(mediaElement);
|
|
@@ -225,15 +228,15 @@ function patchAudioContext(audioContext, options = {}) {
|
|
|
225
228
|
autoPauseOptions,
|
|
226
229
|
debug
|
|
227
230
|
);
|
|
228
|
-
silenceDetector.connect(
|
|
231
|
+
silenceDetector.connect(gainNode);
|
|
229
232
|
}
|
|
230
233
|
Object.defineProperty(audioContext, "destination", {
|
|
231
|
-
get: () =>
|
|
234
|
+
get: () => gainNode,
|
|
232
235
|
enumerable: true,
|
|
233
236
|
configurable: true
|
|
234
237
|
});
|
|
235
|
-
if (!("maxChannelCount" in
|
|
236
|
-
Object.defineProperty(
|
|
238
|
+
if (!("maxChannelCount" in gainNode)) {
|
|
239
|
+
Object.defineProperty(gainNode, "maxChannelCount", {
|
|
237
240
|
get: () => originalDestination.maxChannelCount,
|
|
238
241
|
enumerable: true
|
|
239
242
|
});
|
|
@@ -292,31 +295,32 @@ function patchAudioContext(audioContext, options = {}) {
|
|
|
292
295
|
}
|
|
293
296
|
function useAudioContext(options = {}) {
|
|
294
297
|
const { autoUnlock = true, ...patchOptions } = options;
|
|
295
|
-
const
|
|
296
|
-
const
|
|
298
|
+
const [audioContext, setAudioContext] = useState(null);
|
|
299
|
+
const [isUnlocked, setIsUnlocked] = useState(false);
|
|
297
300
|
const unlockFnRef = useRef(null);
|
|
298
301
|
useEffect(() => {
|
|
299
302
|
const ctx = new AudioContext();
|
|
300
|
-
|
|
303
|
+
const patchedCtx = patchAudioContext(ctx, patchOptions);
|
|
304
|
+
setAudioContext(patchedCtx);
|
|
301
305
|
return () => {
|
|
302
|
-
|
|
303
|
-
|
|
306
|
+
patchedCtx.cleanup();
|
|
307
|
+
patchedCtx.close();
|
|
304
308
|
};
|
|
305
309
|
}, []);
|
|
306
|
-
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
if (!audioContext) return;
|
|
307
312
|
unlockFnRef.current = async () => {
|
|
308
|
-
|
|
309
|
-
if (!ctx || isUnlockedRef.current) return;
|
|
313
|
+
if (isUnlocked) return;
|
|
310
314
|
try {
|
|
311
|
-
await
|
|
312
|
-
|
|
315
|
+
await audioContext.unlock();
|
|
316
|
+
setIsUnlocked(true);
|
|
313
317
|
} catch (error) {
|
|
314
318
|
console.warn("Failed to unlock audio:", error);
|
|
315
319
|
}
|
|
316
320
|
};
|
|
317
|
-
}
|
|
321
|
+
}, [audioContext, isUnlocked]);
|
|
318
322
|
useEffect(() => {
|
|
319
|
-
if (!autoUnlock) return;
|
|
323
|
+
if (!autoUnlock || !audioContext) return;
|
|
320
324
|
const handleInteraction = async () => {
|
|
321
325
|
await unlockFnRef.current?.();
|
|
322
326
|
};
|
|
@@ -326,11 +330,12 @@ function useAudioContext(options = {}) {
|
|
|
326
330
|
document.removeEventListener("click", handleInteraction);
|
|
327
331
|
document.removeEventListener("touchstart", handleInteraction);
|
|
328
332
|
};
|
|
329
|
-
}, [autoUnlock]);
|
|
333
|
+
}, [autoUnlock, audioContext]);
|
|
330
334
|
return {
|
|
331
|
-
audioContext
|
|
332
|
-
isUnlocked
|
|
333
|
-
unlock: unlockFnRef.current
|
|
335
|
+
audioContext,
|
|
336
|
+
isUnlocked,
|
|
337
|
+
unlock: unlockFnRef.current || (async () => {
|
|
338
|
+
})
|
|
334
339
|
};
|
|
335
340
|
}
|
|
336
341
|
export {
|