diff --git a/shared/js/voice/VoiceHandler.ts b/shared/js/voice/VoiceHandler.ts index 6154a25b..52023bae 100644 --- a/shared/js/voice/VoiceHandler.ts +++ b/shared/js/voice/VoiceHandler.ts @@ -21,19 +21,23 @@ class CodecPool { private _supported: boolean = true; initialize(cached: number) { - for(let i = 0; i < cached; i++) - this.ownCodec(i + 1).then(codec => { - console.log(tr("Release again! (%o)"), codec); - this.releaseCodec(i + 1); - }).catch(error => { + /* test if we're able to use this codec */ + const dummy_client_id = 0xFFEF; + + this.ownCodec(dummy_client_id).then(codec => { + console.log(tr("Release again! (%o)"), codec); + this.releaseCodec(dummy_client_id); + }).catch(error => { + if(this._supported) { console.warn(tr("Disabling codec support for "), this.name); - if(this._supported) { - createErrorModal(tr("Could not load codec driver"), tr("Could not load or initialize codec ") + this.name + "
" + - "Error: " + JSON.stringify(error) + "").open(); - } - this._supported = false; - console.error(error); - }); + createErrorModal(tr("Could not load codec driver"), tr("Could not load or initialize codec ") + this.name + "
" + + "Error: " + JSON.stringify(error) + "").open(); + console.error(tr("Failed to initialize the opus codec. Error: %o"), error); + } else { + console.debug(tr("Failed to initialize already disabled codec. Error: %o"), error); + } + this._supported = false; + }); } supported() { return this._supported; } @@ -56,7 +60,7 @@ class CodecPool { this.ownCodec(clientId, false).then(resolve).catch(reject); }).catch(error => { console.error(tr("Could not initialize codec!\nError: %o"), error); - reject(tr("Could not initialize codec!")); + reject(typeof(error) === 'string' ? error : tr("Could not initialize codec!")); }); } return; diff --git a/shared/js/workers/codec/OpusCodec.ts b/shared/js/workers/codec/OpusCodec.ts index 9ca65348..3b008c73 100644 --- a/shared/js/workers/codec/OpusCodec.ts +++ b/shared/js/workers/codec/OpusCodec.ts @@ -1,6 +1,11 @@ /// -this["Module"] = typeof this["Module"] !== "undefined" ? this["Module"] : {}; +const WASM_ERROR_MESSAGES = [ + 'no native wasm support detected' +]; + +this["Module"] = this["Module"] || {}; + let initialized = false; Module['onRuntimeInitialized'] = function() { initialized = true; @@ -12,11 +17,43 @@ Module['onRuntimeInitialized'] = function() { success: true }) }; -Module['onAbort'] = message => { + +let abort_message: string = undefined; +let last_error_message: string; + +Module['print'] = function() { + if(arguments.length == 1 && arguments[0] == abort_message) + return; /* we don't need to reprint the abort message! */ + console.log(...arguments); +}; + +Module['printErr'] = function() { + if(arguments.length == 1 && arguments[0] == abort_message) + return; /* we don't need to reprint the abort message! */ + + last_error_message = arguments[0]; + for(const suppress of WASM_ERROR_MESSAGES) + if((arguments[0] as string).indexOf(suppress) != -1) + return; + + console.error(...arguments); +}; + +Module['onAbort'] = (message: string | DOMException) => { + /* no native wasm support detected */ Module['onAbort'] = undefined; if(message instanceof DOMException) message = "DOMException (" + message.name + "): " + message.code + " => " + message.message; + else { + abort_message = message; + if(message.indexOf("no binaryen method succeeded") != -1) + for(const error of WASM_ERROR_MESSAGES) + if(last_error_message.indexOf(error) != -1) { + message = "no native wasm support detected, but its required"; + break; + } + } sendMessage({ token: workerCallbackToken, @@ -31,10 +68,11 @@ try { Module['locateFile'] = file => "../../wasm/" + file; importScripts("../../wasm/TeaWeb-Worker-Codec-Opus.js"); } catch (e) { - console.log(e); - Module['onAbort']("Cloud not load native script!"); + if(typeof(Module['onAbort']) === "function") { + console.log(e); + Module['onAbort']("Failed to load native scripts"); + } /* else the error had been already handled because its a WASM error */ } -//let Module = typeof Module !== 'undefined' ? Module : {}; enum OpusType { VOIP = 2048,