-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathtd_eg.dart
54 lines (38 loc) · 1006 Bytes
/
td_eg.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
library TDLib;
import 'dart:ffi' as ffi;
import 'package:ffi/ffi.dart';
import 'dart:convert';
import 'bindings/bindings.dart';
ffi.Pointer client = td_json.client_create();
Object td_execute(Object query) {
return json.decode(
Utf8.fromUtf8(td_json.client_execute(
client,
Utf8.toUtf8(json.encode(query))
))
);
}
void td_send(Object query) {
td_json.client_send(
client,
Utf8.toUtf8(json.encode(query))
);
}
Object td_receive() {
dynamic result = td_json.client_receive(client, 1.0);
if (result != null) {
result = json.decode(Utf8.fromUtf8(result));
}
return result;
}
void main() {
td_json.client_destroy(client);
client = td_json.client_create();
print(td_execute({'@type': 'setLogVerbosityLevel', 'new_verbosity_level': 4, '@extra': 1.01234}));
while (true) {
td_send({'@type': 'getAuthorizationState', '@extra': 1.01234});
var event = td_receive();
print(json.encode(event));
}
td_json.client_destroy(client);
}