Skip to content

Commit

Permalink
Experimental support for new tdjson interface
Browse files Browse the repository at this point in the history
- Added `useNewTdjsonInterface` experimental option to `tdl.configure`.
- The Client is changed to allow managing through another entity that
  can pass receive() results to the client and gets notified when the
  client is closed.
- Added `receiveTimeout` option to `tdl.configure`.
- `receiveTimeout` in the `createClient` options is deprecated (works
  with the old interface only). The option is very rarely used.
- The deprecated pause/resume do not work with the new interface.

The old interface still seems to work fine (modulo the fact that tdl
reuses the main libuv threadpool for clients) and the implementation is
somewhat simpler since the clients are independent.
  • Loading branch information
eilvelia committed Oct 4, 2023
1 parent 87fa627 commit 871d8d8
Show file tree
Hide file tree
Showing 11 changed files with 498 additions and 126 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

<!-- Hi! -->

## tdl (unreleased)
## tdl@7.4.0 (unreleased)

- Added `tdl.setLogMessageCallback` that allows to pass a callback to the
`td_set_log_message_callback` TDLib function using Node-API's thread-safe
functions. (TDLib v1.8.0+ only)
- `tdl.configure`: Added an experimental option `useNewTdjsonInterface` that
enables the use of `td_create_client_id`/`td_send`/`td_receive`/`td_execute`
interface with a client manager and global receive loop, though the old
interface still works well.
This does not use the libuv threadpool and does not have a limitation of max
`UV_THREADPOOL_SIZE` clients.
(TDLib v1.7.0+ only)
- `tdl.configure`: Added a `receiveTimeout` advanced option.
- `receiveTimeout` in the client options is deprecated.
- Deprecated the `useMutableRename` advanced option.

## [email protected] (2023-09-26)
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TDLib version 1.5.0 or newer is required.
- The tdjson shared library (`libtdjson.so` on Linux, `libtdjson.dylib` on macOS, `tdjson.dll` on Windows)
- In some cases, a C++ compiler and Python installed to build the node addon[^1]

[^1]: `tdl` is packaged with pre-built addons for Windows (x86_64), GNU/Linux (x86_64, glibc >= 2.17), and macOS (x86_64, aarch64). If a pre-built binary is not available for your system, then the node addon will be built using node-gyp, requiring Python and a C++ toolchain to be installed (on Windows, MSVS or Build Tools). Pass `--build-from-source` to never use the pre-built binaries. Note that macOS aarch64 binaries aren't tested.
[^1]: `tdl` is packaged with pre-built addons for Windows (x86_64), GNU/Linux (x86_64, glibc >= 2.17), and macOS (x86_64, aarch64). If a pre-built binary is not available for your system, then the node addon will be built using node-gyp, requiring Python and a C++ toolchain (C++14 is required) to be installed (on Windows, MSVS or Build Tools). Pass `--build-from-source` to never use the pre-built binaries. Note that macOS aarch64 binaries aren't tested.

<a name="installation"></a>
## Installation
Expand Down Expand Up @@ -57,7 +57,7 @@ const tdl = require('tdl')

// If libtdjson is not present in the system search paths, the path to the
// libtdjson shared library can be set manually, e.g.:
// tdl.configure({ tdjson: '/usr/local/lib/libtdjson.dylib'})
// tdl.configure({ tdjson: '/usr/local/lib/libtdjson.dylib' })
// The library prefix can be set separate from the library name,
// example to search for libtdjson in the directory of the current script:
// tdl.configure({ libdir: __dirname })
Expand Down Expand Up @@ -145,9 +145,11 @@ tdl.configure({
// 'libtdjson.dylib' on macOS, or 'libtdjson.so' otherwise.
tdjson: 'libtdjson.so',
// Path to the library directory. By default, it is empty string.
libdir: '...',
libdir: '/usr/local/lib',
// Verbosity level of TDLib. By default, it is 2.
verbosityLevel: 3
verbosityLevel: 3,
// Experimental option. Defaults to false.
useNewTdjsonInterface: false
})
```

Expand All @@ -158,8 +160,8 @@ Some examples:
- `tdl.configure({ tdjson: require('prebuilt-tdlib').getTdjson() })`

The path concatenation of `libdir` + `tdjson` is directly passed to
[`dlopen`][dlopen] (Unix) or [`LoadLibrary`][LoadLibraryW] (Windows). Check your OS documentation
to find out where the shared library will be searched for.
[`dlopen`][dlopen] (Unix) or [`LoadLibrary`][LoadLibraryW] (Windows). Check your
OS documentation to find out where the shared library will be searched for.

#### `tdl.createClient(options: ClientOptions) => Client`

Expand All @@ -185,9 +187,8 @@ type ClientOptions = {
useTestDc: boolean, // Use test telegram server (defaults to false)
tdlibParameters: Object, // Raw TDLib parameters
// Advanced options:
skipOldUpdates: boolean,
bare: boolean,
receiveTimeout: number
skipOldUpdates: boolean
}
```
Expand Down Expand Up @@ -421,6 +422,9 @@ globally or per-project as a dev dependency.
The current limitation is that the number of created clients should not exceed
[UV_THREADPOOL_SIZE][] (as for now, the default is 4, max is 1024).

When `useNewTdjsonInterface` (experimental option) is set to true in
`tdl.configure`, this limitation does not apply.

[UV_THREADPOOL_SIZE]: http://docs.libuv.org/en/v1.x/threadpool.html

<a name="possible-errors"></a>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "eslint . --max-warnings 0",
"jest-tests": "jest --testPathIgnorePatterns tests/integration",
"test": "npm run flow:check && npm run ts:check && npm run lint && npm run jest-tests",
"integration-tests": "jest tests/integration && cross-env TEST_TDL_TDLIB_ADDON=1 jest tests/integration",
"integration-tests": "jest tests/integration && cross-env TEST_TDL_TDLIB_ADDON=1 jest tests/integration && cross-env TEST_NEW_TDJSON=1 jest tests/integration",
"test:all": "npm run test && npm run integration-tests",
"coverage": "jest --coverage",
"prepare": "npm run clean && npm run build",
Expand Down
Loading

0 comments on commit 871d8d8

Please sign in to comment.