diff --git a/build.gradle b/build.gradle
index f826fd1..7d793cf 100644
--- a/build.gradle
+++ b/build.gradle
@@ -17,7 +17,6 @@ repositories {
dependencies {
api 'org.java-websocket:Java-WebSocket:1.5.4'
compileOnly 'org.java-websocket:Java-WebSocket:1.5.4'
- implementation 'net.sourceforge.streamsupport:android-retrofuture:1.7.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.3'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.15.3'
implementation 'com.github.ben-manes.caffeine:jcache:3.1.5'
diff --git a/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/FXMLController.java b/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/FXMLController.java
index 22b8c4e..125bce8 100644
--- a/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/FXMLController.java
+++ b/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/FXMLController.java
@@ -1,20 +1,82 @@
package io.github.chronosxyz.JGUN.examples.chat;
+import io.github.chronosx88.JGUN.api.Gun;
+import io.github.chronosx88.JGUN.api.graph.ArrayBuilder;
+import io.github.chronosx88.JGUN.api.graph.NodeBuilder;
+import io.github.chronosx88.JGUN.models.graph.Node;
+import io.github.chronosx88.JGUN.models.graph.NodeValue;
+import io.github.chronosx88.JGUN.models.graph.values.ArrayValue;
+import io.github.chronosx88.JGUN.models.graph.values.NodeLinkValue;
+import io.github.chronosx88.JGUN.models.graph.values.StringValue;
+import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
-import javafx.scene.control.Label;
+import javafx.scene.control.Button;
+import javafx.scene.control.TextArea;
+import javafx.scene.control.TextField;
import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.ResourceBundle;
+import java.util.concurrent.ExecutionException;
public class FXMLController implements Initializable {
@FXML
- private Label label;
+ Button sendButton;
+
+ @FXML
+ TextArea chatBox;
+
+ @FXML
+ TextArea msgEditbox;
+
+ @FXML
+ TextField nicknameEditbox;
+
+ private Gun gun;
@Override
public void initialize(URL url, ResourceBundle rb) {
- String javaVersion = System.getProperty("java.version");
- String javafxVersion = System.getProperty("javafx.version");
- label.setText("Hello, JavaFX " + javafxVersion + "\nRunning on Java " + javaVersion + ".");
+ Platform.runLater(() -> {
+ gun.get("chat").map((k, v) -> {
+ if (!k.equals("messages")) return;
+ ArrayValue val = (ArrayValue) v;
+ val.getValue().forEach((e) -> {
+ if (e.getValueType() == NodeValue.ValueType.LINK) {
+ Node obj;
+ try {
+ obj = gun.get(((NodeLinkValue) e).getLink()).once().get().getData();
+ } catch (InterruptedException | ExecutionException ex) {
+ throw new RuntimeException(ex);
+ }
+ StringValue fromVal = (StringValue) obj.getValues().get("from");
+ StringValue msgVal = (StringValue) obj.getValues().get("text");
+ StringValue dateVal = (StringValue) obj.getValues().get("date");
+ chatBox.appendText(String.format("[%s] <%s> %s\n", dateVal.getValue(), fromVal.getValue(), msgVal.getValue()));
+ }
+ });
+ });
+ });
+
+ sendButton.setOnAction((e) -> {
+ try {
+ gun.get("chat")
+ .put(new NodeBuilder().add("messages", new ArrayBuilder()
+ .add(new NodeBuilder()
+ .add("date", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+ .format(Calendar.getInstance().getTime()))
+ .add("from", nicknameEditbox.getText())
+ .add("text", msgEditbox.getText()))).build())
+ .get();
+ } catch (InterruptedException | ExecutionException ex) {
+ throw new RuntimeException(ex);
+ }
+ msgEditbox.clear();
+ });
+ }
+
+ public void setGunInstance(Gun gun) {
+ this.gun = gun;
}
}
\ No newline at end of file
diff --git a/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/Gateway.java b/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/Gateway.java
new file mode 100644
index 0000000..81932e5
--- /dev/null
+++ b/examples/chat/src/main/java/io/github/chronosxyz/JGUN/examples/chat/Gateway.java
@@ -0,0 +1,14 @@
+package io.github.chronosxyz.JGUN.examples.chat;
+
+import io.github.chronosx88.JGUN.api.Gun;
+import io.github.chronosx88.JGUN.network.GatewayNetworkNode;
+import io.github.chronosx88.JGUN.storage.MemoryStorage;
+import io.github.chronosx88.JGUN.storage.Storage;
+
+public class Gateway {
+ public static void main(String[] args) throws InterruptedException {
+ Storage storage = new MemoryStorage();
+ GatewayNetworkNode peer = new GatewayNetworkNode(5054, storage);
+ Gun gun = new Gun(storage, peer);
+ }
+}
diff --git a/examples/chat/src/main/resources/io/github/chronosxyz/JGUN/examples/chat/scene.fxml b/examples/chat/src/main/resources/io/github/chronosxyz/JGUN/examples/chat/scene.fxml
index 00e0612..78a977f 100644
--- a/examples/chat/src/main/resources/io/github/chronosxyz/JGUN/examples/chat/scene.fxml
+++ b/examples/chat/src/main/resources/io/github/chronosxyz/JGUN/examples/chat/scene.fxml
@@ -1,10 +1,42 @@
-
-
+
+
+
-
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/io/github/chronosx88/JGUN/network/GatewayNetworkNode.java b/src/main/java/io/github/chronosx88/JGUN/network/GatewayNetworkNode.java
index 08b89f0..8a8e4c9 100644
--- a/src/main/java/io/github/chronosx88/JGUN/network/GatewayNetworkNode.java
+++ b/src/main/java/io/github/chronosx88/JGUN/network/GatewayNetworkNode.java
@@ -26,8 +26,8 @@ public class GatewayNetworkNode extends WebSocketServer implements Peer {
@Override
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
- if(conn != null) {
- System.out.println("Peer " + conn.getRemoteSocketAddress().toString() + " closed the connection for reason (code): " + reason + " (" + code + ")");
+ if (conn != null) {
+ System.out.println("Peer " + conn + " closed the connection for reason (code): " + reason + " (" + code + ")");
}
}
@@ -38,7 +38,7 @@ public class GatewayNetworkNode extends WebSocketServer implements Peer {
@Override
public void onError(WebSocket conn, Exception ex) {
- if(conn != null) {
+ if (conn != null) {
System.out.println("# Exception occurred on connection: " + conn.getRemoteSocketAddress());
}
ex.printStackTrace();
@@ -50,7 +50,7 @@ public class GatewayNetworkNode extends WebSocketServer implements Peer {
}
public void emit(String data) {
- for(WebSocket conn : this.getConnections()) {
+ for (WebSocket conn : this.getConnections()) {
conn.send(data);
}
}