Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated jnLibs to latest v1.8.33 #29

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 117 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
# tdlib-dart

A Dart wrapper for [tdlib](https://github.com/tdlib/td). Contains generated schema classes of [td_api.tl](https://github.com/tdlib/td/blob/master/td/generate/scheme/td_api.tl) and a client that interacts with lib through [ffi](https://dart.dev/guides/libraries/c-interop).

| Version | tdlib commit | td_api.tl revision |
|---------|:-------------------------------------------------------------:|-----------------------------------------------------------------------------------:|
| 1.8.29 | last commit | [44b548c](https://github.com/tdlib/td/blob/44b548c/td/generate/scheme/td_api.tl) |
| 1.8.26 | [d7a31ad](https://github.com/ivk1800/tdlib-dart/tree/d7a31ad) | [b1b33cf](https://github.com/tdlib/td/blob/b1b33cf/td/generate/scheme/td_api.tl) |
| 1.8.21 | [32d37d9](https://github.com/ivk1800/tdlib-dart/tree/32d37d9) | [404761c](https://github.com/tdlib/td/blob/404761c/td/generate/scheme/td_api.tl) |
| 1.8.19 | [1a00bae](https://github.com/ivk1800/tdlib-dart/tree/1a00bae) | [986f1ab](https://github.com/tdlib/td/blob/986f1ab/td/generate/scheme/td_api.tl) |
| 1.8.18 | [532fae5](https://github.com/ivk1800/tdlib-dart/tree/532fae5) | [daf4801](https://github.com/tdlib/td/blob/daf4801/td/generate/scheme/td_api.tl) |
| 1.8.15 | [3f91948](https://github.com/ivk1800/tdlib-dart/tree/3f91948) | [8893dc8](https://github.com/tdlib/td/blob/8893dc8/td/generate/scheme/td_api.tl) |
| 1.8.14 | [90171aa](https://github.com/ivk1800/tdlib-dart/tree/90171aa) | [4041ecb](https://github.com/tdlib/td/blob/4041ecb/td/generate/scheme/td_api.tl) |
| 1.8.13 | [d5ed66a](https://github.com/ivk1800/tdlib-dart/tree/d5ed66a) | [c95598e](https://github.com/tdlib/td/blob/c95598e/td/generate/scheme/td_api.tl) |
| 1.8.11 | [1b99276](https://github.com/ivk1800/tdlib-dart/tree/1b99276) | [1543c41](https://github.com/tdlib/td/blob/1543c41/td/generate/scheme/td_api.tl) |
| 1.8.9 | [5b8706c](https://github.com/ivk1800/tdlib-dart/tree/5b8706c) | [6cbe182](https://github.com/tdlib/td/blob/6cbe182/td/generate/scheme/td_api.tl) |
| 1.8.8 | [f069453](https://github.com/ivk1800/tdlib-dart/tree/f069453) | [bbe37ee](https://github.com/tdlib/td/blob/bbe37ee/td/generate/scheme/td_api.tl) |
| 1.8.7 | [60c2975](https://github.com/ivk1800/tdlib-dart/tree/60c2975) | [92f8093](https://github.com/tdlib/td/blob/92f8093/td/generate/scheme/td_api.tl) |
| 1.8.4 | [324fa2b](https://github.com/ivk1800/tdlib-dart/tree/324fa2b) | [d489014](https://github.com/tdlib/td/blob/d489014/td/generate/scheme/td_api.tl) |
| 1.8.0 | [781d969](https://github.com/ivk1800/tdlib-dart/tree/781d969) | [c0385078](https://github.com/tdlib/td/blob/c0385078/td/generate/scheme/td_api.tl) |
| 1.7.9 | [2dec79f](https://github.com/ivk1800/tdlib-dart/tree/2dec79f) | [8d7bda00](https://github.com/tdlib/td/blob/8d7bda00/td/generate/scheme/td_api.tl) |
| 1.7.3 | [2a29b25](https://github.com/ivk1800/tdlib-dart/tree/2a29b25) | - |
# tdlib-dart fork of ivk1800/tdlib

### Table of Contents

Expand All @@ -33,9 +12,11 @@ A Dart wrapper for [tdlib](https://github.com/tdlib/td). Contains generated sche
- [Web](#web)

### Integration example

As an example of use, you can see the project [telegram-flutter](https://github.com/ivk1800/telegram-flutter).

### Example
### Dart Example

```dart
import 'package:tdlib/td_client.dart';
import 'package:tdlib/td_api.dart' as td;
Expand All @@ -56,25 +37,102 @@ Future<void> main() async {
}
```

### installation

add the following code to your dependencies section in pubspec.yaml

```yaml
dependencies:
tdlib:
git:
url: "https://github.com/stellarNuke/tdlib-dart"
ref: master
```

### Getting started with flutter example

1. Obtain `api_id` and `api_hash` at https://my.telegram.org
2. Build tdlib for your operating system following the [instruction](https://github.com/tdlib/td#building) or download [prebuild](https://github.com/ivk1800/td-json-client-prebuilt/releases) binaries. Following the instraction below for setup tdlib.
3. Open `example/lib/main.dart` and place obtained `api_id` and `api_hash` to appropriate methods `getApiId` and `getApiHash`.
4. Specify phone number and code in `getPhoneNumber` and `getCode` methods. Attention, the phone number must be specified from the test DC. If you don't want to use the test DC and want to authenticate with your account, change `useTestDc` to `false` in `TdlibParameters`.
5. cd `<repo folder>/example`
6. `flutter run`
2. Build tdlib for your operating system following the [instruction](https://github.com/tdlib/td#building) or download ~~[prebuild](https://github.com/ivk1800/td-json-client-prebuilt/releases)~~
for android downnload from here => [ v1.8.31 releases](https://github.com/stellarNuke/tdlib-dart/releases/tag/v1.8.31)
binaries.
3. place the files in the desired platforms folder instructions below
4. import package

```dart
import 'package:tdlib/td_client.dart';
import 'package:tdlib/td_api.dart' as td;
```

5. create and initialize client

```dart
late final Client client;
client = Client.create();
await client.initialize();
```

6. listen for updates received from the client
list of [All available update states](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_update.html)

```dart
client.updates.listen((tda.TdObject event) async {
print('[EVENT] : ${event.toJson()}');
var eventType = event.toJson()['@type'];

if (eventType == 'updateAuthorizationState') {
tda.UpdateAuthorizationState update = event as tda.UpdateAuthorizationState;
tda.AuthorizationState authorizationState = update.authorizationState;

//handle on different authorization states sent as update

}
}, onError: (object) => {print(object.toString())}, cancelOnError: false, onDone: () => {print('[===========DONE LISTENING=========]')});
```

**Note : The first authorization state received by the Application is always of the type authorizationStateWaitTdlibParameters. When it is received, the Application must provide parameters for TDLib initialization by calling the setTdlibParameters API method as mentioned below.**

7. use an API method to send requests.
[All available methods](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html)

```dart
var params = tda.SetTdlibParameters(
apiHash: apiHash,
apiId: int.parse(apikey),
systemLanguageCode: 'en-US',
deviceModel: 'device model',
systemVersion: 'systemversion',
applicationVersion: 'v1',
useTestDc: false,
databaseDirectory: 'path',
filesDirectory: 'path',
databaseEncryptionKey: 'testkey',
useFileDatabase: true,
useChatInfoDatabase: true,
useMessageDatabase: true,
useSecretChats: false,
);
await client.send(params)

```

**_ Note : After call to `setTdlibParameters` in case of success Application will receive `updateAuthorizationState` with new state and just needs to handle that update.If user isn't authorized yet, then some of `authorizationStateWaitPhoneNumber, authorizationStateWaitEmailAddress, authorizationStateWaitEmailCode, authorizationStateWaitCode, authorizationStateWaitRegistration` and `authorizationStateWaitPassword `authorization states may be received. After completing these authorization steps, the Application will receive authorizationStateReady, meaning that authorization was successful and ordinary requests can be sent now. _**

for more info go [official tdlib getting started](https://core.telegram.org/tdlib/getting-started)

### Prebuilt binaries
The tdlib binaries is built automatically using github actions and published on the [releases page](https://github.com/ivk1800/td-json-client-prebuilt/releases/). Follow the instructions below for each platform to configure flutter project to use tdlib

The tdlib binaries is built automatically using github actions and published on the [releases page](https://github.com/ivk1800/td-json-client-prebuilt/releases/). For android downnload from here => [ v1.8.31 releases](https://github.com/stellarNuke/tdlib-dart/releases/tag/v1.8.31). Follow the instructions below for each platform to configure flutter project to use tdlib

### Android

Copy `.so` files from archive to `example/android/app/main/jniLibs`:

```
└── example
└── android
└── app
└── main
└── jniLibs
└── example
└── android
└── app
└── main
└── jniLibs
└── arm64-v8a
│ └── libtdjsonandroid.so
└── armeabi-v7a
Expand All @@ -84,15 +142,19 @@ Copy `.so` files from archive to `example/android/app/main/jniLibs`:
└── x86_64
└── libtdjsonandroid.so
```

13. Open file `example/android/app/build.gradle`

replace

```groovy
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
```
by

by

```groovy
sourceSets {
main {
Expand All @@ -103,15 +165,18 @@ sourceSets {
```

### iOS and macOS

1. Copy `libtdjson.dylib` from archive to `example/ios`
2. Copy `libtdjson.dylib` from archive to `example/macos`

```
└── example
└── ios
└── example
└── ios
│ └── libtdjson.dylib
└── macos
└── libtdjson.dylib
```

3. Open `Runner.xcworkspace` in Xcode.
4. Add `.dylib` file to project.
5. Find `Frameworks, Libraries, and EmbeddedContent`.
Expand All @@ -120,18 +185,22 @@ sourceSets {
8. In Section `App Sandbox (Debug and Profile)` set true `Outgoing Connections (Client)`.

### Windows

1. Copy files from archive to `example/windows/tdlib`

```
└── example
└── windows
└── tdlib
└── example
└── windows
└── tdlib
└── libcrypto-1_1.dll
└── libssl-1_1.dll
└── tdjson.dll
└── zlib1.dll
```

2. Open `example/windows/CMakeLists.txt`.
3. Add below line `set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")`:

```
# begin td
set(dll_path "${CMAKE_CURRENT_SOURCE_DIR}/tdlib")
Expand All @@ -143,15 +212,19 @@ install(FILES "${dll_path}/zlib1.dll" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" CO
```

### Linux

1. Copy file from archive to `example/linux/tdlib`

```
└── example
└── linux
└── tdlib
└── example
└── linux
└── tdlib
└── libtdjson.so
```

2. Open `example/linux/CMakeLists.txt`.
3. Add at the end of file:

```
# begin td
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/tdlib/libtdjson.so" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
Expand All @@ -160,4 +233,5 @@ install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/tdlib/libtdjson.so" DESTINATION "${IN
```

### Web

TBD
51 changes: 0 additions & 51 deletions example/.gitignore

This file was deleted.

Loading