Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from lastverb/master
Browse files Browse the repository at this point in the history
Websocker routing changed from selectors to routing keys
  • Loading branch information
lastverb committed May 14, 2020
2 parents 9eb4b2b + 5b2ce17 commit 5cf957a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target/
# IDE
.vscode/
.idea/
*.iml
!.idea/codeStyleSettings.xml

# Logs
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

<groupId>com.bitbar</groupId>
<artifactId>remote-device-client</artifactId>
<version>2.85</version>
<version>2.96</version>
<packaging>jar</packaging>

<properties>
<java.version>1.8</java.version>
<testdroid-api.version>2.85</testdroid-api.version>
<testdroid-api.version>2.96</testdroid-api.version>
<cli.version>1.3.1</cli.version>
<jsch.version>0.1.55</jsch.version>
<springboot.version>2.2.0.RELEASE</springboot.version>
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/bitbar/remotedevice/StaticParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ public class StaticParameters {

public static final String DEVICE_SESSIONS_URI = "/me/device-sessions";

public static final String RELEASE_DS_URI = "/me/device-sessions/%d/release";

public static final String WEBSOCKET_CONNECTIONS_TOPIC = "/topic/device-session-connections";
public static final String WEBSOCKET_CONNECTIONS_TOPIC_FORMAT = "/topic/device-sessions.%s.connections";

public static final String WEBSOCKET_URI = "/websocket";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.testdroid.api.dto.Context;
import com.testdroid.api.dto.MappingKey;
import com.testdroid.api.filter.FilterEntry;
import com.testdroid.api.filter.ListStringFilterEntry;
import com.testdroid.api.filter.NumberFilterEntry;
import com.testdroid.api.model.APICloudInfo;
import com.testdroid.api.model.APIDevice;
import com.testdroid.api.model.APIDeviceSession;
Expand Down Expand Up @@ -46,7 +44,7 @@ private APIClient createAPIClient(String cloudUrl, String apiKey) throws Require

public List<APIDevice> getSupportedDevices() throws APIException {
Context<APIDevice> ctx = new Context<>(APIDevice.class);
ctx.getFilters().add(new ListStringFilterEntry(OS_TYPE, IN,
ctx.getFilters().add(new FilterEntry(OS_TYPE, IN,
Arrays.asList(ANDROID.getDisplayName(), IOS.getDisplayName())));
apiClient.findDevicePropertyInLabelGroup("supported-frameworks", "remote-session").
ifPresent(val -> ctx.setExtraParams(
Expand All @@ -62,7 +60,7 @@ public List<APIDevice> getSupportedDevices() throws APIException {
public APIDevice getDevice(Long id) throws APIException {
Context<APIDevice> ctx = new Context<>(APIDevice.class);
List<FilterEntry> filters = ctx.getFilters();
filters.add(new NumberFilterEntry(ID, EQ, id));
filters.add(new FilterEntry(ID, EQ, id));
APIList<APIDevice> devices = apiClient.getDevices(ctx).getEntity();
if (devices.isEmpty()) {
throw new APIException(String.format("Could not find device with id %d", id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;

import static com.bitbar.remotedevice.StaticParameters.WEBSOCKET_CONNECTIONS_TOPIC;
import static com.bitbar.remotedevice.StaticParameters.WEBSOCKET_CONNECTIONS_TOPIC_FORMAT;
import static com.bitbar.remotedevice.cli.CommandLineParameter.API_KEY;
import static com.bitbar.remotedevice.cli.CommandLineParameter.CLOUD_URI;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;
Expand Down Expand Up @@ -60,7 +60,7 @@ public StompSession startWebsocketSession(APIDeviceSession deviceSession)
throws ExecutionException, InterruptedException {
WebSocketStompClient stompClient = createStompClient();

StompSessionHandler sessionHandler = new StompSessionHandler(this, WEBSOCKET_CONNECTIONS_TOPIC,
StompSessionHandler sessionHandler = new StompSessionHandler(this, WEBSOCKET_CONNECTIONS_TOPIC_FORMAT,
deviceSession.getId());

WebSocketHttpHeaders webSocketHttpHeaders = new WebSocketHttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,18 @@ public class StompSessionHandler extends StompSessionHandlerAdapter {

private static final Logger LOGGER = LoggerFactory.getLogger(StompSessionHandler.class);

private static final String DEVICE_SESSION_SELECTOR_FORMAT = "deviceSessionId = %d";

private static final String SELECTOR_HEADER_NAME = "selector";

private String connectionTopic;

private Long deviceSessionId;

private WebsocketManager websocketManager;

public StompSessionHandler(WebsocketManager websocketManager, String connectionTopic, Long deviceSessionId) {
this.connectionTopic = connectionTopic;
this.deviceSessionId = deviceSessionId;
public StompSessionHandler(WebsocketManager websocketManager, String connectionTopicFormat, Long deviceSessionId) {
this.connectionTopic = String.format(connectionTopicFormat, deviceSessionId);
this.websocketManager = websocketManager;
}

@Override
public void afterConnected(StompSession session, StompHeaders headers) {
StompHeaders subscribeHeaders = new StompHeaders();
subscribeHeaders.setDestination(connectionTopic);
subscribeHeaders.set(SELECTOR_HEADER_NAME, String.format(DEVICE_SESSION_SELECTOR_FORMAT, deviceSessionId));
session.subscribe(subscribeHeaders, new DeviceSessionStompFrameHandler(websocketManager));
session.subscribe(connectionTopic, new DeviceSessionStompFrameHandler(websocketManager));
}

/**
Expand Down

0 comments on commit 5cf957a

Please sign in to comment.