Comparing version 7.4.0-rc.0 to 7.4.0
@@ -337,2 +337,8 @@ "use strict"; | ||
}; | ||
/** @deprecated */ | ||
destroy = () => { | ||
debug('destroy'); | ||
// Force close | ||
this._handleClose(); | ||
}; | ||
_waitResume() { | ||
@@ -378,16 +384,15 @@ return new Promise(resolve => { | ||
}; | ||
destroy = () => { | ||
debug('destroy'); | ||
_handleClose() { | ||
if (this._tdn) { | ||
this._onClose(); | ||
this._clientId = -1; | ||
this.emit('destroy'); | ||
return; | ||
} else { | ||
if (this._client === null) return; | ||
this._tdlib.destroy(this._client); | ||
this._client = null; | ||
this.resume(); | ||
} | ||
if (this._client === null) return; | ||
this._tdlib.destroy(this._client); | ||
this._client = null; | ||
this.resume(); | ||
this.emit('destroy'); | ||
}; | ||
debug('closed'); | ||
this.emit('destroy'); // TODO: rename to closed? | ||
} | ||
@@ -412,14 +417,12 @@ // Sends { _: 'close' } and waits until the client gets destroyed | ||
// tdl renames '@type' to '_'. | ||
// Initially it was because Flow didn't support disjoint unions | ||
// if the tag is referenced via square brackets. | ||
// tdl renames '@type' to '_'. Initially, it was because Flow didn't support | ||
// disjoint unions if the tag is referenced via square brackets. | ||
// (https://flow.org/en/docs/lang/refinements/) | ||
// It was fixed, but I kept the renaming, since it's more convenient | ||
// to write if (o._ === '...') instead of if (o['@type'] === '...') | ||
// It was fixed, but the renaming was kept, since it's more convenient | ||
// to write `if (o._ === '...')` instead of `if (o['@type'] === '...')` | ||
execute = request => { | ||
debugReq('execute', request); | ||
const tdRequest = (0, _util.deepRenameKey)('_', '@type', request); | ||
if (this._tdn) { | ||
const tdRequest = (0, _util.deepRenameKey)('_', '@type', request); | ||
// the client can be null, it's fine | ||
const tdResponse = this._tdlib.tdn.execute(JSON.stringify(tdRequest)); | ||
@@ -429,3 +432,2 @@ if (tdResponse == null) return null; | ||
} | ||
const tdRequest = (0, _util.deepRenameKey)('_', '@type', request); | ||
// the client can be null, it's fine | ||
@@ -549,3 +551,8 @@ const tdResponse = this._tdlib.execute(this._client, tdRequest); | ||
this.emit('update', update); | ||
this._handleAuth(update).catch(e => this._catchError(new TdlError(e))); | ||
if (update.authorization_state._ === 'authorizationStateClosed') { | ||
this._loginDefer.reject(Error('Received authorizationStateClosed')); | ||
this._handleClose(); | ||
} else if (!this._options.bare) { | ||
this._handleAuth(update).catch(e => this._catchError(new TdlError(e))); | ||
} | ||
return; | ||
@@ -560,8 +567,2 @@ default: | ||
const authorizationState = update.authorization_state; | ||
if (authorizationState._ === 'authorizationStateClosed') { | ||
this._loginDefer.reject(Error('Received authorizationStateClosed')); | ||
this.destroy(); | ||
return; | ||
} | ||
if (this._options.bare) return; | ||
switch (authorizationState._) { | ||
@@ -568,0 +569,0 @@ case 'authorizationStateWaitTdlibParameters': |
{ | ||
"name": "tdl", | ||
"version": "7.4.0-rc.0", | ||
"version": "7.4.0", | ||
"description": "Node.js bindings to TDLib (Telegram Database library)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -61,3 +61,3 @@ # tdl [](https://www.npmjs.com/package/tdl) [](https://github.com/Bannerets/tdl/actions/workflows/ci.yml) | ||
// tdl.configure({ tdjson: '/usr/local/lib/libtdjson.dylib' }) | ||
// The library prefix can be set separate from the library name, | ||
// The library directory can be set separate from the library name, | ||
// example to search for libtdjson in the directory of the current script: | ||
@@ -85,4 +85,4 @@ // tdl.configure({ libdir: __dirname }) | ||
async function main () { | ||
// Log in to a Telegram account. By default, with no arguments, this function will ask | ||
// for phone number etc. in the console. Instead of logging in as a normal user, | ||
// Log in to a Telegram account. By default, with no arguments, this function will | ||
// ask for phone number etc. in the console. Instead of logging in as a user, | ||
// it's also possible to log in as a bot using `client.loginAsBot('<TOKEN>')`. | ||
@@ -115,3 +115,3 @@ await client.login() | ||
[td_api.tl]: https://github.com/tdlib/td/blob/66234ae2537a99ec0eaf7b0857245a6e5c2d2bc9/td/generate/scheme/td_api.tl | ||
[td_api.tl]: https://github.com/tdlib/td/blob/2589c3fd46925f5d57e4ec79233cd1bd0f5d0c09/td/generate/scheme/td_api.tl | ||
@@ -130,3 +130,3 @@ In the TDLib documentation, the `bytes` type means a **base64-encoded** string. | ||
<!-- TODO: Add a guide on how to read the tl scheme or similar? --> | ||
<!-- TODO: Add a guide on how to read the tl schema or similar? --> | ||
@@ -296,3 +296,3 @@ Some short examples are available in the [examples/](examples/) directory. | ||
Attach an event listener to receive updates. | ||
Attach an event listener to receive updates and other events. | ||
@@ -310,5 +310,7 @@ ```javascript | ||
You can consider using reactive libraries like RxJS or most.js for convenient event processing. | ||
You can consider using reactive libraries like RxJS or most.js for convenient | ||
event processing. | ||
Some other rarely-used events also exist and are described in the TypeScript interface. | ||
Some other rarely-used events also exist and are described in the TypeScript | ||
interface. | ||
@@ -326,5 +328,6 @@ `client.addListener` is an alias for `client.on`. | ||
```javascript | ||
const listener = v => { | ||
console.log('New update:', v) | ||
client.off('update', listener) // Removes the listener | ||
const listener = u => { | ||
console.log('New update:', u) | ||
if (u?.authorization_state?._ === 'authorizationStateReady') | ||
client.off('update', listener) // Removes the listener | ||
} | ||
@@ -366,2 +369,10 @@ client.on('update', listener) | ||
#### `client.close() => Promise<void>` | ||
Close the TDLib client. | ||
```javascript | ||
await client.close() | ||
``` | ||
#### `tdl.execute(query: Object) => (Object | null)` | ||
@@ -379,18 +390,9 @@ | ||
#### `client.execute(query: Object) => (Object | null)` | ||
`client.execute` is the same as `tdl.execute`. | ||
Same as `tdl.execute`. | ||
#### `tdl.setLogMessageCallback(maxVerbosityLevel: number, cb: Function | null) => void` | ||
#### `client.close() => Promise<void>` | ||
Set the callback that is called when a message is added to the TDLib log. This | ||
corresponds to the `td_set_log_message_callback` tdjson function. | ||
Close the TDLib client. | ||
```javascript | ||
await client.close() | ||
``` | ||
--- | ||
For the full API, see the [index.d.ts](packages/tdl/index.d.ts) file. | ||
<a name="types"></a> | ||
@@ -434,3 +436,6 @@ ## Types | ||
[deno][] is not yet supported. | ||
[deno][] can also import `tdl` through the node compatibility via | ||
`import * as tdl from 'npm:tdl'`. Currently, the Node-API implementation in deno | ||
seems to be unstable and random segfaults sometimes occur. Not recommended to | ||
use `tdl` in deno. | ||
@@ -479,3 +484,3 @@ [bun]: https://bun.sh/ | ||
You can get this error if libtdjson is dynamically linked against OpenSSL and | ||
some of the symbols got resolved to Node.js instead of the system OpenSSL. | ||
some of the symbols got resolved into Node.js instead of the system OpenSSL. | ||
@@ -482,0 +487,0 @@ Note that Node.js also uses OpenSSL (the distributed binaries are statically |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
546751
1351
0
536