From 554b5e91faf8d8e65709f8d9723645a1f2fb39bc Mon Sep 17 00:00:00 2001
From: tobias <thinkdifferent055@gmail.com>
Date: Tue, 23 Nov 2021 22:12:39 +0100
Subject: [PATCH] #174 - WebAPI connection state icon shows correct state

---
 .../api/client/WebApiRemoteConnectionStateListener.java   | 8 ++++----
 .../scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala | 1 +
 pom.xml                                                   | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/client/WebApiRemoteConnectionStateListener.java b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/client/WebApiRemoteConnectionStateListener.java
index 5611562f..0b1d2b8c 100644
--- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/client/WebApiRemoteConnectionStateListener.java
+++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/java/de/tobias/playpad/plugin/api/client/WebApiRemoteConnectionStateListener.java
@@ -1,13 +1,13 @@
 package de.tobias.playpad.plugin.api.client;
 
 import com.neovisionaries.ws.client.WebSocketException;
-import com.neovisionaries.ws.client.WebSocketState;
 import de.thecodelabs.logger.Logger;
 import de.thecodelabs.utils.threading.Worker;
 import de.thecodelabs.utils.ui.icon.FontAwesomeType;
 import de.thecodelabs.utils.ui.icon.FontIcon;
 import de.thecodelabs.utils.util.Localization;
 import de.tobias.playpad.api.PlayPadClient;
+import de.tobias.playpad.api.PlayPadConnectionState;
 import de.tobias.playpad.plugin.MainWindowListener;
 import de.tobias.playpad.plugin.api.WebApiPlugin$;
 import de.tobias.playpad.viewcontroller.main.IMainViewController;
@@ -43,7 +43,7 @@ public class WebApiRemoteConnectionStateListener implements MainWindowListener {
 				connectionStateIcon.setIcons(allConnected ? FontAwesomeType.CLOUD : FontAwesomeType.EXCLAMATION_CIRCLE);
 				if (!allConnected) {
 					final String disconnectedServers = WebApiPlugin$.MODULE$.connections().entrySet().stream()
-							.filter(entry -> entry.getValue().getPlayPadConnectionState() != WebSocketState.OPEN)
+							.filter(entry -> entry.getValue().getPlayPadConnectionState() != PlayPadConnectionState.CONNECTED)
 							.map(entry -> entry.getKey().getName()).collect(Collectors.joining(", "));
 					connectionStateIcon.setTooltip(new Tooltip(Localization.getString("webapi-settings.remote.state.tooltip", disconnectedServers)));
 					connectionStateIcon.setStyle("-fx-text-fill: red;");
@@ -65,7 +65,7 @@ public class WebApiRemoteConnectionStateListener implements MainWindowListener {
 	private void createConnectionStateBinding() {
 		final List<PlayPadClient> clients = new ArrayList<>(WebApiPlugin$.MODULE$.connections().values());
 		connectedProperty.bind(Bindings.createIntegerBinding(() -> (int) WebApiPlugin$.MODULE$.connections().values().stream()
-						.filter(client -> client.getPlayPadConnectionState() != WebSocketState.OPEN)
+						.filter(client -> client.getPlayPadConnectionState() != PlayPadConnectionState.CONNECTED)
 						.count(),
 				clients.stream()
 						.map(PlayPadClient::playPadConnectionState)
@@ -75,7 +75,7 @@ public class WebApiRemoteConnectionStateListener implements MainWindowListener {
 
 	private void onIconClicked(MouseEvent event) {
 		WebApiPlugin$.MODULE$.connections().values().stream()
-				.filter(client -> client.getPlayPadConnectionState() != WebSocketState.OPEN)
+				.filter(client -> client.getPlayPadConnectionState() != PlayPadConnectionState.CONNECTED)
 				.forEach(client -> Worker.runLater(() -> {
 					try {
 						client.disconnect();
diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala
index 3a186c37..376d97de 100644
--- a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala
+++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala
@@ -95,6 +95,7 @@ object WebApiPlugin {
 				try {
 					val client = new PlayPadClientImpl(f"ws://${remote.getServerAddress}:${remote.getPort}/api")
 					WebApiPlugin.connections.put(remote, client)
+					client.playPadConnectionState.addListener((_, _, newValue) => println(f"State: ${remote.getName} \t $newValue"))
 					client.connect(5)
 					Logger.info(s"Connected to remote PlayWall: ${remote.getName}")
 				} catch {
diff --git a/pom.xml b/pom.xml
index b4ae690d..4e735ed3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
         <jackson-dataformat-csv.version>2.11.3</jackson-dataformat-csv.version>
 
         <spark-core.version>[2.9.3,)</spark-core.version>
-        <PlayWallWebApiClient.version>1.2.1</PlayWallWebApiClient.version>
+        <PlayWallWebApiClient.version>1.2.2</PlayWallWebApiClient.version>
 
         <jna.version>5.6.0</jna.version>
 
-- 
GitLab