diff --git a/README.md b/README.md index 13c466779d77cd5565b0ff5986f9ac5d452968a5..a82b1c55e2776aa1c90a6d880a87c6f32c8afc5f 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,13 @@ Or you can use Docker to build the native executable using: `./gradlew buildNati You can then execute your binary: `./build/machine-1.0.0-SNAPSHOT-runner` -If you want to learn more about building native executables, please consult https://quarkus.io/guides/gradle-tooling#building-a-native-executable . \ No newline at end of file +If you want to learn more about building native executables, please consult https://quarkus.io/guides/gradle-tooling#building-a-native-executable . + +## Websocket protocol: + +automaton/id/states (operation) [info] + +eg: + + automaton/id/states add q1 + automaton/id/name set "Cool Name" \ No newline at end of file diff --git a/build.gradle b/build.gradle index b497ad310fd18c2d29926933809e0e62ab84211a..22f2794a2a70aa5fe3dd6a811552878514392a09 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,7 @@ dependencies { implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") implementation 'io.quarkus:quarkus-resteasy' implementation 'io.quarkus:quarkus-resteasy-qute' + implementation 'io.quarkus:quarkus-jdbc-postgresql' testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io.rest-assured:rest-assured' diff --git a/src/main/java/org/un1qu3/endpoints/AutomatonSocket.java b/src/main/java/org/un1qu3/endpoints/AutomatonSocket.java new file mode 100644 index 0000000000000000000000000000000000000000..ae6aff071af2f6fac1c85c236a2cd0a4a44b8f4c --- /dev/null +++ b/src/main/java/org/un1qu3/endpoints/AutomatonSocket.java @@ -0,0 +1,64 @@ +package org.un1qu3.endpoints; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import javax.enterprise.context.ApplicationScoped; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint("/websocket") +@ApplicationScoped +public class AutomatonSocket { + + Map sessions = new ConcurrentHashMap<>(); + + @OnOpen + public void onOpen(Session session) { + String username = "Hans"; + sessions.put(username, session); + broadcast("User " + username + " joined"); + } + + @OnClose + public void onClose(Session session) { + String username = "Hans"; + sessions.remove(username); + broadcast("User " + username + " left"); + } + + @OnError + public void onError(Session session, Throwable throwable) { + String username = "Hans"; + sessions.remove(username); + broadcast("User " + username + " left on error: " + throwable); + } + + @OnMessage + public void onMessage(String message) { + String username = "Hans"; + String[] msg = message.split(" "); + if (msg[0].startsWith("automaton")) { + if (msg[1].contains("add")) {} + } + } + + private void broadcast(String message) { + sessions + .values() + .forEach( + s -> { + s.getAsyncRemote() + .sendObject( + message, + result -> { + if (result.getException() != null) { + System.out.println("Unable to send message: " + result.getException()); + } + }); + }); + } +} diff --git a/src/main/resources/META-INF/resources/index.html b/src/main/resources/META-INF/resources/index.html index 889f22f070e270e81c540e370561db32097e16d9..785e1748fa134789b9f3a62c29f5c65c28359507 100644 --- a/src/main/resources/META-INF/resources/index.html +++ b/src/main/resources/META-INF/resources/index.html @@ -1,152 +1,16 @@ - - machine - 1.0.0-SNAPSHOT - + + Aut0m4t0n // Alpha + - - - -
-
-

Congratulations, you have created a new Quarkus application.

- -

Why do you see this?

- -

This page is served by Quarkus. The source is in - src/main/resources/META-INF/resources/index.html.

- -

What can I do from here?

- -

If not already done, run the application in dev mode using: mvn compile quarkus:dev. -

-
    -
  • Add REST resources, Servlets, functions and other services in src/main/java.
  • -
  • Your static assets are located in src/main/resources/META-INF/resources.
  • -
  • Configure your application in src/main/resources/application.properties. -
  • -
- -

How do I get rid of this page?

-

Just delete the src/main/resources/META-INF/resources/index.html file.

-
-
-
-

Application

-
    -
  • GroupId: org.un1qu3
  • -
  • ArtifactId: machine
  • -
  • Version: 1.0.0-SNAPSHOT
  • -
  • Quarkus Version: 1.2.0.Final
  • -
-
- -
-
- - + + + \ No newline at end of file diff --git a/src/main/resources/META-INF/resources/main.css b/src/main/resources/META-INF/resources/main.css new file mode 100644 index 0000000000000000000000000000000000000000..234e7ffab07d2ed15aed93e139c27224041bdec8 --- /dev/null +++ b/src/main/resources/META-INF/resources/main.css @@ -0,0 +1,40 @@ +* { + margin: 0; + padding: 0; +} + +@media (prefers-color-scheme: dark) { + :root { + --main-bg-color: black; + --main-ac-color: #212121; + --main-color: whitesmoke; + --toolbar-height: 2vh; + } +} + +ul { + list-style-type: none; + overflow: hidden; + background-color: var(--main-bg-color); +} + +li { + float: left; +} + +li a { + display: block; + color: var(--main-color); + text-align: center; + padding: var(--toolbar-height); + text-decoration: none; +} + +li a:hover { + background-color: var(--main-ac-color); +} + +canvas { + width: 100%; + height: 80%; +} \ No newline at end of file diff --git a/src/main/resources/META-INF/resources/main.js b/src/main/resources/META-INF/resources/main.js new file mode 100644 index 0000000000000000000000000000000000000000..14164b19d75e9f7efae0c5bebcc56f4e293d64e1 --- /dev/null +++ b/src/main/resources/META-INF/resources/main.js @@ -0,0 +1,9 @@ +let canvas = document.getElementsByTagName('canvas')[0]; +canvas.height = 80; +canvas.width = canvas.style.width; + +let webSocket = new WebSocket( + 'ws://' + window.location.host + "/websocket"); +webSocket.onopen = function (event) { + console.log("Socket connected") +}; \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3c1ac56a1ad0a80f8c75a56e1c2d8d5e76060e1e..e41bf5ec6fb5ffead7858b8e0887160a110498af 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,7 @@ # Configuration file -# key = value \ No newline at end of file +quarkus.datasource.url=jdbc:postgresql://localhost:5432/hibernate_db +quarkus.datasource.driver=org.postgresql.Driver +quarkus.datasource.username=root +quarkus.datasource.password=test123 +# drop and create the database at startup (use `update` to only update the schema) +quarkus.hibernate-orm.database.generation=update \ No newline at end of file