tdweb: use td_execute for verbosity, rename verbosity
GitOrigin-RevId: e099e4acc918392613dab33832390e51086ba8be
This commit is contained in:
parent
82589eeb2f
commit
909772df8f
@ -17,10 +17,9 @@ const sleep = ms => new Promise(res => setTimeout(res, ms));
|
|||||||
* Differences from TDLib API<br>
|
* Differences from TDLib API<br>
|
||||||
* 1. updateFatalError error:string = Update; <br>
|
* 1. updateFatalError error:string = Update; <br>
|
||||||
* 3. file <..as in td_api..> idb_key:string = File; <br>
|
* 3. file <..as in td_api..> idb_key:string = File; <br>
|
||||||
* 2. setJsVerbosity verbosity:int = Ok; // currenly no result will be sent <br>
|
* 2. setJsLogVerbosityLevel new_verbosity_level:string = Ok;
|
||||||
* 3. inputFileBlob blob:<javascript blob> = InputFile;<br>
|
* 3. inputFileBlob blob:<javascript blob> = InputFile;<br>
|
||||||
* <br>
|
* <br>
|
||||||
* 4. setVerbosity verbosity:int = Ok; // Deprecated
|
|
||||||
*/
|
*/
|
||||||
class TdClient {
|
class TdClient {
|
||||||
/**
|
/**
|
||||||
@ -32,20 +31,20 @@ class TdClient {
|
|||||||
* Create TdClient
|
* Create TdClient
|
||||||
* @param {Object} options - Options
|
* @param {Object} options - Options
|
||||||
* @param {updateCallback} options.onUpdate - Callback for all updates. Could also be set explicitly right after TdClient construction.
|
* @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.jsLogVerbosityLevel='info'] - Verbosity level for javascript part of the code (error, warning, info, log, debug)
|
||||||
* @param {number} [options.verbosity=5] - Verbosity level for tdlib
|
* @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 instace is kept alive.
|
* @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 instace to keep alive, we prefer instance with isBackground=false
|
* @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 {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.
|
* @param {boolean} [options.readOnly=false] - Open tdlib in read-only mode. Changes to tdlib database won't be persisted. For debug only.
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
log.setVerbosity(options.jsVerbosity);
|
log.setVerbosity(options.jsLogVerbosityLevel);
|
||||||
this.worker = new MyWorker();
|
this.worker = new MyWorker();
|
||||||
var self = this;
|
var self = this;
|
||||||
this.worker.onmessage = function(e) {
|
this.worker.onmessage = function(e) {
|
||||||
let response = e.data;
|
let response = e.data;
|
||||||
log.info(
|
log.debug(
|
||||||
'receive from worker: ',
|
'receive from worker: ',
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
JSON.stringify(response, (key, value) => {
|
JSON.stringify(response, (key, value) => {
|
||||||
@ -115,11 +114,11 @@ class TdClient {
|
|||||||
query_id: this.query_id
|
query_id: this.query_id
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (query['@type'] === 'setJsVerbosity') {
|
if (query['@type'] === 'setJsLogVerbosityLevel') {
|
||||||
log.setVerbosity(query.verbosity);
|
log.setVerbosity(query.new_verbosity_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info('send to worker: ', query);
|
log.debug('send to worker: ', query);
|
||||||
this.worker.postMessage(query);
|
this.worker.postMessage(query);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.query_callbacks.set(this.query_id, [resolve, reject]);
|
this.query_callbacks.set(this.query_id, [resolve, reject]);
|
||||||
|
@ -323,7 +323,7 @@ class TdClient {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.testLocalForage();
|
await this.testLocalForage();
|
||||||
log.setVerbosity(options.jsVerbosity);
|
log.setVerbosity(options.jsLogVerbosityLevel);
|
||||||
this.wasInit = true;
|
this.wasInit = true;
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@ -397,10 +397,10 @@ class TdClient {
|
|||||||
log.info('FS inited');
|
log.info('FS inited');
|
||||||
|
|
||||||
// no async initialization after this point
|
// no async initialization after this point
|
||||||
if (options.verbosity === undefined) {
|
if (options.logVerbosityLevel === undefined) {
|
||||||
options.verbosity = 5;
|
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.client = this.td_functions.td_create();
|
||||||
|
|
||||||
this.savingFiles = new Map();
|
this.savingFiles = new Map();
|
||||||
@ -416,7 +416,6 @@ class TdClient {
|
|||||||
this.flushPendingQueries();
|
this.flushPendingQueries();
|
||||||
|
|
||||||
this.receive();
|
this.receive();
|
||||||
//setInterval(()=>this.receive(), 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareQueryRecursive(query) {
|
prepareQueryRecursive(query) {
|
||||||
@ -464,12 +463,16 @@ class TdClient {
|
|||||||
this.onStart();
|
this.onStart();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (query['@type'] === 'setJsVerbosity') {
|
if (query['@type'] === 'setJsLogVerbosityLevel') {
|
||||||
log.setVerbosity(query.verbosity);
|
log.setVerbosity(query.new_verbosity_level);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (query['@type'] === 'setVerbosity') {
|
if (query['@type'] === 'setLogVerbosityLevel' ||
|
||||||
this.td_functions.td_set_verbosity(query.verbosity);
|
query['@type'] === 'getLogVerbosityLevel' ||
|
||||||
|
query['@type'] === 'setLogTagVerbosityLevel' ||
|
||||||
|
query['@type'] === 'getLogTagVerbosityLevel' ||
|
||||||
|
query['@type'] === 'getLogTags') {
|
||||||
|
this.execute(query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.isPending) {
|
if (this.isPending) {
|
||||||
@ -481,6 +484,15 @@ class TdClient {
|
|||||||
this.scheduleReceiveSoon();
|
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() {
|
receive() {
|
||||||
this.cancelReceive();
|
this.cancelReceive();
|
||||||
if (this.wasFatalError) {
|
if (this.wasFatalError) {
|
||||||
|
Loading…
Reference in New Issue
Block a user