tdweb: options.wasmUrl

GitOrigin-RevId: 24047f84740d201397045a33b680a850359af9b9
This commit is contained in:
Arseny Smirnov 2019-07-02 15:06:05 +02:00
parent ef3cf44240
commit fdb303f513

View File

@ -61,17 +61,20 @@ async function initLocalForage() {
localforage.defineDriver(memoryDriver); localforage.defineDriver(memoryDriver);
} }
async function loadTdlibWasm(onFS) { async function loadTdlibWasm(onFS, wasmUrl) {
console.log('loadTdlibWasm'); console.log('loadTdlibWasm');
const Module = await import('./prebuilt/release/td_wasm.js'); const Module = await import('./prebuilt/release/td_wasm.js');
log.info('got td_wasm.js'); log.info('got td_wasm.js');
const td_wasm = td_wasm_release; let td_wasm = td_wasm_release;
if (wasmUrl) {
td_wasm = wasmUrl;
}
const module = Module.default({ const module = Module.default({
onRuntimeInitialized: () => { onRuntimeInitialized: () => {
log.info('runtime intialized'); log.info('runtime intialized');
}, },
instantiateWasm: (imports, successCallback) => { instantiateWasm: (imports, successCallback) => {
log.info('start instantiateWasm'); log.info('start instantiateWasm', td_wasm);
const next = instance => { const next = instance => {
log.info('finish instantiateWasm'); log.info('finish instantiateWasm');
successCallback(instance); successCallback(instance);
@ -99,7 +102,7 @@ async function loadTdlibAsmjs(onFS) {
console.log('got td_asm.js'); console.log('got td_asm.js');
const fromFile = 'td_asmjs.js.mem'; const fromFile = 'td_asmjs.js.mem';
const toFile = td_asmjs_mem_release; const toFile = td_asmjs_mem_release;
const module = Module({ const module = Module.default({
onRuntimeInitialized: () => { onRuntimeInitialized: () => {
console.log('runtime intialized'); console.log('runtime intialized');
}, },
@ -122,7 +125,7 @@ async function loadTdlibAsmjs(onFS) {
return TdModule; return TdModule;
} }
async function loadTdlib(mode, onFS) { async function loadTdlib(mode, onFS, wasmUrl) {
const wasmSupported = (() => { const wasmSupported = (() => {
try { try {
if ( if (
@ -152,7 +155,7 @@ async function loadTdlib(mode, onFS) {
if (mode === 'asmjs') { if (mode === 'asmjs') {
return loadTdlibAsmjs(onFS); return loadTdlibAsmjs(onFS);
} }
return loadTdlibWasm(onFS); return loadTdlibWasm(onFS, wasmUrl);
} }
class OutboundFileSystem { class OutboundFileSystem {
@ -481,7 +484,7 @@ class TdClient {
} }
log.info('load TdModule'); log.info('load TdModule');
this.TdModule = await loadTdlib(mode, this.onFS); this.TdModule = await loadTdlib(mode, this.onFS, options.wasmUrl);
log.info('got TdModule'); log.info('got TdModule');
this.td_functions = { this.td_functions = {
td_create: this.TdModule.cwrap('td_create', 'number', []), td_create: this.TdModule.cwrap('td_create', 'number', []),