connectToPlatform static method
Future<bool>
connectToPlatform({
- required String ip,
- required int port,
- required dynamic notifier(),
- required void onPlatformConnectionChange(),
- required void onPlatformDisconnect(),
- required void onStopCommand({}),
- required String airlineCode,
- required String applicationVersion,
- required String applicationName,
- bool showErrorToast = false,
Implementation
static Future<bool> connectToPlatform(
{required String ip,
required int port,
required Function() notifier,
required void Function(bool) onPlatformConnectionChange,
required void Function() onPlatformDisconnect,
required void Function({required bool canDefer, required Function onForceClose, required Function onDefer}) onStopCommand,
required String airlineCode,
required String applicationVersion,
required String applicationName,
bool showErrorToast = false}) async {
_instance.onPlatformConnectionChange = onPlatformConnectionChange;
_instance.onPlatformDisconnect = onPlatformDisconnect;
_instance.notifier = notifier;
_instance.airline = airlineCode;
_instance.applicationVersion = applicationVersion;
_instance.applicationName = applicationName;
_instance.onStopCommand = onStopCommand;
try {
_instance.socketService = SocketService(ip: ip, port: port);
bool? connection = await _instance.socketService.initialize(
onLost: onPlatformDisconnect,
// ip: ip,
// port: port,
rh: cuppsResponseHandler,
onClose: onPlatformClose,
logID: 'Platform',
logSuff: 'Platform');
log("Platform Socket Connection $connection");
_instance.onPlatformConnectionChange!(connection);
generateToken();
return connection;
} catch (e) {
if (showErrorToast) {
Get.snackbar("Platform Connection Error", e.toString());
} else {
log("Platform Connection Error:\n $e");
}
_instance.onPlatformConnectionChange!(false);
return false;
}
}