Skip to content
Merged

V4 #107

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

Learn more about buttplug.io at https://buttplug.io


## Platform Support

Buttplug Java should run on any 1.8 or later JRE (including Android).
Expand All @@ -19,13 +18,15 @@ library, so there's no need to add a separate dependency); see the 2
dependency import examples below.

For Gradle:

```groovy
dependencies {
implementation 'io.github.blackspherefollower:buttplug4j.connectors.jetty.websocket.client:3.1.180'
}
```

For Maven:

```xml
<dependencies>
<dependency>
Expand All @@ -38,11 +39,10 @@ For Maven:

For an all-in-one example project, please see https://github.com/blackspherefollower/buttplug4j-example

In general, you'll want to create a `ButtplugClientWSClient` object in a scope where it will not get garbage collected
In general, you'll want to create a `ButtplugClientWSClient` object in a scope where it will not get garbage collected
before you're done, add callbacks for error and event handling, then connect it to the address Intiface is listening
on. Then you can scan for devices, iterate over them and send commands.


### Snapshots

Snapshot libraries from the buttplug4j repo are available via Maven from the Central Portal Snapshots
Expand All @@ -51,6 +51,7 @@ repository: https://central.sonatype.com/repository/maven-snapshots
Releases will be available from Maven Central.

For Gradle:

```groovy
repositories {
maven {
Expand All @@ -59,11 +60,12 @@ repositories {
}
}
dependencies {
implementation 'io.github.blackspherefollower:buttplug4j.connectors.jetty.websocket.client:3.1.+'
implementation 'io.github.blackspherefollower:buttplug4j.connectors.jetty.websocket.client:4.0.+'
}
```

For Maven:

```xml
<repositories>
<repository>
Expand All @@ -79,7 +81,7 @@ For Maven:
<dependency>
<groupId>io.github.blackspherefollower</groupId>
<artifactId>buttplug4j.connectors.jetty.websocket.client</artifactId>
<version>[3.1-SNAPSHOT,)</version>
<version>[4.0-SNAPSHOT,)</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'io.github.blackspherefollower'
version = "3.1." + ("${System.env.GITHUB_RUN_NUMBER ?: 1}") + ("${System.env.GITHUB_REF_TYPE}" == "tag" ? "" : "-SNAPSHOT")
version = "4.0." + ("${System.env.GITHUB_RUN_NUMBER ?: 1}") + ("${System.env.GITHUB_REF_TYPE}" == "tag" ? "" : "-SNAPSHOT")

nexusPublishing {
repositories {
Expand Down
3 changes: 3 additions & 0 deletions buttplug4j.connectors.javax.websocket.client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ dependencies {
api project(':buttplug4j.connectors.javax.websocket.common')
api 'org.eclipse.jetty.websocket:websocket-javax-client:10.0.26'
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
testImplementation project(':buttplug4j.utils.test')
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.13.4'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.13.4'
}


java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
withJavadocJar()
withSourcesJar()
}

checkstyle {
configFile = file("${rootDir}/checkstyle.xml")
showViolations = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void connect(final URI url) throws IllegalStateException, DeploymentExcep

// Restore and echo down the line
setOnConnected(stashCallback);
if(stashCallback != null )
if (stashCallback != null)
stashCallback.onConnected(this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,87 @@
package io.github.blackspherefollower.buttplug4j.connectors.javax.websocket.client;

import io.github.blackspherefollower.buttplug4j.client.ButtplugClientDevice;
import io.github.blackspherefollower.buttplug4j.client.ButtplugClientDeviceFeature;
import io.github.blackspherefollower.buttplug4j.client.ButtplugDeviceFeatureException;
import io.github.blackspherefollower.buttplug4j.protocol.ButtplugMessage;
import io.github.blackspherefollower.buttplug4j.protocol.messages.InputReading;
import io.github.blackspherefollower.buttplug4j.utils.test.WSDMClient;
import io.github.blackspherefollower.buttplug4j.utils.test.IntifaceEngineWrapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.net.URI;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

public class ButtplugWSClientMockTest {

@Disabled
@Test
public void TestConnect() throws Exception {
ButtplugClientWSClient client = new ButtplugClientWSClient("Java Test");
client.connect(new URI("ws://localhost:12345/buttplug"));
client.startScanning();

Thread.sleep(5000);
client.requestDeviceList();
for (ButtplugClientDevice dev : client.getDevices()) {
if (dev.getScalarVibrateCount() > 0) {
dev.sendScalarVibrateCmd(0.5).get();
}
}
try(IntifaceEngineWrapper wrapper = new IntifaceEngineWrapper() ) {
Thread.sleep(500);
WSDMClient wsdev = new WSDMClient(new URI("ws://localhost:" + wrapper.dport), "LVS-Fake", "A9816725B");
Thread.sleep(500);

ButtplugClientWSClient client = new ButtplugClientWSClient("Java Test");
client.connect(new URI("ws://localhost:" + wrapper.cport + "/buttplug"));
client.startScanning();

Thread.sleep(1000);
assertTrue(client.stopAllDevices());
Thread.sleep(500);
client.requestDeviceList();

Thread.sleep(60000);
for (ButtplugClientDevice dev : client.getDevices()) {
if (dev.getScalarVibrateCount() > 0) {
dev.sendScalarVibrateCmd(0.5).get();
assertEquals(1, client.getDevices().size());
for (ButtplugClientDevice dev : client.getDevices()) {
for (ButtplugClientDeviceFeature feat : dev.getDeviceFeatures().values()) {
if (feat.HasVibrate()) {
feat.VibrateFloat(0.5F).get();
}
}
}
}
assertEquals(wsdev.messages.poll(), "Vibrate:10;");

Thread.sleep(1000);
assertTrue(client.stopAllDevices());
Thread.sleep(500);
assertTrue(client.stopAllDevices());
assertEquals(wsdev.messages.poll(), "Vibrate:0;");

Thread.sleep(60000);
for (ButtplugClientDevice dev : client.getDevices()) {
if (dev.getScalarVibrateCount() > 0) {
dev.sendScalarVibrateCmd(0.5).get();
}
client.disconnect();
}
}

Thread.sleep(1000);
assertTrue(client.stopAllDevices());
@Test
@Disabled("See https://github.com/buttplugio/buttplug/issues/801")
public void TestBattery() throws Exception {
try(IntifaceEngineWrapper wrapper = new IntifaceEngineWrapper() ) {
Thread.sleep(500);
WSDMClient wsdev = new WSDMClient(new URI("ws://localhost:" + wrapper.dport), "LVS-Fake", "A9816725B");
Thread.sleep(500);

ButtplugClientWSClient client = new ButtplugClientWSClient("Java Test");
client.connect(new URI("ws://localhost:" + wrapper.cport + "/buttplug"));
client.startScanning();

client.disconnect();
Thread.sleep(500);
client.requestDeviceList();
for (ButtplugClientDevice dev : client.getDevices()) {
for (ButtplugClientDeviceFeature feat : dev.getDeviceFeatures().values()) {
if (feat.HasBattery()) {
ButtplugMessage res = feat.ReadBattery().get();
if (res instanceof InputReading && ((InputReading) res).getData() instanceof InputReading.BatteryData) {
InputReading.BatteryData reading = (InputReading.BatteryData) ((InputReading) res).getData();
int battery = reading.getValue();
System.out.println("Battery is " + battery);
assertTrue(battery >= 0);
assertTrue(battery <= 100);
}
} else {
assertThrows(ButtplugDeviceFeatureException.class, () -> {
feat.ReadBattery().get();
});
}
}
}

client.disconnect();
}
}
}
1 change: 1 addition & 0 deletions buttplug4j.connectors.javax.websocket.common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ java {
withJavadocJar()
withSourcesJar()
}

checkstyle {
configFile = file("${rootDir}/checkstyle.xml")
showViolations = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected final CompletableFuture<ButtplugMessage> sendMessage(final ButtplugMes
if (session == null) {
Error err = new Error("Bad WS state!",
Error.ErrorClass.ERROR_UNKNOWN, ButtplugConsts.SYSTEM_MSG_ID);
if( getErrorReceived() != null) {
if (getErrorReceived() != null) {
getErrorReceived().errorReceived(err);
}
return CompletableFuture.completedFuture(err);
Expand All @@ -103,7 +103,7 @@ protected final CompletableFuture<ButtplugMessage> sendMessage(final ButtplugMes
session.getAsyncRemote().sendText(getParser().formatJson(msg)).get();
} catch (Exception e) {
Error err = new Error(e, msg.getId());
if( getErrorReceived() != null) {
if (getErrorReceived() != null) {
getErrorReceived().errorReceived(err);
}
return CompletableFuture.completedFuture(err);
Expand Down
3 changes: 3 additions & 0 deletions buttplug4j.connectors.javax.websocket.server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ dependencies {
api project(':buttplug4j.connectors.javax.websocket.common')
testImplementation 'org.eclipse.jetty.websocket:websocket-javax-server:10.0.26'
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
testImplementation project(':buttplug4j.utils.test')
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.13.4'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.13.4'
}


java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
withJavadocJar()
withSourcesJar()
}

checkstyle {
configFile = file("${rootDir}/checkstyle.xml")
showViolations = false
Expand Down
Loading
Loading