tdweb: update dependencies

GitOrigin-RevId: fd26c28c878ac4b74f8beca25958ce54d4a428b0
This commit is contained in:
Arseny Smirnov 2019-04-24 10:04:52 +03:00
parent 5cc40abeba
commit 7312a624c5
3 changed files with 134 additions and 96 deletions

View File

@ -3,12 +3,16 @@
"version": "0.2.43", "version": "0.2.43",
"description": "Javascript interface for TDLib (telegram library)", "description": "Javascript interface for TDLib (telegram library)",
"main": "dist/tdweb.js", "main": "dist/tdweb.js",
"repository": {
"type": "git",
"url": "https://github.com/tdlib/td.git",
"directory": "example/web/tdweb"
},
"files": [ "files": [
"dist" "dist"
], ],
"scripts": { "scripts": {
"precommit": "lint-staged", "build": "webpack --mode production",
"build": "webpack",
"start": "webpack-dev-server --open" "start": "webpack-dev-server --open"
}, },
"keywords": [ "keywords": [
@ -17,34 +21,38 @@
"author": "Arseny Smirnov", "author": "Arseny Smirnov",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.3", "@babel/core": "^7.4.3",
"babel-eslint": "^7.2.3", "@babel/plugin-syntax-dynamic-import": "^7.2.0",
"babel-loader": "^7.1.5", "@babel/plugin-transform-runtime": "^7.4.3",
"babel-plugin-syntax-dynamic-import": "^6.18.0", "@babel/preset-env": "^7.4.3",
"babel-plugin-transform-runtime": "^6.23.0", "@typescript-eslint/eslint-plugin": "^1.7.0",
"babel-preset-env": "^1.7.0", "acorn": "^6.1.1",
"clean-webpack-plugin": "^0.1.19", "babel-eslint": "^10.0.1",
"eslint": "^4.19.1", "babel-loader": "^8.0.5",
"eslint-config-react-app": "^2.1.0", "clean-webpack-plugin": "^2.0.1",
"eslint-loader": "^1.9.0", "eslint": "^5.16.0",
"eslint-plugin-flowtype": "^2.50.1", "eslint-config-react-app": "^4.0.0",
"eslint-plugin-import": "^2.14.0", "eslint-loader": "^2.1.2",
"eslint-plugin-jsx-a11y": "^5.1.1", "eslint-plugin-flowtype": "^2.0.0",
"eslint-plugin-react": "^7.11.1", "eslint-plugin-import": "^2.17.2",
"exports-loader": "^0.6.4", "eslint-plugin-jsx-a11y": "^6.2.1",
"file-loader": "^1.1.11", "eslint-plugin-react": "^7.12.4",
"html-webpack-plugin": "^2.30.1", "eslint-plugin-react-hooks": "^1.6.0",
"husky": "^0.14.3", "file-loader": "^3.0.1",
"lint-staged": "^4.3.0", "husky": "^1.3.1",
"prettier": "^1.14.2", "lint-staged": "^8.1.5",
"script-loader": "^0.7.2", "prettier": "^1.17.0",
"uglifyjs-webpack-plugin": "^1.3.0", "typescript": "^3.4.5",
"webpack": "^3.12.0", "webpack": "4.28.2",
"webpack-dev-server": "^2.11.3", "webpack-cli": "^3.3.1",
"worker-loader": "^1.1.1" "worker-loader": "^2.0.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}, },
"lint-staged": { "lint-staged": {
"gitDir": "../../../",
"linters": { "linters": {
"webpack.config.json": [ "webpack.config.json": [
"prettier --single-quote --write", "prettier --single-quote --write",
@ -61,18 +69,17 @@
} }
}, },
"dependencies": { "dependencies": {
"babel-runtime": "^6.26.0", "@babel/runtime": "^7.4.3",
"detect-browser": "^2.5.1", "localforage": "^1.7.3",
"localforage": "^1.7.2",
"uuid": "^3.3.2" "uuid": "^3.3.2"
}, },
"babel": { "babel": {
"presets": [ "presets": [
"env" "@babel/env"
], ],
"plugins": [ "plugins": [
"syntax-dynamic-import", "@babel/syntax-dynamic-import",
"transform-runtime" "@babel/transform-runtime"
] ]
}, },
"eslintConfig": { "eslintConfig": {
@ -84,6 +91,11 @@
}, },
"globals": { "globals": {
"WebAssembly": true "WebAssembly": true
},
"settings": {
"react": {
"version": "999.999.999"
}
} }
} }
} }

