@antha/audio 0.1.3 → 0.3.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.
@@ -1,13 +1,23 @@
1
- import { DeferredPromise } from '@augment-vir/common';
1
+ import { DeferredPromise, wait } from '@augment-vir/common';
2
2
  /**
3
3
  * Detects if the browser session currently supports playing audio.
4
4
  *
5
5
  * @category Internal
6
6
  */
7
7
  export async function isPlayingEnabled(audioContext = new AudioContext()) {
8
- /** Firefox requires an explicit resume after user gesture; other browsers auto-resume. */
8
+ /**
9
+ * Firefox requires an explicit resume after user gesture; other browsers auto-resume. The
10
+ * resume must finish before starting a source: `'ended'` never fires on a suspended context.
11
+ * Firefox also leaves this promise pending (rather than rejecting) while audio is still
12
+ * blocked, so it's raced against a timeout instead of awaited outright.
13
+ */
9
14
  if (audioContext instanceof AudioContext && audioContext.state === 'suspended') {
10
- audioContext.resume().catch(() => { });
15
+ await Promise.race([
16
+ audioContext.resume().catch(() => { }),
17
+ wait({
18
+ milliseconds: 100,
19
+ }),
20
+ ]);
11
21
  }
12
22
  const source = audioContext.createBufferSource();
13
23
  source.buffer = audioContext.createBuffer(1, 1, 22_050);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antha/audio",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "An Antha mod for handling audio.",
5
5
  "keywords": [
6
6
  "vir",
@@ -37,7 +37,7 @@
37
37
  "@augment-vir/common": "^32.2.3"
38
38
  },
39
39
  "devDependencies": {
40
- "@antha/engine": "^0.1.3",
40
+ "@antha/engine": "^0.3.0",
41
41
  "@augment-vir/test": "^32.2.3",
42
42
  "@web/dev-server-esbuild": "^2.0.0",
43
43
  "@web/test-runner": "^1.0.0",
@@ -46,7 +46,7 @@
46
46
  "typed-event-target": "^4.3.3"
47
47
  },
48
48
  "peerDependencies": {
49
- "@antha/engine": "^0.1.3",
49
+ "@antha/engine": "^0.3.0",
50
50
  "element-vir": ">=26",
51
51
  "typed-event-target": ">=4.3"
52
52
  },