TdlibBase constructor

TdlibBase({
  1. String? pathTdl,
  2. TelegramClientLibraryTdlibOptionParameter? clientOption,
  3. int task_max_count = 10000,
  4. int task_min_cooldown = 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. FutureOr<String> on_generate_extra_invoke(
    1. int client_id,
    2. TdlibBase libTdJson
    )?,
  15. FutureOr<Map> on_get_invoke_data(
    1. String extra,
    2. int client_id,
    3. TdlibBase libTdJson
    )?,
  16. FutureOr<void> on_receive_update(
    1. dynamic update,
    2. 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;
  }
}