open method
Future<int>
open(
- AppInfo appInfo, {
- void onDeviceArrival()?,
- void onDeviceRemoval()?,
- void onDecodedData()?,
- void onError()?,
- void onBatteryLevel()?,
- void onPowerState()?,
- void onButtons()?,
- void onSocketCamCanceled()?,
- void onDiscoveredDevice()?,
- void onDiscoveryEnd()?,
- void onLogTrace()?,
Opens an SDK session using the provided appInfo.
All callbacks are optional named parameters. Events arriving before
openClient returns are buffered and replayed in order after open
completes.
Throws CaptureException with SktErrors.ESKT_ALREADYDONE if called while already open. Throws CaptureException on connection failure.
Implementation
Future<int> open(
AppInfo appInfo, {
void Function(CaptureHelperDevice)? onDeviceArrival,
void Function(CaptureHelperDevice)? onDeviceRemoval,
void Function(DecodedData, CaptureHelperDevice)? onDecodedData,
void Function(CaptureException)? onError,
// Phase 2 callbacks (stored but not yet routed)
void Function(int, CaptureHelperDevice)? onBatteryLevel,
void Function(int, CaptureHelperDevice)? onPowerState,
void Function(int, CaptureHelperDevice)? onButtons,
void Function(CaptureHelperDevice)? onSocketCamCanceled,
void Function(DiscoveredDeviceInfo)? onDiscoveredDevice,
void Function(int)? onDiscoveryEnd,
void Function(String)? onLogTrace,
}) async {
if (_capture != null) {
throw CaptureException(
SktErrors.ESKT_ALREADYDONE,
'CaptureHelper is already open. Call close() before opening again.',
);
}
_onDeviceArrival = onDeviceArrival;
_onDeviceRemoval = onDeviceRemoval;
_onDecodedData = onDecodedData;
_onError = onError;
_onBatteryLevel = onBatteryLevel;
_onPowerState = onPowerState;
_onButtons = onButtons;
_onSocketCamCanceled = onSocketCamCanceled;
_onDiscoveredDevice = onDiscoveredDevice;
_onDiscoveryEnd = onDiscoveryEnd;
_onLogTrace = onLogTrace;
final Capture capture = _captureFactory();
_opening = true;
try {
await capture.openClient(appInfo, _handleEvent);
} catch (e) {
_opening = false;
_bufferedEvents.clear();
_clearCallbacks();
if (e is CaptureException) {
rethrow;
}
throw CaptureException(
SktErrors.ESKT_COMMUNICATIONERROR,
'Failed to open CaptureSDK session.',
e.toString(),
);
}
_capture = capture;
_opening = false;
if (Platform.isAndroid) {
final int clientHandle = _capture!.clientOrDeviceHandle ?? 0;
await CapturePlugin.startSocketCamExtension(clientHandle, (_) {});
}
// Drain buffered events that arrived during openClient
final List<({CaptureEvent event, int handle})> buffered =
List<({CaptureEvent event, int handle})>.from(_bufferedEvents);
_bufferedEvents.clear();
for (final ({CaptureEvent event, int handle}) item in buffered) {
await _handleEvent(item.event, item.handle);
}
return _capture!.clientOrDeviceHandle ?? 0;
}