diff --git a/example/web/tdweb/src/index.js b/example/web/tdweb/src/index.js index d79f3e2fa..67dfd2cfe 100644 --- a/example/web/tdweb/src/index.js +++ b/example/web/tdweb/src/index.js @@ -17,10 +17,9 @@ const sleep = ms => new Promise(res => setTimeout(res, ms)); * Differences from TDLib API
* 1. updateFatalError error:string = Update;
* 3. file <..as in td_api..> idb_key:string = File;
- * 2. setJsVerbosity verbosity:int = Ok; // currenly no result will be sent
+ * 2. setJsLogVerbosityLevel new_verbosity_level:string = Ok; * 3. inputFileBlob blob: = InputFile;
*
- * 4. setVerbosity verbosity:int = Ok; // Deprecated */ class TdClient { /** @@ -32,20 +31,20 @@ class TdClient { * Create TdClient * @param {Object} options - Options * @param {updateCallback} options.onUpdate - Callback for all updates. Could also be set explicitly right after TdClient construction. - * @param {number} [options.jsVerbosity='info'] - Verbosity level for javascript part of the code (error, warning, info, log, debug) - * @param {number} [options.verbosity=5] - Verbosity level for tdlib - * @param {string} [options.prefix=tdlib] Currently only one instance of TdClient per a prefix is allowed. All but one created instances will be automatically closed. Usually, the newest instace is kept alive. - * @param {boolean} [options.isBackground=false] - When choosing which instace to keep alive, we prefer instance with isBackground=false + * @param {number} [options.jsLogVerbosityLevel='info'] - Verbosity level for javascript part of the code (error, warning, info, log, debug) + * @param {number} [options.logVerbosityLevel=2] - Verbosity level for tdlib + * @param {string} [options.prefix=tdlib] Currently only one instance of TdClient per a prefix is allowed. All but one created instances will be automatically closed. Usually, the newest instance is kept alive. + * @param {boolean} [options.isBackground=false] - When choosing which instance to keep alive, we prefer instance with isBackground=false * @param {string} [options.mode=wasm] - Type of tdlib build to use. 'asmjs' for asm.js and 'wasm' for WebAssembly. * @param {boolean} [options.readOnly=false] - Open tdlib in read-only mode. Changes to tdlib database won't be persisted. For debug only. */ constructor(options) { - log.setVerbosity(options.jsVerbosity); + log.setVerbosity(options.jsLogVerbosityLevel); this.worker = new MyWorker(); var self = this; this.worker.onmessage = function(e) { let response = e.data; - log.info( + log.debug( 'receive from worker: ', JSON.parse( JSON.stringify(response, (key, value) => { @@ -115,11 +114,11 @@ class TdClient { query_id: this.query_id }; } - if (query['@type'] === 'setJsVerbosity') { - log.setVerbosity(query.verbosity); + if (query['@type'] === 'setJsLogVerbosityLevel') { + log.setVerbosity(query.new_verbosity_level); } - log.info('send to worker: ', query); + log.debug('send to worker: ', query); this.worker.postMessage(query); return new Promise((resolve, reject) => { this.query_callbacks.set(this.query_id, [resolve, reject]); diff --git a/example/web/tdweb/src/worker.js b/example/web/tdweb/src/worker.js index 074e9da00..c98ba4fd9 100644 --- a/example/web/tdweb/src/worker.js +++ b/example/web/tdweb/src/worker.js @@ -323,7 +323,7 @@ class TdClient { return; } await this.testLocalForage(); - log.setVerbosity(options.jsVerbosity); + log.setVerbosity(options.jsLogVerbosityLevel); this.wasInit = true; options = options || {}; @@ -397,10 +397,10 @@ class TdClient { log.info('FS inited'); // no async initialization after this point - if (options.verbosity === undefined) { - options.verbosity = 5; + if (options.logVerbosityLevel === undefined) { + options.logVerbosityLevel = 2; } - this.td_functions.td_set_verbosity(options.verbosity); + this.td_functions.td_set_verbosity(options.logVerbosityLevel); this.client = this.td_functions.td_create(); this.savingFiles = new Map(); @@ -416,7 +416,6 @@ class TdClient { this.flushPendingQueries(); this.receive(); - //setInterval(()=>this.receive(), 100); } prepareQueryRecursive(query) { @@ -464,12 +463,16 @@ class TdClient { this.onStart(); return; } - if (query['@type'] === 'setJsVerbosity') { - log.setVerbosity(query.verbosity); + if (query['@type'] === 'setJsLogVerbosityLevel') { + log.setVerbosity(query.new_verbosity_level); return; } - if (query['@type'] === 'setVerbosity') { - this.td_functions.td_set_verbosity(query.verbosity); + if (query['@type'] === 'setLogVerbosityLevel' || + query['@type'] === 'getLogVerbosityLevel' || + query['@type'] === 'setLogTagVerbosityLevel' || + query['@type'] === 'getLogTagVerbosityLevel' || + query['@type'] === 'getLogTags') { + this.execute(query); return; } if (this.isPending) { @@ -481,6 +484,15 @@ class TdClient { this.scheduleReceiveSoon(); } + execute(query) { + try { + let res = this.td_functions.td_execute(0, JSON.stringify(query)); + let response = JSON.parse(res); + this.callback(response); + } catch (error) { + this.onFatalError(error); + } + } receive() { this.cancelReceive(); if (this.wasFatalError) {