close method

Future<int> close()

Closes the SDK session and all open device handles.

Returns SktErrors.ESKT_NOERROR. Safe to call when not open (no-op).

Implementation

Future<int> close() async {
  if (_capture == null) {
    return SktErrors.ESKT_NOERROR;
  }

  for (final CaptureHelperDevice device in _devices.values) {
    try {
      await device.devCapture.close();
    } catch (_) {
      // Ignore errors on device close; proceed with teardown
    }
  }

  if (_bleDeviceManager != null) {
    try {
      await _bleDeviceManager!.close();
    } catch (_) {}
    _bleDeviceManager = null;
  }

  if (Platform.isAndroid) {
    await CapturePlugin.stopSocketCamExtension();
    await CapturePlugin.cancelSubscription();
  }

  await _capture!.close();

  _bleIdentifiers.clear();
  _pendingIdentifierUuid = null;
  _devices.clear();
  _capture = null;
  _bufferedEvents.clear();
  _clearCallbacks();

  return SktErrors.ESKT_NOERROR;
}