From 012f9164fd513415fd0f861616bc09d87b8c4aa7 Mon Sep 17 00:00:00 2001 From: Dannii Willis Date: Wed, 18 Dec 2024 10:59:59 +1000 Subject: [PATCH] WebGlkOte: Move the creation of the AudioContext to inside init() in case it helps with Safari --- src/glkote/web/web.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/glkote/web/web.ts b/src/glkote/web/web.ts index 4801e45..518e83f 100644 --- a/src/glkote/web/web.ts +++ b/src/glkote/web/web.ts @@ -57,9 +57,6 @@ export default class WebGlkOte extends GlkOte.GlkOteBase implements GlkOte.GlkOt super() this.metrics_calculator = new Metrics(this) - if (typeof AudioContext !== 'undefined') { - this.schannels = new SoundChannelManager(this) - } this.windows = new Windows(this) } @@ -139,6 +136,11 @@ export default class WebGlkOte extends GlkOte.GlkOteBase implements GlkOte.GlkOt } } + // Set up sound channels now to try to avoid the autoplaying-without-user input problem + if (typeof AudioContext !== 'undefined') { + this.schannels = new SoundChannelManager(this) + } + // Note that this must be called last as it will result in VM.start() being called return super.init(options) } @@ -187,7 +189,7 @@ export default class WebGlkOte extends GlkOte.GlkOteBase implements GlkOte.GlkOt 'hyperlinks', 'timer', ] - if (this.schannels) { + if (typeof AudioContext !== 'undefined') { capabilities.push('sounds') } return capabilities