Improved codec error handling
This commit is contained in:
parent
e1a1e72c51
commit
fa30d3d055
2 changed files with 60 additions and 18 deletions
|
@ -21,18 +21,22 @@ class CodecPool {
|
||||||
private _supported: boolean = true;
|
private _supported: boolean = true;
|
||||||
|
|
||||||
initialize(cached: number) {
|
initialize(cached: number) {
|
||||||
for(let i = 0; i < cached; i++)
|
/* test if we're able to use this codec */
|
||||||
this.ownCodec(i + 1).then(codec => {
|
const dummy_client_id = 0xFFEF;
|
||||||
|
|
||||||
|
this.ownCodec(dummy_client_id).then(codec => {
|
||||||
console.log(tr("Release again! (%o)"), codec);
|
console.log(tr("Release again! (%o)"), codec);
|
||||||
this.releaseCodec(i + 1);
|
this.releaseCodec(dummy_client_id);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.warn(tr("Disabling codec support for "), this.name);
|
|
||||||
if(this._supported) {
|
if(this._supported) {
|
||||||
|
console.warn(tr("Disabling codec support for "), this.name);
|
||||||
createErrorModal(tr("Could not load codec driver"), tr("Could not load or initialize codec ") + this.name + "<br>" +
|
createErrorModal(tr("Could not load codec driver"), tr("Could not load or initialize codec ") + this.name + "<br>" +
|
||||||
"Error: <code>" + JSON.stringify(error) + "</code>").open();
|
"Error: <code>" + JSON.stringify(error) + "</code>").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;
|
this._supported = false;
|
||||||
console.error(error);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +60,7 @@ class CodecPool {
|
||||||
this.ownCodec(clientId, false).then(resolve).catch(reject);
|
this.ownCodec(clientId, false).then(resolve).catch(reject);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(tr("Could not initialize codec!\nError: %o"), 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;
|
return;
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
/// <reference path="CodecWorker.ts" />
|
/// <reference path="CodecWorker.ts" />
|
||||||
|
|
||||||
this["Module"] = typeof this["Module"] !== "undefined" ? this["Module"] : {};
|
const WASM_ERROR_MESSAGES = [
|
||||||
|
'no native wasm support detected'
|
||||||
|
];
|
||||||
|
|
||||||
|
this["Module"] = this["Module"] || {};
|
||||||
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
Module['onRuntimeInitialized'] = function() {
|
Module['onRuntimeInitialized'] = function() {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
@ -12,11 +17,43 @@ Module['onRuntimeInitialized'] = function() {
|
||||||
success: true
|
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;
|
Module['onAbort'] = undefined;
|
||||||
|
|
||||||
if(message instanceof DOMException)
|
if(message instanceof DOMException)
|
||||||
message = "DOMException (" + message.name + "): " + message.code + " => " + message.message;
|
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({
|
sendMessage({
|
||||||
token: workerCallbackToken,
|
token: workerCallbackToken,
|
||||||
|
@ -31,10 +68,11 @@ try {
|
||||||
Module['locateFile'] = file => "../../wasm/" + file;
|
Module['locateFile'] = file => "../../wasm/" + file;
|
||||||
importScripts("../../wasm/TeaWeb-Worker-Codec-Opus.js");
|
importScripts("../../wasm/TeaWeb-Worker-Codec-Opus.js");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if(typeof(Module['onAbort']) === "function") {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
Module['onAbort']("Cloud not load native script!");
|
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 {
|
enum OpusType {
|
||||||
VOIP = 2048,
|
VOIP = 2048,
|
||||||
|
|
Loading…
Add table
Reference in a new issue