TdlibBase constructor
TdlibBase({
- String? pathTdl,
- TelegramClientLibraryTdlibOptionParameter? clientOption,
- int task_max_count = 10000,
- int task_min_cooldown = 10,
- String event_invoke = "invoke",
- String event_update = "update",
- EventEmitter? eventEmitter,
- Duration? delayUpdate,
- double timeOutUpdate = 1.0,
- Duration? delayInvoke,
- Duration? invokeTimeOut,
- bool isAutoGetChat = false,
- bool isInvokeThrowOnError = true,
- FutureOr<
String> on_generate_extra_invoke()?, - FutureOr<
Map> on_get_invoke_data()?, - FutureOr<
void> on_receive_update(- dynamic update,
- TdlibBase libTdJson
Implementation
TdlibBase({
String? pathTdl,
TelegramClientLibraryTdlibOptionParameter? clientOption,
this.task_max_count = 10000,
this.task_min_cooldown = 10,
this.event_invoke = "invoke",
this.event_update = "update",
EventEmitter? eventEmitter,
Duration? delayUpdate,
this.timeOutUpdate = 1.0,
Duration? delayInvoke,
Duration? invokeTimeOut,
bool isAutoGetChat = false,
bool isInvokeThrowOnError = true,
this.on_generate_extra_invoke,
this.on_get_invoke_data,
this.on_receive_update,
}) {
if (delayInvoke != null) {
delay_invoke = delayInvoke;
}
delay_update = delayUpdate;
is_invoke_throw_on_error = isInvokeThrowOnError;
pathTdl ??= "libtdjson.${getFormatLibrary}";
path_tdlib = pathTdl;
// opentdLib(pathTdlib: path_tdlib);
is_auto_get_chat = isAutoGetChat;
invokeTimeOut ??= Duration(minutes: 5);
invoke_time_out = invokeTimeOut;
if (eventEmitter != null) {
event_emitter = eventEmitter;
} else {
event_emitter = EventEmitter();
}
if (clientOption != null) {
client_option.rawData.addAll(clientOption.rawData);
}
client_option.rawData.remove("@type");
receivePort.listen((update) async {
if (update is SendPort) {
// sendPort = update;
// is_init_send_port = true;
return;
}
if (on_receive_update != null) {
await on_receive_update!(update, this);
} else if (update is TdlibIsolateReceiveData) {
TdlibIsolateReceiveData tdlibIsolateReceiveData = update;
try {
if (tdlibIsolateReceiveData.updateData["@extra"] is String) {
event_emitter.emit(
eventName: event_invoke, value: tdlibIsolateReceiveData);
} else {
event_emitter.emit(
eventName: event_update, value: tdlibIsolateReceiveData);
}
} catch (e) {
event_emitter.emit(
eventName: event_update, value: tdlibIsolateReceiveData);
}
} else if (update is TdlibIsolateReceiveDataError) {
is_init_isolate = false;
isolate.kill();
await ensureInitialized();
}
});
if (client_option['new_verbosity_level'] is int == false) {
client_option['new_verbosity_level'] = 0;
}
}