diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 1bc9cd60b1eb1d58c548ce5bcb6d53be55126369..cfb629fb5ccc38ed3b8c37eff76828314cfba5c0 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -12,6 +12,7 @@ <file url="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginMedia" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginNativeAudio" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginPlayoutLog" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginWebAPI" charset="UTF-8" /> <file url="PROJECT" charset="UTF-8" /> </component> </project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 9bd9790077c9b6f7e6f963b7e4e736cd5919dfff..71a1574f2f6df494b2028c78bb51cb89fc3ba39e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -12,6 +12,7 @@ <module fileurl="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginMedia/PlayWallPluginMedia.iml" filepath="$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginMedia/PlayWallPluginMedia.iml" /> <module fileurl="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginNativeAudio/PlayWallPluginNativeAudio.iml" filepath="$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginNativeAudio/PlayWallPluginNativeAudio.iml" /> <module fileurl="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginPlayoutLog/PlayWallPluginPlayoutLog.iml" filepath="$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginPlayoutLog/PlayWallPluginPlayoutLog.iml" /> + <module fileurl="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginWebAPI/PlayWallPluginWebAPI.iml" filepath="$PROJECT_DIR$/PlayWallPlugins/PlayWallPluginWebAPI/PlayWallPluginWebAPI.iml" /> <module fileurl="file://$PROJECT_DIR$/PlayWallPlugins/PlayWallPlugins.iml" filepath="$PROJECT_DIR$/PlayWallPlugins/PlayWallPlugins.iml" /> </modules> </component> diff --git a/PlayWallCore/pom.xml b/PlayWallCore/pom.xml index b9e117a433c4d27b06cec2f38d6eecfb1f8e4917..7bb61491c137ce3bbf756b96e478fe2b6b135d69 100644 --- a/PlayWallCore/pom.xml +++ b/PlayWallCore/pom.xml @@ -22,6 +22,10 @@ <groupId>de.thecodelabs</groupId> <artifactId>libLogger</artifactId> </dependency> + <dependency> + <groupId>de.thecodelabs</groupId> + <artifactId>libLogger-slf4j</artifactId> + </dependency> <dependency> <groupId>de.thecodelabs</groupId> <artifactId>libPlugins-core</artifactId> @@ -36,13 +40,6 @@ <version>${versionizer-api.version}</version> </dependency> - <!-- PDF--> - <dependency> - <groupId>com.itextpdf</groupId> - <artifactId>itextpdf</artifactId> - <version>${itextpdf.version}</version> - </dependency> - <!--Audio--> <dependency> <groupId>javazoom</groupId> @@ -112,6 +109,21 @@ <scope>test</scope> </dependency> + <!-- Plugin Dependencies --> + + <!-- PDF--> + <dependency> + <groupId>com.itextpdf</groupId> + <artifactId>itextpdf</artifactId> + <version>${itextpdf.version}</version> + </dependency> + + <!--Spark--> + <dependency> + <groupId>com.sparkjava</groupId> + <artifactId>spark-core</artifactId> + <version>${spark-core.version}</version> + </dependency> </dependencies> <distributionManagement> @@ -149,5 +161,4 @@ </snapshots> </repository> </repositories> - </project> \ No newline at end of file diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/pom.xml b/PlayWallPlugins/PlayWallPluginWebAPI/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..5433e8b85a3ef0fea67651a48bcff7ac91d1fb5b --- /dev/null +++ b/PlayWallPlugins/PlayWallPluginWebAPI/pom.xml @@ -0,0 +1,137 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + 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> + <version>6.2.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>PlayWallPluginWebAPI</artifactId> + + <properties> + <project.outputDirectory>../../build/${project.version}</project.outputDirectory> + <project.artifactName>${project.artifactId}-v${project.version}</project.artifactName> + </properties> + + <dependencies> + <dependency> + <groupId>de.tobias.playpad</groupId> + <artifactId>PlayWallCore</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>com.sparkjava</groupId> + <artifactId>spark-core</artifactId> + <version>${spark-core.version}</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>de.thecodelabs</groupId> + <artifactId>versionizer-maven-plugin</artifactId> + <version>1.0.1</version> + <configuration> + <resourceFile>plugin.yml</resourceFile> + </configuration> + <executions> + <execution> + <id>resource-fill</id> + <goals> + <goal>resource-fill</goal> + </goals> + <phase>compile</phase> + </execution> + </executions> + </plugin> + + <!--Scala Plugin--> + <plugin> + <groupId>net.alchim31.maven</groupId> + <artifactId>scala-maven-plugin</artifactId> + <executions> + <execution> + <id>scala-compile-first</id> + <phase>process-resources</phase> + <goals> + <goal>add-source</goal> + <goal>compile</goal> + </goals> + </execution> + <execution> + <id>scala-test-compile</id> + <phase>process-test-resources</phase> + <goals> + <goal>testCompile</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.1.1</version> + <configuration> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + <outputDirectory>${project.outputDirectory}</outputDirectory> + <finalName>${project.artifactName}</finalName> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + <executions> + <execution> + <id>assemble-all</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <distributionManagement> + <repository> + <id>release</id> + <name>TheCodeLabs-releases</name> + <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-release</url> + </repository> + <snapshotRepository> + <id>snapshots</id> + <name>TheCodeLabs-snapshots</name> + <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-snapshots</url> + </snapshotRepository> + </distributionManagement> + + <repositories> + <repository> + <id>release</id> + <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-release</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + <repository> + <id>snapshots</id> + <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-snapshots</url> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + +</project> \ No newline at end of file diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin.yml b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin.yml new file mode 100644 index 0000000000000000000000000000000000000000..20f98f590f65c3d60a2b38426294a052e816413b --- /dev/null +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +main: "de.tobias.playpad.plugin.api.WebApiPlugin" +name: "WebApiPlugin" +artifactId: "${pom.artifactId}" +groupId: "${pom.groupId}" +version: "${pom.version}" +build: 1 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 new file mode 100644 index 0000000000000000000000000000000000000000..a971e03651a2f00a875051a94c15195ec74b1714 --- /dev/null +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/WebApiPlugin.scala @@ -0,0 +1,22 @@ +package de.tobias.playpad.plugin.api + +import de.thecodelabs.logger.Logger +import de.thecodelabs.plugins.{Plugin, PluginDescriptor} +import de.tobias.playpad.plugin.api.websocket.WebSocketHandler +import spark.Spark + +class WebApiPlugin extends Plugin { + override def startup(pluginDescriptor: PluginDescriptor): Unit = { + Logger.debug("Enable Web API Plugin") + + Spark.port(9876) + Spark.webSocket("/api", classOf[WebSocketHandler]) + Spark.get("/", (_, _) => "PlayWall API") + } + + override def shutdown(): Unit = { + Logger.debug("Disable Web API Plugin") + + Spark.stop() + } +} diff --git a/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/WebSocketHandler.scala b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/WebSocketHandler.scala new file mode 100644 index 0000000000000000000000000000000000000000..aa71195b1d21b5a51841ae1be0d546583fcc63a6 --- /dev/null +++ b/PlayWallPlugins/PlayWallPluginWebAPI/src/main/scala/de/tobias/playpad/plugin/api/websocket/WebSocketHandler.scala @@ -0,0 +1,31 @@ +package de.tobias.playpad.plugin.api.websocket + +import java.util.concurrent.ConcurrentLinkedQueue + +import de.thecodelabs.logger.Logger +import org.eclipse.jetty.websocket.api.Session +import org.eclipse.jetty.websocket.api.annotations._ + +@WebSocket +class WebSocketHandler { + + private val sessions = new ConcurrentLinkedQueue[Session] + + @OnWebSocketConnect def connected(session: Session): Unit = { + Logger.debug("WebSocket Client connected") + sessions.add(session) + } + + @OnWebSocketClose def closed(session: Session, statusCode: Int, reason: String): Unit = { + Logger.debug("WebSocket Client disconnected") + sessions.remove(session) + } + + @OnWebSocketMessage def onRead(session: Session, message: String): Unit = { + Logger.debug("Read from WebSocket: {0}", message) + } + + @OnWebSocketError def onError(session: Session, error: Throwable): Unit = { + Logger.warning(error.getMessage) + } +} diff --git a/PlayWallPlugins/pom.xml b/PlayWallPlugins/pom.xml index 2a798907fbd602dc6499d7aa0f900ad4e5c23727..5ecdd6e1e870c2fee03c0c4277738800b43c8787 100644 --- a/PlayWallPlugins/pom.xml +++ b/PlayWallPlugins/pom.xml @@ -19,6 +19,7 @@ <module>PlayWallPluginMedia</module> <module>PlayWallPluginNativeAudio</module> <module>PlayWallPluginPlayoutLog</module> + <module>PlayWallPluginWebAPI</module> </modules> </project> \ No newline at end of file diff --git a/pom.xml b/pom.xml index c69623941b191668ef39e4bfed49c653f4c6faaf..96417509105f159c01fd85019b4d1c04a8cb9b05 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,8 @@ <itextpdf.version>5.5.13</itextpdf.version> + <spark-core.version>[2.9.0,)</spark-core.version> + <jna.version>5.2.0</jna.version> <scala-library.version>2.13.0</scala-library.version>