TdlibBase constructor

TdlibBase({
  1. String? pathTdl,
  2. TelegramClientLibraryTdlibOptionParameter? clientOption,
  3. int taskMaxCount = 10000,
  4. int taskMinCooldown = 10,
  5. String event_invoke = "invoke",
  6. String event_update = "update",
  7. EventEmitter? eventEmitter,
  8. Duration? delayUpdate,
  9. double timeOutUpdate = 1.0,
  10. Duration? delayInvoke,
  11. Duration? invokeTimeOut,
  12. bool isAutoGetChat = false,
  13. bool isInvokeThrowOnError = true,
  14. TdlibOnGenerateExtraInvoke? onGenerateExtraInvoke,
  15. TdlibOnGetInvokeData? onGetInvokeData,
  16. TdlibOnReceiveUpdate? onReceiveUpdate,
})

TelegramClientUncompleDocumentation

Implementation

TdlibBase({
  String? pathTdl,
  TelegramClientLibraryTdlibOptionParameter? clientOption,
  this.taskMaxCount = 10000,
  this.taskMinCooldown = 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.onGenerateExtraInvoke,
  this.onGetInvokeData,
  this.onReceiveUpdate,
}) : eventEmitter = eventEmitter ?? EventEmitter() {
  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 (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;
    }
    final onReceiveUpdate = this.onReceiveUpdate;
    if (onReceiveUpdate != null) {
      await onReceiveUpdate(update, this);
    } else if (update is TdlibIsolateReceiveData) {
      TdlibIsolateReceiveData tdlibIsolateReceiveData = update;
      try {
        if (tdlibIsolateReceiveData.updateData["@extra"] is String) {
          this.eventEmitter.emit(
                eventName: event_invoke,
                value: tdlibIsolateReceiveData,
              );
        } else {
          this.eventEmitter.emit(
                eventName: event_update,
                value: tdlibIsolateReceiveData,
              );
        }
      } catch (e) {
        this.eventEmitter.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;
  }
}