Class ButtplugClient
java.lang.Object
io.github.blackspherefollower.buttplug4j.client.ButtplugClient
ButtplugClient is the abstract class containing the bulk of the logic for communicating with the Buttplug.io sever
Intiface Central.
The transport logic is not in this package, as the various websocket libraries have differing requirements that will not fit all use-cases. In general, the Java8 compatible Jetty Websocket Client connector will meet the needs of most users: see tinyurl.com/buttplug4j
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumConnection state enum. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidcleanup()Cleanup resources.final voidDisconnect the client.protected final voidPerform the handshake with the server.Get the connection state.final IDeviceAddedEventGet the device added handler.final IDeviceChangedEventGet the device changed handler.final IDeviceRemovedEventGet the device removed handler.final List<ButtplugClientDevice>Get the list of connected devices.final IErrorEventGet the error handler.final IInputEventGet the input handler.final intGet the next message ID.final IConnectedEventGet the connected handler.protected final ButtplugJsonMessageParserGet the JSON parser.final IScanningEventGet the scanning finished handler.final booleanCheck if the client is connected.final voidonMessage(List<ButtplugMessage> msgs) Called when a list of messages is received.final voidRequest the device list from the server.protected final CompletableFuture<ButtplugMessage>scheduleWait(int id, CompletableFuture<ButtplugMessage> promise) Schedule a wait for a message response.final CompletableFuture<ButtplugMessage>sendDeviceMessage(ButtplugClientDevice device, ButtplugDeviceMessage deviceMsg) Send a device message.protected abstract CompletableFuture<ButtplugMessage>Send a message.protected final voidsetConnectionState(ButtplugClient.ConnectionState connectionState) Set the connection state.final voidsetDeviceAddedHandler(IDeviceAddedEvent deviceAddedHandler) Set the device added handler.final voidsetDeviceChangedHandler(IDeviceChangedEvent deviceChangedHandler) Set the device changed handler.final voidsetDeviceRemovedHandler(IDeviceRemovedEvent deviceRemovedHandler) Set the device removed handler.final voidsetErrorHandler(IErrorEvent errorReceivedHandler) Set the error handler.final voidsetInputHandler(IInputEvent inputHandler) Set the input handler.final voidsetOnConnected(IConnectedEvent onConnected) Set the connected handler.final voidsetScanningFinishedHandler(IScanningEvent scanningFinishedHandler) Set the scanning finished handler.final booleanStart scanning for devices.final Future<ButtplugMessage>Start scanning for devices asynchronously.final booleanStop all devices.final booleanstopAllDevices(boolean inputs, boolean outputs) Stop all devices.final Future<ButtplugMessage>Stop all devices asynchronously.final Future<ButtplugMessage>stopAllDevicesAsync(boolean inputs, boolean outputs) Stop all devices asynchronously.final booleanStop scanning for devices.final Future<ButtplugMessage>Stop scanning for devices asynchronously.protected final booleanwaitForOk(Future<ButtplugMessage> msg) Wait for an Ok message.
-
Constructor Details
-
ButtplugClient
Constructor.- Parameters:
aClientName- client name
-
-
Method Details
-
getParser
Get the JSON parser.- Returns:
- parser
-
getConnectionState
Get the connection state.- Returns:
- connection state
-
setConnectionState
Set the connection state.- Parameters:
connectionState- connection state
-
isConnected
public final boolean isConnected()Check if the client is connected.- Returns:
- true if connected
-
getNextMsgId
public final int getNextMsgId()Get the next message ID.- Returns:
- message ID
-
onMessage
Called when a list of messages is received.- Parameters:
msgs- messages
-
doHandshake
protected final void doHandshake()Perform the handshake with the server. -
requestDeviceList
public final void requestDeviceList() throws ButtplugClientException, ExecutionException, InterruptedException, TimeoutExceptionRequest the device list from the server.- Throws:
ButtplugClientException- if an error occursExecutionException- if an error occursInterruptedException- if an error occursTimeoutException- if an error occurs
-
getDevices
Get the list of connected devices.- Returns:
- devices
-
startScanning
public final boolean startScanning() throws ExecutionException, InterruptedException, IOException, TimeoutExceptionStart scanning for devices.- Returns:
- true if successful
- Throws:
ExecutionException- if an error occursInterruptedException- if an error occursIOException- if an error occursTimeoutException- if an error occurs
-
startScanningAsync
Start scanning for devices asynchronously.- Returns:
- future
-
stopScanning
public final boolean stopScanning() throws ExecutionException, InterruptedException, TimeoutExceptionStop scanning for devices.- Returns:
- true if successful
- Throws:
ExecutionException- if an error occursInterruptedException- if an error occursTimeoutException- if an error occurs
-
stopScanningAsync
Stop scanning for devices asynchronously.- Returns:
- future
-
stopAllDevices
public final boolean stopAllDevices() throws ExecutionException, InterruptedException, IOException, TimeoutExceptionStop all devices.- Returns:
- true if successful
- Throws:
ExecutionException- if an error occursInterruptedException- if an error occursIOException- if an error occursTimeoutException- if an error occurs
-
stopAllDevices
public final boolean stopAllDevices(boolean inputs, boolean outputs) throws ExecutionException, InterruptedException, IOException, TimeoutException Stop all devices.- Parameters:
inputs- stop inputsoutputs- stop outputs- Returns:
- true if successful
- Throws:
ExecutionException- if an error occursInterruptedException- if an error occursIOException- if an error occursTimeoutException- if an error occurs
-
stopAllDevicesAsync
Stop all devices asynchronously.- Returns:
- future
-
stopAllDevicesAsync
Stop all devices asynchronously.- Parameters:
inputs- stop inputsoutputs- stop outputs- Returns:
- future
-
sendDeviceMessage
public final CompletableFuture<ButtplugMessage> sendDeviceMessage(ButtplugClientDevice device, ButtplugDeviceMessage deviceMsg) Send a device message.- Parameters:
device- devicedeviceMsg- message- Returns:
- future
-
waitForOk
protected final boolean waitForOk(Future<ButtplugMessage> msg) throws ExecutionException, InterruptedException, TimeoutException Wait for an Ok message.- Parameters:
msg- message future- Returns:
- true if Ok
- Throws:
ExecutionException- if an error occursInterruptedException- if an error occursTimeoutException- if an error occurs
-
sendMessage
Send a message.- Parameters:
msg- message- Returns:
- future
-
getDeviceAddedHandler
Get the device added handler.- Returns:
- handler
-
setDeviceAddedHandler
Set the device added handler.- Parameters:
deviceAddedHandler- handler
-
getDeviceChanged
Get the device changed handler.- Returns:
- handler
-
setDeviceChangedHandler
Set the device changed handler.- Parameters:
deviceChangedHandler- handler
-
getDeviceRemovedHandler
Get the device removed handler.- Returns:
- handler
-
setDeviceRemovedHandler
Set the device removed handler.- Parameters:
deviceRemovedHandler- handler
-
getScanningFinishedHandler
Get the scanning finished handler.- Returns:
- handler
-
setScanningFinishedHandler
Set the scanning finished handler.- Parameters:
scanningFinishedHandler- handler
-
getErrorHandler
Get the error handler.- Returns:
- handler
-
setErrorHandler
Set the error handler.- Parameters:
errorReceivedHandler- handler
-
getInputHandler
Get the input handler.- Returns:
- handler
-
setInputHandler
Set the input handler.- Parameters:
inputHandler- handler
-
getOnConnectedHandler
Get the connected handler.- Returns:
- handler
-
setOnConnected
Set the connected handler.- Parameters:
onConnected- handler
-
cleanup
protected abstract void cleanup()Cleanup resources. -
disconnect
public final void disconnect()Disconnect the client. -
scheduleWait
protected final CompletableFuture<ButtplugMessage> scheduleWait(int id, CompletableFuture<ButtplugMessage> promise) Schedule a wait for a message response.- Parameters:
id- message IDpromise- promise- Returns:
- future
-