tdweb: minor documentation improvements.

GitOrigin-RevId: 88b5bf71ab142c51586bc7071647efa49400387d
This commit is contained in:
levlam 2019-04-24 22:05:09 +03:00
parent 00bc68ef92
commit 7050bc1b31
2 changed files with 15 additions and 18 deletions

View File

@ -18,8 +18,8 @@ const sleep = ms => new Promise(res => setTimeout(res, ms));
* <br> * <br>
* Differences from TDLib API:<br> * Differences from TDLib API:<br>
* 1. Added the update <code>updateFatalError error:string = Update;</code> which is sent whenever a TDLib fatal error is encountered.<br> * 1. Added the update <code>updateFatalError error:string = Update;</code> which is sent whenever a TDLib fatal error is encountered.<br>
* 2. Added the field <code>idb_key</code> to <code>file</code> object, which contains IndexedDB key in which the file content is stored. IndexedDB table name is options.instanceName. <br> * 2. Added the field <code>idb_key</code> to <code>file</code> object, which contains IndexedDB key in which the file content is stored.<br>
* This field is non-empty only for fully downloaded files. IndexedDB database name is chosen during TdClient creation.<br> * This field is non-empty only for fully downloaded files. IndexedDB database name is chosen during TdClient creation via options.instanceName parameter.<br>
* 3. Added the method <code>setJsLogVerbosityLevel new_verbosity_level:string = Ok;</code>, which allows to change the verbosity level of tdweb logging.<br> * 3. Added the method <code>setJsLogVerbosityLevel new_verbosity_level:string = Ok;</code>, which allows to change the verbosity level of tdweb logging.<br>
* 4. Added the possibility to use blobs as input files via constructor <code>inputFileBlob data:<JavaScript blob> = InputFile;</code>.<br> * 4. Added the possibility to use blobs as input files via constructor <code>inputFileBlob data:<JavaScript blob> = InputFile;</code>.<br>
* 5. Added the method <code>readFilePart path:string offset:int64 size:int64 = FilePart;</code> and class <code>filePart data:<JavaScript blob> = FilePart;</code><br> * 5. Added the method <code>readFilePart path:string offset:int64 size:int64 = FilePart;</code> and class <code>filePart data:<JavaScript blob> = FilePart;</code><br>
@ -39,11 +39,11 @@ class TdClient {
* @param {TdClient~updateCallback} options.onUpdate - The callback for all incoming updates. * @param {TdClient~updateCallback} options.onUpdate - The callback for all incoming updates.
* @param {string} [options.instanceName=tdlib] - The name of the TDLib instance. Currently only one instance of TdClient with a given name is allowed. All but one created instances with a given name will be automatically closed. Usually, the newest non-background instance is kept alive. Files will be stored in IndexedDb table with the same name. * @param {string} [options.instanceName=tdlib] - The name of the TDLib instance. Currently only one instance of TdClient with a given name is allowed. All but one created instances with a given name will be automatically closed. Usually, the newest non-background instance is kept alive. Files will be stored in IndexedDb table with the same name.
* @param {boolean} [options.isBackground=false] - Pass true, if the instance is opened from the background. * @param {boolean} [options.isBackground=false] - Pass true, if the instance is opened from the background.
* @param {string} [options.jsLogVerbosityLevel='info'] - The initial verbosity level of the JavaScript part of the code (one of 'error', 'warning', 'info', 'log', 'debug'). * @param {string} [options.jsLogVerbosityLevel=info] - The initial verbosity level of the JavaScript part of the code (one of 'error', 'warning', 'info', 'log', 'debug').
* @param {number} [options.logVerbosityLevel=2] - The initial verbosity level for TDLib internal logging (0-1023). * @param {number} [options.logVerbosityLevel=2] - The initial verbosity level for TDLib internal logging (0-1023).
* @param {boolean} [options.useDatabase=true] - Pass false to use TDLib without database and secret chats. It will significantly improve load time, but some functionality will be unavailable. * @param {boolean} [options.useDatabase=true] - Pass false to use TDLib without database and secret chats. It will significantly improve load time, but some functionality will be unavailable.
* @param {string} [options.mode='auto'] - For debug only. The type of the TDLib build to use. 'asmjs' for asm.js and 'wasm' for WebAssembly. If mode == 'auto' WebAbassembly will be used if supported by browser, asm.js otherwise.
* @param {boolean} [options.readOnly=false] - For debug only. Pass true to open TDLib database in read-only mode * @param {boolean} [options.readOnly=false] - For debug only. Pass true to open TDLib database in read-only mode
* @param {string} [options.mode=auto] - For debug only. The type of the TDLib build to use. 'asmjs' for asm.js and 'wasm' for WebAssembly. If mode == 'auto' WebAbassembly will be used if supported by browser, asm.js otherwise.
*/ */
constructor(options) { constructor(options) {
log.setVerbosity(options.jsLogVerbosityLevel); log.setVerbosity(options.jsLogVerbosityLevel);
@ -114,7 +114,7 @@ class TdClient {
'@type': 'error', '@type': 'error',
'@extra': query['@extra'], '@extra': query['@extra'],
code: 400, code: 400,
message: "method '" + query['@type'] + "' is not supported" message: "Method '" + query['@type'] + "' is not supported"
}); });
return; return;
} }
@ -330,7 +330,7 @@ class TdClient {
} }
/** @private */ /** @private */
onUpdate(response) { onUpdate(update) {
log.info('ignore onUpdate'); log.info('ignore onUpdate');
//nop //nop
} }

