Service constructor

Service({
  1. String? dir,
  2. String? file,
  3. double timeout = 10,
  4. int maxExtra = 10000000,
  5. int? newVerbosityLevel,
  6. required Map<String, dynamic> tdlibParameters,
  7. void onStreamError(
    1. dynamic
    )?,
  8. void onReceive(
    1. String
    )?,
  9. void onReceiveError(
    1. Error
    )?,
  10. void afterReceive(
    1. Map<String, dynamic>
    )?,
  11. void beforeSend(
    1. Map<String, dynamic>
    )?,
  12. void beforeExecute(
    1. Map<String, dynamic>
    )?,
  13. void afterExecute(
    1. Map<String, dynamic>
    )?,
  14. dynamic start = true,
})

Implementation

Service({
  // Parameters for native lib loader
  super.dir,
  super.file,
  // Parameters for handling client
  super.timeout = 10,
  this.maxExtra = 10000000,
  // Parameters for td api
  super.newVerbosityLevel,
  required Map<String, dynamic> tdlibParameters,

  // Event handlers
  super.onStreamError,
  super.onReceive,
  this.onReceiveError,
  this.afterReceive,
  this.beforeSend,
  this.beforeExecute,
  this.afterExecute,

  /// start the receive stream loop, default is true, set it to false if you want start it later
  start = true,
}) {
  // Check those 5 required parameters before loading json client
  if (!tdlibParameters.containsKey('api_id')) {
    throw ArgumentError("tdlibParameters['api_id'] must be set");
  }
  if (!tdlibParameters.containsKey('api_hash')) {
    throw ArgumentError("tdlibParameters['api_hash'] must be set");
  }
  if (!tdlibParameters.containsKey('system_language_code')) {
    tdlibParameters['system_language_code'] = Platform.localeName;
  }
  if (!tdlibParameters.containsKey('application_version')) {
    tdlibParameters['application_version'] = "0.0.1";
  }
  if (!tdlibParameters.containsKey('device_model')) {
    throw ArgumentError("tdlibParameters['device_model'] must be set");
  }
  this.tdlibParameters = tdlibParameters;
  if (maxExtra < 10000) {
    throw ArgumentError(
        "To prevent infinity generating @extra, don't set maxExtra less than 10000");
  }
  _client = Client(dir: dir, file: file);
  if (start) {
    super.start();
  }
}