Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FiDeSMo Utility · [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/fidesmo/fdsm/blob/master/LICENSE) [![Build Status](https://github.com/fidesmo/fdsm/workflows/Continuous%20Integration/badge.svg?branch=master)](https://github.com/fidesmo/fdsm/actions) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.fidesmo/fdsm/badge.svg)](https://mvnrepository.com/artifact/com.fidesmo/fdsm) [![Release]( https://img.shields.io/github/release/fidesmo/fdsm/all.svg)](https://github.com/fidesmo/fdsm/releases)
# FiDeSMo Utility · [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/fidesmo/fdsm/blob/master/LICENSE) [![Build Status](https://github.com/fidesmo/fdsm/workflows/Continuous%20Integration/badge.svg?branch=master)](https://github.com/fidesmo/fdsm/actions) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.fidesmo/fdsm/badge.svg)](https://mvnrepository.com/artifact/com.fidesmo/fdsm) [![Release](https://img.shields.io/github/release/fidesmo/fdsm/all.svg)](https://github.com/fidesmo/fdsm/releases)

FDSM is _the_ developer's Swiss Army Knife for working with a [Fidesmo device](https://fidesmo.com/consumer/wearables/) and the [Fidesmo API](https://developer.fidesmo.com/api). It provides an alternative to [Fidesmo Android app](https://play.google.com/store/apps/details?id=com.fidesmo.sec.android) when delivering services to a device via a PC/SC reader (contact or contactless). All from the command line.

Expand Down
9 changes: 4 additions & 5 deletions library/src/main/java/com/fidesmo/fdsm/WsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class WsClient {
private final URI uri;
private final Map<String, String> headers;
private final BIBO card;
private WebSocket client;
private volatile WebSocket client;
private final CompletableFuture<ServiceDeliverySession.DeliveryResult> deliveryResult = new CompletableFuture<>();
private String sessionId;
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
Expand Down Expand Up @@ -91,9 +91,6 @@ public CompletableFuture<ServiceDeliverySession.DeliveryResult> run() {
deliveryResult.completeExceptionally(error);
return;
}

client = webSocket;

scheduler.scheduleAtFixedRate(() -> {
if (client != null) {
client.sendPing(ByteBuffer.wrap(new byte[] {1})).exceptionally(ex -> {
Expand Down Expand Up @@ -127,6 +124,7 @@ protected WebSocket.Listener buildWsListener() {
private final StringBuilder incomingMessage = new StringBuilder();
@Override
public void onOpen(WebSocket webSocket) {
client = webSocket;
webSocket.request(1);
}

Expand All @@ -141,7 +139,7 @@ public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean

String message = incomingMessage.toString();
incomingMessage.setLength(0);

try {
processCommand(mapper.readTree(message));
} catch (IOException | DecoderException | BIBOException e) {
Expand Down Expand Up @@ -222,6 +220,7 @@ protected void respond(ObjectNode node) {
}

private void close() {
logger.debug("Closing websocket");
WebSocket wsClient = client;
scheduler.shutdown();
if (wsClient != null && !wsClient.isOutputClosed()) {
Expand Down
Loading