Autoblow JS SDK
This is a guide for the Autoblow JS SDK. This SDK is used to control the Autoblow devices in a node environment or in the browser.
Installation
Section titled “Installation”npm install @xsense/autoblow-sdk
import * as Autoblow from "@xsense/autoblow-sdk";
const { vacuglide, ultra } = await Autoblow.deviceInit("m3ztyf7bxgoi");//The deviceInit function will return the device objects if the device is connected//If the device is not connected, it will throw an error//if the connected device is a Vacuglide, it will return a Vacuglide object//if the connected device is a Ultra, it will return a Ultra object
if (vacuglide) await demoVacuglide(vacuglide);if (ultra) await demoUltra(ultra);
async function demoVacuglide(vacuglide: Autoblow.Vacuglide) { const state = await vacuglide.getState(); console.log(state);
const deviceInfo = await vacuglide.getInfo(); console.log(deviceInfo);
//We can handle the button presses events and make our app react to them vacuglide.deviceEvents.addEventListener("mode-button-pressed", event => { console.log("mode-button-pressed"); });}
async function demoUltra(ultra: Autoblow.Ultra) { const state = await ultra.getState(); console.log(state);
const deviceInfo = await ultra.getInfo(); console.log(deviceInfo);
//We can handle the button presses events and make our app react to them ultra.deviceEvents.addEventListener("pause-button-pressed", event => { console.log("pause-button-pressed"); });}
SDK Reference
Section titled “SDK Reference”Common Methods (Both Ultra and Vacuglide)
Section titled “Common Methods (Both Ultra and Vacuglide)”deviceInit(token: string): Promise<DeviceInitResult>
Section titled “deviceInit(token: string): Promise<DeviceInitResult>”Initialize the connection to the given device token.
Returns:
{ deviceInfo: DeviceInfo; deviceToken: string; deviceType: "autoblow-ultra" | "vacuglide"; ultra?: Ultra; vacuglide?: Vacuglide;}
Throws:
DeviceNotConnectedError
if device is not connected
getInfo(): Promise<DeviceInfo>
Section titled “getInfo(): Promise<DeviceInfo>”Returns the device information.
getState(): Promise<DeviceState>
Section titled “getState(): Promise<DeviceState>”Returns the current device state.
getStateCache(): DeviceState | null
Section titled “getStateCache(): DeviceState | null”Returns the cached device state without making a network request.
getConnectedCluster(): string | null
Section titled “getConnectedCluster(): string | null”Returns the connected cluster string or null if not connected.
estimateLatency(noOfRequests?: number): Promise<number>
Section titled “estimateLatency(noOfRequests?: number): Promise<number>”Estimates the latency of the device by sending a number of requests and calculating the average latency. If no number of requests is given, the default is 10.
Local Script Methods
Section titled “Local Script Methods”localScriptList(): Promise<number[]>
Section titled “localScriptList(): Promise<number[]>”Returns the list of loaded local scripts.
localScriptReplace(replacedLocalScriptIndex: number, newLocalScriptId: number): Promise<number[]>
Section titled “localScriptReplace(replacedLocalScriptIndex: number, newLocalScriptId: number): Promise<number[]>”Replaces a local script at the given index with a new script ID.
localScriptSwap(scriptIndexA: number, scriptIndexB: number): Promise<number[]>
Section titled “localScriptSwap(scriptIndexA: number, scriptIndexB: number): Promise<number[]>”Swaps two local scripts at the given indices.
localScriptMove(fromIndex: number, toIndex: number): Promise<number[]>
Section titled “localScriptMove(fromIndex: number, toIndex: number): Promise<number[]>”Moves a local script from one index to another.
localScriptStart(): Promise<DeviceState>
Section titled “localScriptStart(): Promise<DeviceState>”Starts the local script.
localScriptStop(): Promise<DeviceState>
Section titled “localScriptStop(): Promise<DeviceState>”Stops the local script.
Sync Script Methods
Section titled “Sync Script Methods”syncScriptLoadToken(token: string): Promise<DeviceState>
Section titled “syncScriptLoadToken(token: string): Promise<DeviceState>”Loads the sync script with the given sync token.
syncScriptUploadFunscriptUrl(funscriptUrl: string): Promise<DeviceState>
Section titled “syncScriptUploadFunscriptUrl(funscriptUrl: string): Promise<DeviceState>”Downloads the funscript from the given url, converts it to a binary script that autoblow can play and uploads it onto the device.
syncScriptUploadFunscriptFile(funscript: Funscript): Promise<DeviceState>
Section titled “syncScriptUploadFunscriptFile(funscript: Funscript): Promise<DeviceState>”Uploads the given funscript onto the device. The funscript should be a Funscript object.
syncScriptUploadCsvUrl(csvUrl: string): Promise<DeviceState>
Section titled “syncScriptUploadCsvUrl(csvUrl: string): Promise<DeviceState>”Downloads the csv file from the given url, converts it to a binary script that autoblow can play and uploads it onto the device.
syncScriptUploadCsvFile(csvContent: string): Promise<DeviceState>
Section titled “syncScriptUploadCsvFile(csvContent: string): Promise<DeviceState>”Uploads the given csv script onto the device. The csv content should be a string.
syncScriptStart(startTimeMs: number): Promise<DeviceState>
Section titled “syncScriptStart(startTimeMs: number): Promise<DeviceState>”Starts the sync script at the specified time in milliseconds.
syncScriptStop(): Promise<DeviceState>
Section titled “syncScriptStop(): Promise<DeviceState>”Stops the sync script.
syncScriptOffset(offsetTimeMs: number): Promise<DeviceState>
Section titled “syncScriptOffset(offsetTimeMs: number): Promise<DeviceState>”Sets the sync script offset time in milliseconds.
Firmware Methods
Section titled “Firmware Methods”firmwareUpdateStart(): Promise<true>
Section titled “firmwareUpdateStart(): Promise<true>”Starts a firmware update process.
Throws:
Error
if firmware update fails
firmwareUpdateInfo(): Promise<FirmwareInfo>
Section titled “firmwareUpdateInfo(): Promise<FirmwareInfo>”Returns firmware update information.
Ultra-Specific Methods
Section titled “Ultra-Specific Methods”localScriptSet(localScriptIndex: number, speedIndex: number): Promise<UltraDeviceState>
Section titled “localScriptSet(localScriptIndex: number, speedIndex: number): Promise<UltraDeviceState>”Sets the local script to the given index and speed index.
oscillateSet(speed: number, minY: number, maxY: number): Promise<UltraDeviceState>
Section titled “oscillateSet(speed: number, minY: number, maxY: number): Promise<UltraDeviceState>”Sets the oscillation speed and the oscillation range.
oscillateStart(): Promise<UltraDeviceState>
Section titled “oscillateStart(): Promise<UltraDeviceState>”Starts the oscillation.
oscillateStop(): Promise<UltraDeviceState>
Section titled “oscillateStop(): Promise<UltraDeviceState>”Stops the oscillation.
goToPosition(position: number, speed: number): Promise<UltraDeviceState>
Section titled “goToPosition(position: number, speed: number): Promise<UltraDeviceState>”Moves the device to a specific position at the given speed.
Ultra Events
Section titled “Ultra Events”speed-up-button-pressed
speed-down-button-pressed
mode-button-pressed
pause-button-pressed
Vacuglide-Specific Methods
Section titled “Vacuglide-Specific Methods”localScriptSet(localScriptIndex: number): Promise<VacuglideDeviceState>
Section titled “localScriptSet(localScriptIndex: number): Promise<VacuglideDeviceState>”Sets the local script to the given index.
valveStrokePlusSet(valveState: boolean): Promise<VacuglideDeviceState>
Section titled “valveStrokePlusSet(valveState: boolean): Promise<VacuglideDeviceState>”Controls the stroke plus valve state. If the valveState is true, the valve will be opened. If the valveState is false, the valve will be closed.
valveStrokeMinusSet(valveState: boolean): Promise<VacuglideDeviceState>
Section titled “valveStrokeMinusSet(valveState: boolean): Promise<VacuglideDeviceState>”Controls the stroke minus valve state. If the valveState is true, the valve will be opened. If the valveState is false, the valve will be closed.
targetSpeedSet(targetSpeed: number): Promise<VacuglideDeviceState>
Section titled “targetSpeedSet(targetSpeed: number): Promise<VacuglideDeviceState>”Sets the target speed for the device in percent. The value should be between 0 and 100.
targetSpeedStop(): Promise<VacuglideDeviceState>
Section titled “targetSpeedStop(): Promise<VacuglideDeviceState>”Stops the target speed mode.
Vacuglide Events
Section titled “Vacuglide Events”speed-plus-button-pressed
speed-minus-button-pressed
mode-button-pressed
DeviceInfo
Section titled “DeviceInfo”type DeviceInfo = { firmwareVersion: number; firmwareBranch: string; hardwareVersion: string; firmwareStatus: "UP_TO_DATE" | "UPDATE_AVAILABLE" | "UPDATE_REQUIRED"; mac: string; deviceType: "autoblow-ultra" | "vacuglide";};
UltraDeviceState
Section titled “UltraDeviceState”type UltraDeviceState = { operationalMode: UltraOperationalMode; localScript: number; localScriptSpeed: number; motorTemperature: number; oscillatorTargetSpeed: number; oscillatorLowPoint: number; oscillatorHighPoint: number; syncScriptCurrentTime: number; syncScriptOffsetTime: number; syncScriptToken: string; syncScriptLoop: boolean;};
VacuglideDeviceState
Section titled “VacuglideDeviceState”type VacuglideDeviceState = { operationalMode: VacuglideOperationalMode; localScript: number; targetSpeed: number; strokePlusValve: boolean; strokeMinusValve: boolean; syncScriptCurrentTime: number; syncScriptOffsetTime: number; syncScriptToken: string; syncScriptLoop: boolean;};
Funscript
Section titled “Funscript”type Funscript = { metadata: { id: number; version: number }; actions: { at: number; pos: number }[];};
FirmwareInfo
Section titled “FirmwareInfo”type FirmwareInfo = { branch: number; firmwareVersion: string; hardwareVersion: string;};
Error Handling
Section titled “Error Handling”The SDK provides several custom error types:
DeviceNotConnectedError
: Thrown when device is not connectedDeviceNotInitializedError
: Thrown when device is not initializedDeviceTimeoutError
: Thrown when device request times outValidationError
: Thrown when request validation failsDeviceCommandResultError
: Thrown when device command fails
- The SDK uses a task queue system to manage requests efficiently
- Device state is cached locally to improve performance
- All methods return promises and can be used with async/await
- Event listeners are available for real-time device button press events
- The SDK automatically handles device type detection and returns the appropriate device instance