Service constructor

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

Implementation

Service(
    {
    // Parameters for native lib loader
    String? dir,
    String? file,
    // Parameters for handleing client
    this.timeout = 10,
    this.maxExtra = 10000000,

    /// start the recevie stream loop, default is true, set it to false if you want start it later
    start = true,
    // Parameters for td api
    required Map<String, dynamic> tdlibParameters,
    this.encryptionKey = "",
    this.newVerbosityLevel = 1,
    // Event handlers
    this.beforeSend,
    this.afterReceive,
    this.beforeExecute,
    this.afterExecute,
    this.onReceiveError,
    this.onStreamError}) {
  // 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");
  }
  tdlibParameters['@type'] = 'tdlibParameters';
  this.tdlibParameters = tdlibParameters;
  if (maxExtra < 10000) {
    throw ArgumentError(
        "To prevent infinity generating @extra, don't set maxExtra less than 10000");
  }
  _dir = dir;
  _file = file;
  _client = Client(dir: _dir, file: _file);
  if (start) {
    this.start();
  }
}