load wasm binary for akono

This commit is contained in:
Florian Dold 2019-08-16 10:31:36 +02:00
parent 0049a240e7
commit 8f5b6ffd7d
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -57,22 +57,39 @@ export class SynchronousCryptoWorker {
}
}
private getEmscriptenEnvironment(): Promise<EmscEnvironment> {
private async getWasmBinary(): Promise<Uint8Array> {
// @ts-ignore
const akonoGetData = global.__akono_getData;
if (akonoGetData) {
// We're running embedded node on Android
console.log("reading wasm binary from akono");
const data = akonoGetData("taler-emscripten-lib.wasm");
// The data we get is base64-encoded binary data
let buf = new Buffer(data, 'base64');
return new Uint8Array(buf);
} else {
// We're in a normal node environment
const binaryPath = __dirname + "/../../../emscripten/taler-emscripten-lib.wasm";
console.log("reading from", binaryPath);
const wasmBinary = new Uint8Array(fs.readFileSync(binaryPath));
return wasmBinary;
}
}
private async getEmscriptenEnvironment(): Promise<EmscEnvironment> {
if (this.cachedEmscEnvironment) {
return Promise.resolve(this.cachedEmscEnvironment);
return this.cachedEmscEnvironment;
}
if (this.cachedEmscEnvironmentPromise) {
return this.cachedEmscEnvironmentPromise;
}
const binaryPath =
__dirname + "/../../../emscripten/taler-emscripten-lib.wasm";
console.log("reading from", binaryPath);
const wasmBinary = new Uint8Array(fs.readFileSync(binaryPath));
let lib: any;
const wasmBinary = await this.getWasmBinary();
return new Promise((resolve, reject) => {
// Arguments passed to the emscripten prelude
const libArgs = {