Infinity Plugin API Reference
This page documents all methods and event streams available in the Anyline Infinity Plugin.
Overview
-
React Native
| Method | Description | Returns |
|---|---|---|
|
Initializes the Anyline SDK with a license key |
|
|
Starts a scan session with a |
|
|
Stops the active scan session |
|
|
Switches scan mode using a full scan-start request |
|
|
Switches scan mode using a raw |
|
|
Submits a User Corrected Result report |
|
|
Exports cached scan events as a ZIP archive |
|
|
Returns the plugin version string |
|
|
Returns the native SDK version string |
|
| Event | Description | Returns |
|---|---|---|
|
Subscribes to scan results during an active session (0..N) |
|
|
Subscribes to UI feedback element tap events (0..N) |
|
Call .remove() on the returned EmitterSubscription when the subscription is no longer needed.
|
Methods
All request and response types use the WrapperSession prefix (e.g. WrapperSessionScanStartRequest, WrapperSessionScanResponse). These are generated from the Anyline JSON schemas and represent the structured data exchanged between your application and the native SDK.
requestSdkInitialization
Initializes the Anyline SDK. Call this before starting any scan session.
Parameters:
-
request: aWrapperSessionSdkInitializationRequestcontaining your license key and optional configuration
Returns: WrapperSessionSdkInitializationResponse. See the overview table for platform-specific return type details.
-
React Native
const request = {
licenseKey: 'YOUR_LICENSE_KEY', // Replace with your Anyline License Key
// Optional: only needed if your app bundles custom ML model files provided by Anyline.
// The value depends on where these files are placed in your project. See the Developer Examples.
assetPathPrefix: 'anyline_assets',
};
const response = await infinityPlugin.requestSdkInitialization(request);
if (response.initialized) {
console.log('SDK initialized:', response.succeedInfo);
} else {
console.error('SDK init failed:', response.failInfo?.lastError);
}
requestScanStart
Starts a scan session. The method resolves/completes when the session ends (user dismissal, error, or programmatic stop). Intermediate scan results arrive via the onScanResults event stream.
Parameters:
-
request: aWrapperSessionScanStartRequestcontaining thescanViewConfigContentString(JSON)
Returns: WrapperSessionScanResponse when the session ends. See the overview table for platform-specific return type details.
-
React Native
import {
AnylineInfinityPlugin,
ExportedScanResultImageFormat,
} from 'anyline-ocr-react-native-module/AnylineInfinityPlugin';
// Subscribe to scan results before starting the scan
const subscription = infinityPlugin.onScanResults((result) => {
const scanResult = result.exportedScanResults?.[0];
console.log('Scan result:', scanResult?.pluginResult);
});
// Specify image format and delivery method for scan results
const scanResultConfig = {
imageContainer: {
encoded: {},
},
imageParameters: {
format: ExportedScanResultImageFormat.Png,
quality: 50,
},
};
// scanViewConfigJson is a JSON string containing your ScanViewConfig
const request = {
scanViewConfigContentString: scanViewConfigJson,
scanResultConfig: scanResultConfig,
};
// requestScanStart resolves when the scan session ends
const response = await infinityPlugin.requestScanStart(request);
console.log('Scan session ended:', response.status);
// Clean up subscription when done
subscription.remove();
requestScanStop
Stops the active scan session.
Parameters:
-
request(optional): aWrapperSessionScanStopRequestwith stop configuration
Returns: No return value. See the overview table for platform-specific details.
-
React Native
// Stop with default behavior
infinityPlugin.requestScanStop();
// Or stop with an optional reason (surfaces in abortInfo.message on the scan response)
infinityPlugin.requestScanStop({ message: 'Scan stopped: no result within timeout' });
requestScanSwitchWithScanStartRequestParams
Switches to a new scan mode without stopping the current session. Uses a full WrapperSessionScanStartRequest allowing you to change all scan parameters.
Parameters:
-
request: aWrapperSessionScanStartRequestwith the new configuration
Returns: No return value. See the overview table for platform-specific details.
Code examples for both switch methods are shown below.
requestScanSwitchWithScanViewConfigContentString
Switches to a new scan mode using only a raw ScanViewConfig JSON string. Use this when you only need to change the scan configuration without modifying other request parameters.
Parameters:
-
scanViewConfigContentString: a raw JSON string containing the newScanViewConfig
Returns: No return value. See the overview table for platform-specific details.
-
React Native
Switch to a new scan mode using a full scan-start request. For example, to change the scan configuration, save result images to a directory, and set a workflow correlationId:
import { WrapperSessionScanResultCleanStrategyConfig } from 'anyline-ocr-react-native-module/AnylineInfinityPlugin';
import * as FileSystem from 'expo-file-system';
const resultPath = FileSystem.documentDirectory
.replace(/^file:\/\//, '')
.replace(/\/$/, '') + '/results/';
// newScanViewConfigJson: a JSON string containing the replacement ScanViewConfig
const switchRequest = {
scanViewConfigContentString: newScanViewConfigJson,
scanResultConfig: {
cleanStrategy: WrapperSessionScanResultCleanStrategyConfig.CleanFolderOnStartScanning,
imageContainer: {
saved: {
path: resultPath,
},
},
imageParameters: {
quality: 50,
format: 'png',
},
},
scanViewInitializationParameters: {
correlationId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
},
};
infinityPlugin.requestScanSwitchWithScanStartRequestParams(switchRequest);
Or switch using only a raw ScanViewConfig JSON string:
infinityPlugin.requestScanSwitchWithScanViewConfigContentString(
newScanViewConfigJson,
);
requestUCRReport
Submits a User Corrected Result (UCR) report. UCR allows you to send corrections for scan results back to Anyline for model improvement.
Parameters:
-
request: aWrapperSessionUcrReportRequestcontaining the corrected result data
Returns: WrapperSessionUcrReportResponse. See the overview table for platform-specific return type details.
-
React Native
import {
AnylineInfinityPlugin,
WrapperSessionUcrReportResponseStatus,
} from 'anyline-ocr-react-native-module/AnylineInfinityPlugin';
// pluginResult: obtained from the onScanResults event stream (see Scan Result Handling)
// userCorrectedValue: the value corrected by the user after reviewing the scan result
const ucrRequest = {
blobKey: pluginResult.blobKey,
correctedResult: userCorrectedValue,
};
const ucrResponse = await infinityPlugin.requestUCRReport(ucrRequest);
if (ucrResponse.status === WrapperSessionUcrReportResponseStatus.UcrReportSucceeded) {
console.log('UCR submitted:', ucrResponse.succeedInfo?.message);
} else {
console.log('UCR failed:', ucrResponse.failInfo?.lastError);
}
requestExportCachedEvents
Exports all cached scan events as a ZIP archive. Useful for debugging or offline analytics.
Parameters: none
Returns: WrapperSessionExportCachedEventsResponse. See the overview table for platform-specific return type details.
-
React Native
import {
AnylineInfinityPlugin,
WrapperSessionExportCachedEventsResponseStatus,
} from 'anyline-ocr-react-native-module/AnylineInfinityPlugin';
const exportResponse = await infinityPlugin.requestExportCachedEvents();
if (exportResponse.status === WrapperSessionExportCachedEventsResponseStatus.ExportSucceeded) {
const filePath = exportResponse.succeedInfo?.exportedFile;
console.log('Events exported to:', filePath);
} else {
console.log('Export failed:', exportResponse.failInfo?.lastError);
}
getPluginVersion
Returns the version string of the wrapper plugin itself.
Parameters: none
Returns: Version string. See the overview table for platform-specific return type details.
getSDKVersion
Returns the version string of the underlying native Anyline SDK.
Parameters: none
Returns: Version string. See the overview table for platform-specific return type details.
-
React Native
// Get the plugin version (synchronous)
const pluginVersion = infinityPlugin.getPluginVersion();
// Get the native SDK version
const sdkVersion = await infinityPlugin.getSDKVersion();
Event Streams
onScanResults
Emits WrapperSessionScanResultsResponse objects during an active scan session. You may receive zero or more results before the session ends.
Subscribe to this event stream before calling requestScanStart.
See Scan Result Handling for details on the result structure.
-
React Native
const subscription = infinityPlugin.onScanResults((result) => {
// Iterate over all results in this batch (may contain multiple when using composite scanning)
for (const scanResult of result.exportedScanResults ?? []) {
const pluginResult = scanResult.pluginResult;
console.log('Plugin result:', pluginResult);
// Handle images based on delivery method
const imageContainer = scanResult.imageContainer;
if (imageContainer?.saved) {
const saved = imageContainer.saved;
const basePath = saved.path ?? '';
const fullFramePath = `${basePath}/${saved.images?.image}`;
const cutoutPath = `${basePath}/${saved.images?.cutoutImage}`;
} else if (imageContainer?.encoded) {
const encoded = imageContainer.encoded;
// Decode from Base64 for display or upload
const fullFrameBase64 = encoded.images?.image;
const cutoutBase64 = encoded.images?.cutoutImage;
}
}
});
// Remove subscription when no longer needed
subscription.remove();
onUIElementClicked
Emits UiFeedbackElementConfig objects when the user taps a UI feedback element during scanning. This is useful for interactive scan overlays.
See UI Feedback Config for details on configuring UI feedback elements.
-
React Native
const subscription = infinityPlugin.onUIElementClicked(
(element: UiFeedbackElementConfig) => {
console.log('UI element tapped:', element.id);
}
);
// Clean up when done
subscription.remove();