From 0bb4becfc40bfb6b4d5a541535d936b3e6114989 Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Sat, 20 Nov 2021 19:47:53 +0100 Subject: [PATCH] #174 - Add PlayWallClient api --- PlayWallPlugins/PlayWallPluginWebAPI/pom.xml | 7 ++++++- .../playpad/plugin/api/WebApiPlugin.scala | 20 ++++++++++++++++++- pom.xml | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/pom.xml b/PlayWallPlugins/PlayWallPluginWebAPI/pom.xml index 25c4656c..d214e0fe 100644 --- a/PlayWallPlugins/PlayWallPluginWebAPI/pom.xml +++ b/PlayWallPlugins/PlayWallPluginWebAPI/pom.xml @@ -3,8 +3,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> - <artifactId>PlayWallPlugins</artifactId> <groupId>de.tobias.playpad</groupId> + <artifactId>PlayWallPlugins</artifactId> <version>7.2.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> @@ -29,6 +29,11 @@ <artifactId>spark-core</artifactId> <version>${spark-core.version}</version> </dependency> + <dependency> + <groupId>de.tobias.playpad</groupId> + <artifactId>PlayWallWebApiClient</artifactId> + <version>${PlayWallWebApiClient.version}</version> + </dependency> </dependencies> <build> 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 986fd6bb..23e9900a 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 @@ -6,15 +6,18 @@ import de.thecodelabs.plugins.versionizer.PluginArtifact import de.thecodelabs.storage.settings.{Storage, StorageTypes} import de.thecodelabs.utils.application.ApplicationUtils import de.thecodelabs.utils.application.container.PathType +import de.thecodelabs.utils.threading.Worker import de.thecodelabs.utils.util.Localization import de.tobias.playpad.PlayPadPlugin -import de.tobias.playpad.plugin.api.settings.{WebApiSettings, WebApiSettingsViewController} +import de.tobias.playpad.api.{PlayPadClient, PlayPadClientImpl} +import de.tobias.playpad.plugin.api.settings.{WebApiRemoteSettings, WebApiSettings, WebApiSettingsViewController} import de.tobias.playpad.plugin.api.websocket.WebSocketHandler import de.tobias.playpad.plugin.api.websocket.listener.{PadStatusListener, ProjectListener} import de.tobias.playpad.plugin.{Module, PlayPadPluginStub} import spark.{Request, Response, Spark} import java.nio.file.{Files, Path} +import java.util class WebApiPlugin extends PlayPadPluginStub with PluginArtifact { @@ -45,6 +48,19 @@ class WebApiPlugin extends PlayPadPluginStub with PluginArtifact { Logger.info(f"Start WebAPI on port ${webApiSettings.getPort}") } + webApiSettings.getRemoteSettings.forEach(remote => { + Worker.runLater(() => { + try { + val client = new PlayPadClientImpl(f"ws://${remote.getServerAddress}:${remote.getPort}/api") + WebApiPlugin.connections.put(remote, client) + client.connect(5) + Logger.info(s"Connected to remote PlayWall: ${remote.getName}") + } catch { + case e: Exception => Logger.error(e) + } + }) + }) + PlayPadPlugin.getInstance().addGlobalSettingsTab(() => new WebApiSettingsViewController(webApiSettings)) Localization.addResourceBundle("plugin/webapi/lang/base", getClass.getClassLoader) } @@ -60,4 +76,6 @@ class WebApiPlugin extends PlayPadPluginStub with PluginArtifact { object WebApiPlugin { def getWebApiSettingsPath: Path = ApplicationUtils.getApplication.getPath(PathType.CONFIGURATION, "webapi.json") + + var connections: util.Map[WebApiRemoteSettings, PlayPadClient] = new util.HashMap() } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 177d22c7..31dcf934 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ <jackson-dataformat-csv.version>2.11.3</jackson-dataformat-csv.version> <spark-core.version>[2.9.0,)</spark-core.version> + <PlayWallWebApiClient.version>1.0.2</PlayWallWebApiClient.version> <jna.version>5.6.0</jna.version> -- GitLab