View File

@ -1,8 +1,6 @@
import localforage from 'localforage'; import localforage from 'localforage';
import log from './logger.js'; import log from './logger.js';
import { import { instantiateAny } from './wasm-utils.js';
instantiateAny
} from './wasm-utils.js';
import td_wasm_release from './prebuilt/release/td_wasm.wasm'; import td_wasm_release from './prebuilt/release/td_wasm.wasm';
@ -10,7 +8,11 @@ import td_wasm_release from './prebuilt/release/td_wasm.wasm';
import td_asmjs_mem_release from './prebuilt/release/td_asmjs.js.mem'; import td_asmjs_mem_release from './prebuilt/release/td_asmjs.js.mem';
const tdlibVersion = 6; const tdlibVersion = 6;
const localForageDrivers = [localforage.INDEXEDDB, localforage.LOCALSTORAGE, 'memoryDriver']; const localForageDrivers = [
localforage.INDEXEDDB,
localforage.LOCALSTORAGE,
'memoryDriver'
];
async function initLocalForage() { async function initLocalForage() {
// Implement the driver here. // Implement the driver here.
@ -31,14 +33,14 @@ async function initLocalForage() {
}, },
getItem: async function(key) { getItem: async function(key) {
let value = this._map.get(key); let value = this._map.get(key);
console.log("getItem", this._map, key, value); console.log('getItem', this._map, key, value);
return value; return value;
}, },
iterate: async function(iteratorCallback) { iterate: async function(iteratorCallback) {
log.error("iterate is not supported"); log.error('iterate is not supported');
}, },
key: async function(n) { key: async function(n) {
log.error("key n is not supported"); log.error('key n is not supported');
}, },
keys: async function() { keys: async function() {
return this._map.keys(); return this._map.keys();
@ -47,15 +49,15 @@ async function initLocalForage() {
return this._map.size(); return this._map.size();
}, },
removeItem: async function(key) { removeItem: async function(key) {
this._map.delete(key) this._map.delete(key);
}, },
setItem: async function(key, value) { setItem: async function(key, value) {
let originalValue = this._map.get(key); let originalValue = this._map.get(key);
console.log("setItem", this._map, key, value); console.log('setItem', this._map, key, value);
this._map.set(key, value); this._map.set(key, value);
return originalValue; return originalValue;
} }
} };
// Add the driver to localForage. // Add the driver to localForage.
localforage.defineDriver(memoryDriver); localforage.defineDriver(memoryDriver);
@ -66,7 +68,7 @@ async function loadTdLibWasm(onFS) {
let Module = await import('./prebuilt/release/td_wasm.js'); let Module = await import('./prebuilt/release/td_wasm.js');
log.info('got td_wasm.js'); log.info('got td_wasm.js');
let td_wasm = td_wasm_release; let td_wasm = td_wasm_release;
let module = Module({ let module = Module.default({
onRuntimeInitialized: () => { onRuntimeInitialized: () => {
log.info('runtime intialized'); log.info('runtime intialized');
}, },
@ -126,18 +128,23 @@ async function loadTdLibAsmjs(onFS) {
async function loadTdLib(mode, onFS) { async function loadTdLib(mode, onFS) {
const wasmSupported = (() => { const wasmSupported = (() => {
try { try {
if (typeof WebAssembly === "object" if (
&& typeof WebAssembly.instantiate === "function") { typeof WebAssembly === 'object' &&
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); typeof WebAssembly.instantiate === 'function'
) {
const module = new WebAssembly.Module(
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)
);
if (module instanceof WebAssembly.Module) if (module instanceof WebAssembly.Module)
return new WebAssembly.Instance(module) instanceof WebAssembly.Instance; return (
} new WebAssembly.Instance(module) instanceof WebAssembly.Instance
} catch (e) { );
} }
} catch (e) {}
return false; return false;
})(); })();
if (!wasmSupported) { if (!wasmSupported) {
log.warning("WebAssembly is not supported, trying to use asmjs"); log.warning('WebAssembly is not supported, trying to use asmjs');
mode = 'asmjs'; mode = 'asmjs';
} }
@ -212,7 +219,9 @@ class InboundFileSystem {
log.debug('InboundFileSystem::create::keys start'); log.debug('InboundFileSystem::create::keys start');
let keys = await this.store.keys(); let keys = await this.store.keys();
let keys_time = (performance.now() - keys_start) / 1000; let keys_time = (performance.now() - keys_start) / 1000;
log.debug('InboundFileSystem::create::keys ' + keys_time + ' ' + keys.length); log.debug(
'InboundFileSystem::create::keys ' + keys_time + ' ' + keys.length
);
this.pids = new Set(keys); this.pids = new Set(keys);
} }
@ -262,23 +271,23 @@ class DbFileSystem {
}); });
}); });
let rmrf = (path) => { let rmrf = path => {
log.debug("rmrf " , path); log.debug('rmrf ', path);
var info; var info;
try { try {
info = FS.lookupPath(path); info = FS.lookupPath(path);
} catch (e) { } catch (e) {
return; return;
} }
log.debug("rmrf " , path, info); log.debug('rmrf ', path, info);
if (info.node.isFolder) { if (info.node.isFolder) {
for (var key in info.node.contents) { for (var key in info.node.contents) {
rmrf(info.path + '/' + info.node.contents[key].name); rmrf(info.path + '/' + info.node.contents[key].name);
} }
log.debug("rmdir " , path); log.debug('rmdir ', path);
FS.rmdir(path); FS.rmdir(path);
} else { } else {
log.debug("unlink " , path); log.debug('unlink ', path);
FS.unlink(path); FS.unlink(path);
} }
}; };
@ -287,15 +296,15 @@ class DbFileSystem {
let root_dir = FS.lookupPath(root); let root_dir = FS.lookupPath(root);
for (var key in root_dir.node.contents) { for (var key in root_dir.node.contents) {
let value = root_dir.node.contents[key]; let value = root_dir.node.contents[key];
log.debug("node " , key, value); log.debug('node ', key, value);
if (!value.isFolder) { if (!value.isFolder) {
continue; continue;
} }
dirs.push(root_dir.path + '/' + value.name) dirs.push(root_dir.path + '/' + value.name);
} }
for (let i in dirs) { for (let i in dirs) {
let dir = dirs[i]; let dir = dirs[i];
rmrf(dir) rmrf(dir);
//FS.mkdir(dir); //FS.mkdir(dir);
//FS.mount(FS.filesystems.MEMFS, {}, dir); //FS.mount(FS.filesystems.MEMFS, {}, dir);
} }
@ -343,11 +352,11 @@ class DbFileSystem {
req.onerror = function(e) { req.onerror = function(e) {
log.info('ONERROR'); log.info('ONERROR');
reject(e.error); reject(e.error);
} };
req.onblocked = function(e) { req.onblocked = function(e) {
log.info('ONBLOCKED'); log.info('ONBLOCKED');
reject('blocked'); reject('blocked');
} };
}); });
} }
} }
@ -372,7 +381,11 @@ class TdFileSystem {
); );
//IDBFS. MEMFS which is flushed to IDB from time to time //IDBFS. MEMFS which is flushed to IDB from time to time
let dbFileSystem = DbFileSystem.create(prefix + '/dbfs', FS_promise, readOnly); let dbFileSystem = DbFileSystem.create(
prefix + '/dbfs',
FS_promise,
readOnly
);
let FS = await FS_promise; let FS = await FS_promise;
tdfs.FS = FS; tdfs.FS = FS;
@ -414,20 +427,20 @@ class TdClient {
localForageDrivers localForageDrivers
]; ];
for (const driverName of DRIVERS) { for (const driverName of DRIVERS) {
console.log("Test ", driverName); console.log('Test ', driverName);
try { try {
await localforage.setDriver(driverName); await localforage.setDriver(driverName);
console.log("A"); console.log('A');
await localforage.setItem('hello', 'world'); await localforage.setItem('hello', 'world');
console.log("B"); console.log('B');
let x = await localforage.getItem('hello'); let x = await localforage.getItem('hello');
console.log("got ", x); console.log('got ', x);
await localforage.clear(); await localforage.clear();
console.log("C"); console.log('C');
} catch (error) { } catch (error) {
console.log("Error", error); console.log('Error', error);
}
} }
};
} }
async init(options) { async init(options) {
@ -573,7 +586,8 @@ class TdClient {
query.parameters.use_secret_chats = useDb; query.parameters.use_secret_chats = useDb;
} }
if (query['@type'] === 'getLanguagePackString') { if (query['@type'] === 'getLanguagePackString') {
query.language_pack_database_path = this.tdfs.dbFileSystem.root + '/language'; query.language_pack_database_path =
this.tdfs.dbFileSystem.root + '/language';
} }
return this.prepareQueryRecursive(query); return this.prepareQueryRecursive(query);
} }
@ -591,16 +605,24 @@ class TdClient {
var buf = new Uint8Array(query.size); var buf = new Uint8Array(query.size);
this.FS.read(stream, buf, 0, query.size, query.offset); this.FS.read(stream, buf, 0, query.size, query.offset);
this.FS.close(stream); this.FS.close(stream);
res = buf res = buf;
} catch (e) { } catch (e) {
this.callback({'@type':'error', '@extra': query['@extra'], code: 400, message: e}); this.callback({
'@type': 'error',
'@extra': query['@extra'],
code: 400,
message: e
});
return; return;
} }
this.callback({ this.callback(
{
'@type': 'FilePart', '@type': 'FilePart',
'@extra': query['@extra'], '@extra': query['@extra'],
'data': res data: res
}, [res.buffer]); },
[res.buffer]
);
} }
send(query) { send(query) {
@ -630,11 +652,13 @@ class TdClient {
this.pendingQueries.push(query); this.pendingQueries.push(query);
return; return;
} }
if (query['@type'] === 'setLogVerbosityLevel' || if (
query['@type'] === 'setLogVerbosityLevel' ||
query['@type'] === 'getLogVerbosityLevel' || query['@type'] === 'getLogVerbosityLevel' ||
query['@type'] === 'setLogTagVerbosityLevel' || query['@type'] === 'setLogTagVerbosityLevel' ||
query['@type'] === 'getLogTagVerbosityLevel' || query['@type'] === 'getLogTagVerbosityLevel' ||
query['@type'] === 'getLogTags') { query['@type'] === 'getLogTags'
) {
this.execute(query); this.execute(query);
return; return;
} }
@ -744,8 +768,7 @@ class TdClient {
authorization_state: { authorization_state: {
'@type': 'authorizationStateClosed' '@type': 'authorizationStateClosed'
} }
} });
);
} }
async asyncOnFatalError(error) { async asyncOnFatalError(error) {

View File

@ -1,7 +1,5 @@
const path = require('path'); const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = { module.exports = {
entry: ['./src/index.js'], entry: ['./src/index.js'],
@ -10,16 +8,20 @@ module.exports = {
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, 'dist'),
library: 'tdweb', library: 'tdweb',
libraryTarget: 'umd', libraryTarget: 'umd',
umdNamedDefine: true umdNamedDefine: true,
globalObject: 'this'
}, },
devServer: { devServer: {
contentBase: './dist' contentBase: './dist'
}, },
plugins: [ plugins: [
// new HtmlWebpackPlugin(), // new HtmlWebpackPlugin(),
new CleanWebpackPlugin(['dist'], {}) new CleanWebpackPlugin({})
//, new UglifyJSPlugin() //, new UglifyJSPlugin()
], ],
optimization:{
minimize: false, // <---- disables uglify.
},
module: { module: {
noParse: /td_asmjs\.js$/, noParse: /td_asmjs\.js$/,
rules: [ rules: [
@ -56,6 +58,7 @@ module.exports = {
{ {
test: /\.(wasm|mem)$/, test: /\.(wasm|mem)$/,
include: [path.resolve(__dirname, 'src')], include: [path.resolve(__dirname, 'src')],
type: "javascript/auto",
use: [ use: [
{ {
loader: require.resolve('file-loader') loader: require.resolve('file-loader')