Skip to content
Snippets Groups Projects
Commit 0bb4becf authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

#174 - Add PlayWallClient api

parent cda10c54
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>PlayWallPlugins</artifactId>
<groupId>de.tobias.playpad</groupId> <groupId>de.tobias.playpad</groupId>
<artifactId>PlayWallPlugins</artifactId>
<version>7.2.0-SNAPSHOT</version> <version>7.2.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
<artifactId>spark-core</artifactId> <artifactId>spark-core</artifactId>
<version>${spark-core.version}</version> <version>${spark-core.version}</version>
</dependency> </dependency>
<dependency>
<groupId>de.tobias.playpad</groupId>
<artifactId>PlayWallWebApiClient</artifactId>
<version>${PlayWallWebApiClient.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -6,15 +6,18 @@ import de.thecodelabs.plugins.versionizer.PluginArtifact ...@@ -6,15 +6,18 @@ import de.thecodelabs.plugins.versionizer.PluginArtifact
import de.thecodelabs.storage.settings.{Storage, StorageTypes} import de.thecodelabs.storage.settings.{Storage, StorageTypes}
import de.thecodelabs.utils.application.ApplicationUtils import de.thecodelabs.utils.application.ApplicationUtils
import de.thecodelabs.utils.application.container.PathType import de.thecodelabs.utils.application.container.PathType
import de.thecodelabs.utils.threading.Worker
import de.thecodelabs.utils.util.Localization import de.thecodelabs.utils.util.Localization
import de.tobias.playpad.PlayPadPlugin 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.WebSocketHandler
import de.tobias.playpad.plugin.api.websocket.listener.{PadStatusListener, ProjectListener} import de.tobias.playpad.plugin.api.websocket.listener.{PadStatusListener, ProjectListener}
import de.tobias.playpad.plugin.{Module, PlayPadPluginStub} import de.tobias.playpad.plugin.{Module, PlayPadPluginStub}
import spark.{Request, Response, Spark} import spark.{Request, Response, Spark}
import java.nio.file.{Files, Path} import java.nio.file.{Files, Path}
import java.util
class WebApiPlugin extends PlayPadPluginStub with PluginArtifact { class WebApiPlugin extends PlayPadPluginStub with PluginArtifact {
...@@ -45,6 +48,19 @@ 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}") 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)) PlayPadPlugin.getInstance().addGlobalSettingsTab(() => new WebApiSettingsViewController(webApiSettings))
Localization.addResourceBundle("plugin/webapi/lang/base", getClass.getClassLoader) Localization.addResourceBundle("plugin/webapi/lang/base", getClass.getClassLoader)
} }
...@@ -60,4 +76,6 @@ class WebApiPlugin extends PlayPadPluginStub with PluginArtifact { ...@@ -60,4 +76,6 @@ class WebApiPlugin extends PlayPadPluginStub with PluginArtifact {
object WebApiPlugin { object WebApiPlugin {
def getWebApiSettingsPath: Path = ApplicationUtils.getApplication.getPath(PathType.CONFIGURATION, "webapi.json") 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
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
<jackson-dataformat-csv.version>2.11.3</jackson-dataformat-csv.version> <jackson-dataformat-csv.version>2.11.3</jackson-dataformat-csv.version>
<spark-core.version>[2.9.0,)</spark-core.version> <spark-core.version>[2.9.0,)</spark-core.version>
<PlayWallWebApiClient.version>1.0.2</PlayWallWebApiClient.version>
<jna.version>5.6.0</jna.version> <jna.version>5.6.0</jna.version>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment