CaptureHelper for The React Native CaptureSDK¶
In the latest version of the React Native CaptureSDK, we have included the first iteration of CaptureHelper
.
CaptureHelper¶
The CaptureHelper
class is a class provided by the React Native CaptureSDK in order to have certain core CaptureSDK logic built out and ready to be used by the developer. Currently CaptureHelper
only has variables, interfaces and helper methods related to SocketCam. But in the future, it will include a lot more. For example, the developer used to be responsible for constructing the trigger options used in the UI for SocketCam; now those are provided by CaptureHelper
.
How to Use It¶
You will already have access to CaptureHelper
out of the box with the latest version of the React Native CaptureSDK. All you need to do it import it from the CaptureSDK. See below.
import { CaptureHelper } from 'react-native-capture';
Below is a sample on how it might be used in your React app.
import {
CaptureRn,
Trigger,
type CaptureDeviceInfo,
CaptureHelper, // HERE IS CAPTURE HELPER
} from 'react-native-capture';
...
<RadioButtons
title="Scan Trigger Type"
data={CaptureHelper.SocketCamTriggerOptions} // here you can use CaptureHelper to access the predefined trigger options.
handleTriggerType={handleTriggerType}
value={triggerType.toString()}
/>
It also provides a method for checking if SocketCam is enabled for your app. See the below code from the CaptureHelper
class itself.
static async getSocketCamEnabled({
socketCamCapture,
handleSetSocketCamEnabled,
fromCallback,
}: GetSocketCamEnabledArguments) {
let property = new CaptureProperty(
CapturePropertyIds.SocketCamStatus,
CapturePropertyTypes.None,
{}
);
try {
let data = await socketCamCapture.getProperty(property);
handleSetSocketCamEnabled(data.value);
let statusOption =
CaptureHelper.SocketCamStatusOptions[
data.value as keyof SocketCamStatusOption
];
return (
!fromCallback &&
`successfully retrieved SocketCamStatus: '${statusOption?.message}'`
);
} catch (error) {
let err = CaptureHelper.errorCheck(error);
return `failed to get SocketCamStatus: ${err.code} : ${err.message}`;
}
}
The developer can call the above method and provide the required arguments like so.
import {
CaptureRn,
Trigger,
type CaptureDeviceInfo,
CaptureHelper, // HERE IS CAPTURE HELPER
} from 'react-native-capture';
const [socketCamCapture, setSocketCamCapture] = useState(new CaptureRn());
const [socketCamEnabled, setSocketCamEnabled] = useState(1)
const handleSetSocketCamEnabled = (stat: number) =>{
setSocketCamEnabled(stat)
}
const handleGetSocketCamEnabled = () => {
CaptureHelper.getSocketCamEnabled({
socketCamCapture,
handleSetSocketCamEnabled, // this will allow our helper method invoke whatever logic you need with the result of SocketCam enabled
});
}
...
<Button title="Get SocketCam Enabled" onPress={handleGetSocketCamEnabled}/>
List of Methods and Variables Currently Included in CaptureHelper¶
Below are a list of currently supported methods, variables and interfaces currently available for use in the React Native CaptureSDK.
Variables
- SocketCamTriggerOptions
: Trigger options for SocketCam.
- SocketCamStatusOptions
: Status options for enabling/disabling SocketCam (it is recommended to keep status set to “enabled”, which is it by default).
Methods
- getSocketCamEnabled
: Method for retrieving whether or not SocketCam is enabled for your app (is enabled by default).
- setSocketCamEnabled
: Method for setting whether or not SocketCam is enabled for your app (disabling SocketCam is not recommended).
- setSocketCamTriggerProperty
: Method for setting the SocketCam Trigger (to one of the options provided in SocketCamTriggerOptions
).