diff --git a/shared/js/ConnectionHandler.ts b/shared/js/ConnectionHandler.ts index 03ee5922..b3c656c0 100644 --- a/shared/js/ConnectionHandler.ts +++ b/shared/js/ConnectionHandler.ts @@ -660,8 +660,10 @@ class ConnectionHandler { acquire_recorder(voice_recoder: RecorderProfile, update_control_bar: boolean) { const vconnection = this.serverConnection.voice_connection(); - if(vconnection) - vconnection.acquire_voice_recorder(voice_recoder); - this.update_voice_status(undefined); + (vconnection ? vconnection.acquire_voice_recorder(voice_recoder) : Promise.resolve()).catch(error => { + console.error(tr("Failed to acquire recorder (%o)"), error); + }).then(() => { + this.update_voice_status(undefined); + }); } } \ No newline at end of file diff --git a/shared/js/connection/ConnectionBase.ts b/shared/js/connection/ConnectionBase.ts index cd1076fc..ecdda9f8 100644 --- a/shared/js/connection/ConnectionBase.ts +++ b/shared/js/connection/ConnectionBase.ts @@ -82,7 +82,7 @@ namespace connection { abstract unregister_client(client: VoiceClient) : Promise; abstract voice_recorder() : RecorderProfile; - abstract acquire_voice_recorder(recorder: RecorderProfile | undefined); + abstract acquire_voice_recorder(recorder: RecorderProfile | undefined) : Promise; } } diff --git a/shared/js/load.ts b/shared/js/load.ts index a82e0791..4777e26a 100644 --- a/shared/js/load.ts +++ b/shared/js/load.ts @@ -591,12 +591,7 @@ const loader_javascript = { "js/permission/GroupManager.js", //Load audio - "js/voice/VoiceHandler.js", - "js/voice/AudioResampler.js", - "js/voice/VoiceClient.js", - "js/voice/RecorderBase.js", - "js/voice/JavascriptRecorder.js", "js/voice/RecorderProfile.js", //Load codec @@ -633,7 +628,12 @@ const loader_javascript = { await loader.load_scripts([ ["js/audio/AudioPlayer.js"], ["js/audio/WebCodec.js"], - ["js/WebPPTListener.js"] + ["js/WebPPTListener.js"], + + "js/voice/AudioResampler.js", + "js/voice/JavascriptRecorder.js", + "js/voice/VoiceHandler.js", + "js/voice/VoiceClient.js", ]); }, load_scripts_debug_client: async () => { diff --git a/shared/js/main.ts b/shared/js/main.ts index eb33fd6b..fb42afe6 100644 --- a/shared/js/main.ts +++ b/shared/js/main.ts @@ -424,9 +424,9 @@ loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, { } }, priority: 100 -}) +}); -loader.register_task(loader.Stage.LOADED, { +loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, { name: "app starter", function: async () => { try { @@ -443,6 +443,6 @@ loader.register_task(loader.Stage.LOADED, { displayCriticalError("Failed to boot app function:
" + ex); } }, - priority: 10 + priority: 100 }); diff --git a/shared/js/voice/AudioResampler.ts b/web/js/voice/AudioResampler.ts similarity index 100% rename from shared/js/voice/AudioResampler.ts rename to web/js/voice/AudioResampler.ts diff --git a/shared/js/voice/JavascriptRecorder.ts b/web/js/voice/JavascriptRecorder.ts similarity index 99% rename from shared/js/voice/JavascriptRecorder.ts rename to web/js/voice/JavascriptRecorder.ts index 836b70b7..cc334318 100644 --- a/shared/js/voice/JavascriptRecorder.ts +++ b/web/js/voice/JavascriptRecorder.ts @@ -292,13 +292,11 @@ namespace audio { async start() { this._state = InputState.INITIALIZING; - if(!this._current_device) { + if(!this._current_device) return; - } - if(!this._audio_context) { + if(!this._audio_context) return; - } try { const media_function = getUserMediaFunction(); @@ -326,7 +324,6 @@ namespace audio { this._initialize_filters(); this._state = InputState.RECORDING; } catch(error) { - console.warn(tr("Failed to start recorder (%o)"), error); this._state = InputState.PAUSED; throw error; } diff --git a/shared/js/voice/VoiceClient.ts b/web/js/voice/VoiceClient.ts similarity index 100% rename from shared/js/voice/VoiceClient.ts rename to web/js/voice/VoiceClient.ts diff --git a/shared/js/voice/VoiceHandler.ts b/web/js/voice/VoiceHandler.ts similarity index 98% rename from shared/js/voice/VoiceHandler.ts rename to web/js/voice/VoiceHandler.ts index 1f665b1e..6ae53938 100644 --- a/shared/js/voice/VoiceHandler.ts +++ b/web/js/voice/VoiceHandler.ts @@ -190,14 +190,15 @@ namespace audio { if(!this.javascript_encoding_supported()) return; } - acquire_voice_recorder(recorder: RecorderProfile | undefined, enforce?: boolean) { + async acquire_voice_recorder(recorder: RecorderProfile | undefined, enforce?: boolean) { if(this._audio_source === recorder && !enforce) return; if(recorder) - recorder.unmount(); /* FIXME: Await promise? */ + await recorder.unmount(); + if(this._audio_source) - this._audio_source.unmount(); + await this._audio_source.unmount(); this.handleVoiceEnded(); this._audio_source = recorder; @@ -217,7 +218,7 @@ namespace audio { if(!this.local_audio_stream) this.setup_native(); /* requires initialized audio */ - recorder.input.set_consumer({ + await recorder.input.set_consumer({ type: audio.recorder.InputConsumerType.NODE, callback_node: node => { if(!this.local_audio_stream) @@ -233,7 +234,7 @@ namespace audio { } } as audio.recorder.NodeInputConsumer); } else { - recorder.input.set_consumer({ + await recorder.input.set_consumer({ type: audio.recorder.InputConsumerType.CALLBACK, callback_audio: buffer => this.handleVoiceData(buffer, false) } as audio.recorder.CallbackInputConsumer); @@ -538,7 +539,7 @@ namespace audio { private on_recoder_yield() { console.log("Lost recorder!"); this._audio_source = undefined; - this.acquire_voice_recorder(undefined, true); + this.acquire_voice_recorder(undefined, true); /* we can ignore the promise because we should finish this directly */ } connected(): boolean {