Service constructor
Service({
- String? dir,
- String? file,
- double timeout = 10,
- int maxExtra = 10000000,
- int? newVerbosityLevel,
- required Map<
String, dynamic> tdlibParameters, - void onStreamError(
- dynamic
- void onReceive()?,
- void onReceiveError()?,
- void afterReceive()?,
- void beforeSend()?,
- void beforeExecute()?,
- void afterExecute()?,
- 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();
}
}