View File

@ -3,8 +3,6 @@ import log from './logger.js';
import { instantiateAny } from './wasm-utils.js'; import { 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';
// Uncomment for asmjs support
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;
@ -63,8 +61,8 @@ async function initLocalForage() {
localforage.defineDriver(memoryDriver); localforage.defineDriver(memoryDriver);
} }
async function loadTdLibWasm(onFS) { async function loadTdlibWasm(onFS) {
console.log('loadTdLibWasm'); console.log('loadTdlibWasm');
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;
@ -95,9 +93,8 @@ async function loadTdLibWasm(onFS) {
return TdModule; return TdModule;
} }
// Uncomment for asmjs support async function loadTdlibAsmjs(onFS) {
async function loadTdLibAsmjs(onFS) { console.log('loadTdlibAsmjs');
console.log('loadTdLibAsmjs');
let Module = await import('./prebuilt/release/td_asmjs.js'); let Module = await import('./prebuilt/release/td_asmjs.js');
console.log('got td_asm.js'); console.log('got td_asm.js');
let fromFile = 'td_asmjs.js.mem'; let fromFile = 'td_asmjs.js.mem';
@ -125,7 +122,7 @@ async function loadTdLibAsmjs(onFS) {
return TdModule; return TdModule;
} }
async function loadTdLib(mode, onFS) { async function loadTdlib(mode, onFS) {
const wasmSupported = (() => { const wasmSupported = (() => {
try { try {
if ( if (
@ -147,15 +144,15 @@ async function loadTdLib(mode, onFS) {
if (mode === 'wasm') { if (mode === 'wasm') {
log.error('WebAssembly is not supported, trying to use it anyway'); log.error('WebAssembly is not supported, trying to use it anyway');
} else { } else {
log.warning('WebAssembly is not supported, trying to use asmjs'); log.warning('WebAssembly is not supported, trying to use asm.js');
mode = 'asmjs'; mode = 'asmjs';
} }
} }
if (mode === 'asmjs') { if (mode === 'asmjs') {
return loadTdLibAsmjs(onFS); return loadTdlibAsmjs(onFS);
} }
return loadTdLibWasm(onFS); return loadTdlibWasm(onFS);
} }
class OutboundFileSystem { class OutboundFileSystem {
@ -477,7 +474,7 @@ class TdClient {
} }
log.info('load TdModule'); log.info('load TdModule');
this.TdModule = await loadTdLib(mode, self.onFS); this.TdModule = await loadTdlib(mode, self.onFS);
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', []),