tdweb: 0.2.24 (unstable), automatic wasm streaming support, and experiments with private mode in firefox
GitOrigin-RevId: caafea864dc13fe881a90d3db19ddf442c3bd0ac
This commit is contained in:
parent
eb382c0d0b
commit
071e8b1d6d
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@arseny30/tdweb",
|
||||
"version": "0.2.23",
|
||||
"version": "0.2.24",
|
||||
"description": "Javascript interface for TDLib (telegram library)",
|
||||
"main": "dist/tdweb.js",
|
||||
"files": [
|
||||
|
@ -3,10 +3,9 @@
|
||||
// This library function fetches the wasm module at 'url', instantiates it with
|
||||
// the given 'importObject', and returns the instantiated object instance
|
||||
|
||||
export function instantiateStreaming(url, importObject) {
|
||||
return WebAssembly.instantiateStreaming(fetch(url), importObject).then(
|
||||
results => results.instance
|
||||
);
|
||||
export async function instantiateStreaming(url, importObject) {
|
||||
let result = await WebAssembly.instantiateStreaming(fetch(url), importObject);
|
||||
return result.instance;
|
||||
}
|
||||
export function fetchAndInstantiate(url, importObject) {
|
||||
return fetch(url)
|
||||
@ -119,3 +118,19 @@ export function instantiateCachedURL(dbVersion, url, importObject) {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function instantiateAny(version, url, importObject) {
|
||||
console.log("instantiate");
|
||||
try {
|
||||
return await instantiateStreaming(url, importObject);
|
||||
} catch (e) {
|
||||
console.log("instantiateSteaming failed", e);
|
||||
}
|
||||
try {
|
||||
return await instantiateCachedURL(version, url, importObject);
|
||||
} catch (e) {
|
||||
console.log("instantiateCachedURL failed", e);
|
||||
}
|
||||
throw new Error("can't instantiate wasm");
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
import localforage from 'localforage';
|
||||
import log from './logger.js';
|
||||
import {
|
||||
instantiateCachedURL,
|
||||
/*fetchAndInstantiate,*/ instantiateStreaming
|
||||
instantiateAny
|
||||
} from './wasm-utils.js';
|
||||
|
||||
import td_wasm_release from './prebuilt/release/td_wasm.wasm';
|
||||
@ -12,9 +11,59 @@ import td_wasm_release from './prebuilt/release/td_wasm.wasm';
|
||||
|
||||
import { detect } from 'detect-browser';
|
||||
const browser = detect();
|
||||
const tdlibVersion = 5;
|
||||
const tdlibVersion = 6;
|
||||
const localForageDrivers = [localforage.INDEXEDDB, localforage.LOCALSTORAGE, 'memoryDriver'];
|
||||
|
||||
async function loadTdLibWasm(useStreaming) {
|
||||
async function initLocalForage() {
|
||||
// Implement the driver here.
|
||||
var memoryDriver = {
|
||||
_driver: 'memoryDriver',
|
||||
_initStorage: function(options) {
|
||||
var dbInfo = {};
|
||||
if (options) {
|
||||
for (var i in options) {
|
||||
dbInfo[i] = options[i];
|
||||
}
|
||||
}
|
||||
this._dbInfo = dbInfo;
|
||||
this._map = new Map();
|
||||
},
|
||||
clear: async function() {
|
||||
this._map.clear();
|
||||
},
|
||||
getItem: async function(key) {
|
||||
let value = this._map.get(key);
|
||||
console.log("getItem", this._map, key, value);
|
||||
return value;
|
||||
},
|
||||
iterate: async function(iteratorCallback) {
|
||||
log.error("iterate is not supported");
|
||||
},
|
||||
key: async function(n) {
|
||||
log.error("key n is not supported");
|
||||
},
|
||||
keys: async function() {
|
||||
return this._map.keys();
|
||||
},
|
||||
length: async function() {
|
||||
return this._map.size();
|
||||
},
|
||||
removeItem: async function(key) {
|
||||
this._map.delete(key)
|
||||
},
|
||||
setItem: async function(key, value) {
|
||||
let originalValue = this._map.get(key);
|
||||
console.log("setItem", this._map, key, value);
|
||||
this._map.set(key, value);
|
||||
return originalValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the driver to localForage.
|
||||
localforage.defineDriver(memoryDriver);
|
||||
}
|
||||
|
||||
async function loadTdLibWasm() {
|
||||
let Module = await import('./prebuilt/release/td_wasm.js');
|
||||
log.info('got td_wasm.js');
|
||||
let td_wasm = td_wasm_release;
|
||||
@ -29,11 +78,7 @@ async function loadTdLibWasm(useStreaming) {
|
||||
log.info('finish instantiateWasm');
|
||||
successCallback(instance);
|
||||
};
|
||||
if (useStreaming) {
|
||||
instantiateStreaming(td_wasm, imports).then(next);
|
||||
} else {
|
||||
instantiateCachedURL(tdlibVersion, td_wasm, imports).then(next);
|
||||
}
|
||||
instantiateAny(tdlibVersion, td_wasm, imports).then(next);
|
||||
return {};
|
||||
},
|
||||
ENVIROMENT: 'WORKER'
|
||||
@ -78,7 +123,7 @@ async function loadTdLib(mode) {
|
||||
//if (mode === 'asmjs') {
|
||||
//return loadTdLibAsmjs();
|
||||
//}
|
||||
return loadTdLibWasm(mode !== 'wasm');
|
||||
return loadTdLibWasm();
|
||||
}
|
||||
|
||||
class OutboundFileSystem {
|
||||
@ -125,7 +170,8 @@ class InboundFileSystem {
|
||||
FS.mkdir(root);
|
||||
|
||||
ifs.store = localforage.createInstance({
|
||||
name: dbName
|
||||
name: dbName,
|
||||
driver: localForageDrivers
|
||||
});
|
||||
let keys = await ifs.store.keys();
|
||||
|
||||
@ -246,10 +292,37 @@ class TdClient {
|
||||
this.wasInit = false;
|
||||
}
|
||||
|
||||
async testLocalForage() {
|
||||
await initLocalForage();
|
||||
var DRIVERS = [
|
||||
localforage.INDEXEDDB,
|
||||
'memoryDriver',
|
||||
localforage.LOCALSTORAGE,
|
||||
localforage.WEBSQL,
|
||||
localForageDrivers
|
||||
];
|
||||
for (const driverName of DRIVERS) {
|
||||
console.log("Test ", driverName);
|
||||
try {
|
||||
await localforage.setDriver(driverName);
|
||||
console.log("A");
|
||||
await localforage.setItem('hello', 'world');
|
||||
console.log("B");
|
||||
let x = await localforage.getItem('hello');
|
||||
console.log("got ", x);
|
||||
await localforage.clear();
|
||||
console.log("C");
|
||||
} catch (error) {
|
||||
console.log("Error", error);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async init(options) {
|
||||
if (this.wasInit) {
|
||||
return;
|
||||
}
|
||||
await this.testLocalForage();
|
||||
log.setVerbosity(options.jsVerbosity);
|
||||
this.wasInit = true;
|
||||
|
||||
|
@ -570,8 +570,9 @@ void AuthManager::set_phone_number(uint64 query_id, string phone_number, bool al
|
||||
|
||||
on_new_query(query_id);
|
||||
|
||||
auto unique_id = UniqueId::next();
|
||||
start_net_query(NetQueryType::SendCode,
|
||||
G()->net_query_creator().create(create_storer(r_send_code.move_as_ok()), DcId::main(),
|
||||
G()->net_query_creator().create(unique_id, create_storer(r_send_code.move_as_ok()), DcId::main(),
|
||||
NetQuery::Type::Common, NetQuery::AuthFlag::Off));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user