From 947182f3239256b5eef91c9214f15b6ddbc808f4 Mon Sep 17 00:00:00 2001 From: Lost-Fly <114507453+Lost-Fly@users.noreply.github.com> Date: Sun, 31 Mar 2024 10:01:30 +0500 Subject: [PATCH] FUlly rearranged WS client logic, ws interaction removed from core src, initialize while app created --- .../{ => client}/AndroidLauncher.java | 0 .../packandgo/client/MessageProcessor.java | 2 + .../packandgo/client/dto/InputStateImpl.java | 2 + .../client/ws/EventListenerCallback.java | 2 + .../packandgo/client/ws/WebSocketClient.java | 10 +-- .../client/ws/WebSocketListener.java | 0 .../packandgo/client/ws/WsEvent.java | 0 assets/env.properties | 0 .../aqwsxlostfly/packandgo/InputState.java | 2 + .../aqwsxlostfly/packandgo/MessageSender.java | 2 + .../packandgo/TouchProcessor.java | 2 + .../aqwsxlostfly/packandgo/client/ssd.java | 4 - .../packandgo/client/ws/WebSocketClient.java | 88 ------------------- 13 files changed, 15 insertions(+), 99 deletions(-) rename android/src/com/aqwsxlostfly/packandgo/{ => client}/AndroidLauncher.java (100%) create mode 100644 android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java create mode 100644 android/src/com/aqwsxlostfly/packandgo/client/dto/InputStateImpl.java create mode 100644 android/src/com/aqwsxlostfly/packandgo/client/ws/EventListenerCallback.java rename core/src/com/aqwsxlostfly/packandgo/client/ws/NewWebSocket.java => android/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketClient.java (74%) rename {core => android}/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketListener.java (100%) rename {core => android}/src/com/aqwsxlostfly/packandgo/client/ws/WsEvent.java (100%) create mode 100644 assets/env.properties create mode 100644 core/src/com/aqwsxlostfly/packandgo/InputState.java create mode 100644 core/src/com/aqwsxlostfly/packandgo/MessageSender.java create mode 100644 core/src/com/aqwsxlostfly/packandgo/TouchProcessor.java delete mode 100644 core/src/com/aqwsxlostfly/packandgo/client/ssd.java delete mode 100644 core/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketClient.java diff --git a/android/src/com/aqwsxlostfly/packandgo/AndroidLauncher.java b/android/src/com/aqwsxlostfly/packandgo/client/AndroidLauncher.java similarity index 100% rename from android/src/com/aqwsxlostfly/packandgo/AndroidLauncher.java rename to android/src/com/aqwsxlostfly/packandgo/client/AndroidLauncher.java diff --git a/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java b/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java new file mode 100644 index 0000000..0e4ff51 --- /dev/null +++ b/android/src/com/aqwsxlostfly/packandgo/client/MessageProcessor.java @@ -0,0 +1,2 @@ +package com.aqwsxlostfly.packandgo.client;public class MessageProcessor { +} diff --git a/android/src/com/aqwsxlostfly/packandgo/client/dto/InputStateImpl.java b/android/src/com/aqwsxlostfly/packandgo/client/dto/InputStateImpl.java new file mode 100644 index 0000000..b1b0cd6 --- /dev/null +++ b/android/src/com/aqwsxlostfly/packandgo/client/dto/InputStateImpl.java @@ -0,0 +1,2 @@ +package com.aqwsxlostfly.packandgo.client.dto;public interface InputStateImpl { +} diff --git a/android/src/com/aqwsxlostfly/packandgo/client/ws/EventListenerCallback.java b/android/src/com/aqwsxlostfly/packandgo/client/ws/EventListenerCallback.java new file mode 100644 index 0000000..32cb157 --- /dev/null +++ b/android/src/com/aqwsxlostfly/packandgo/client/ws/EventListenerCallback.java @@ -0,0 +1,2 @@ +package com.aqwsxlostfly.packandgo.client.ws;public class EventListenerCallback { +} diff --git a/core/src/com/aqwsxlostfly/packandgo/client/ws/NewWebSocket.java b/android/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketClient.java similarity index 74% rename from core/src/com/aqwsxlostfly/packandgo/client/ws/NewWebSocket.java rename to android/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketClient.java index 5a55be5..57f4c8f 100644 --- a/core/src/com/aqwsxlostfly/packandgo/client/ws/NewWebSocket.java +++ b/android/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketClient.java @@ -4,34 +4,30 @@ import org.java_websocket.client.WebSocketClient; import org.java_websocket.handshake.ServerHandshake; + import java.net.URI; public class NewWebSocket extends WebSocketClient { - private WebSocketListener webSocketListener; + private WebSocketListener webSocketListener; public NewWebSocket(URI serverUri, WebSocketListener webSocketListener) { - super(serverUri); this.webSocketListener = webSocketListener; - } @Override public void onOpen(ServerHandshake handshake) { webSocketListener.onConnect(handshake); - Gdx.app.log("CONNECTION CREATED", "On connect"); } @Override public void onClose(int code, String reason, boolean remote) { - webSocketListener.onClose(code,reason); - Gdx.app.log("CONNECTION CLOSED", " code: " + code + " reason: " + reason); + webSocketListener.onClose(code, reason); } @Override public void onMessage(String message) { webSocketListener.onMessageReceived(message); - Gdx.app.log("MESSAGE RECEIVED", message); } @Override diff --git a/core/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketListener.java b/android/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketListener.java similarity index 100% rename from core/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketListener.java rename to android/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketListener.java diff --git a/core/src/com/aqwsxlostfly/packandgo/client/ws/WsEvent.java b/android/src/com/aqwsxlostfly/packandgo/client/ws/WsEvent.java similarity index 100% rename from core/src/com/aqwsxlostfly/packandgo/client/ws/WsEvent.java rename to android/src/com/aqwsxlostfly/packandgo/client/ws/WsEvent.java diff --git a/assets/env.properties b/assets/env.properties new file mode 100644 index 0000000..e69de29 diff --git a/core/src/com/aqwsxlostfly/packandgo/InputState.java b/core/src/com/aqwsxlostfly/packandgo/InputState.java new file mode 100644 index 0000000..14a516a --- /dev/null +++ b/core/src/com/aqwsxlostfly/packandgo/InputState.java @@ -0,0 +1,2 @@ +package com.aqwsxlostfly.packandgo;public interface InputState { +} diff --git a/core/src/com/aqwsxlostfly/packandgo/MessageSender.java b/core/src/com/aqwsxlostfly/packandgo/MessageSender.java new file mode 100644 index 0000000..0ea8008 --- /dev/null +++ b/core/src/com/aqwsxlostfly/packandgo/MessageSender.java @@ -0,0 +1,2 @@ +package com.aqwsxlostfly.packandgo;public class MessageSender { +} diff --git a/core/src/com/aqwsxlostfly/packandgo/TouchProcessor.java b/core/src/com/aqwsxlostfly/packandgo/TouchProcessor.java new file mode 100644 index 0000000..57ee67d --- /dev/null +++ b/core/src/com/aqwsxlostfly/packandgo/TouchProcessor.java @@ -0,0 +1,2 @@ +package com.aqwsxlostfly.packandgo;public class TouchProcessor { +} diff --git a/core/src/com/aqwsxlostfly/packandgo/client/ssd.java b/core/src/com/aqwsxlostfly/packandgo/client/ssd.java deleted file mode 100644 index 544117e..0000000 --- a/core/src/com/aqwsxlostfly/packandgo/client/ssd.java +++ /dev/null @@ -1,4 +0,0 @@ -//package com.aqwsxlostfly.packandgo.client; -// -//public class ssd { -//} diff --git a/core/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketClient.java b/core/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketClient.java deleted file mode 100644 index 6adcc57..0000000 --- a/core/src/com/aqwsxlostfly/packandgo/client/ws/WebSocketClient.java +++ /dev/null @@ -1,88 +0,0 @@ -//package com.aqwsxlostfly.packandgo.client.ws; -// -// -//import com.badlogic.gdx.Gdx; -//import com.badlogic.gdx.Net; -//import com.badlogic.gdx.net.Socket; -//import com.badlogic.gdx.net.SocketHints; -// -//import java.io.BufferedReader; -//import java.io.IOException; -//import java.io.InputStreamReader; -// -//public class WebSocketClient { -// private Socket socket; -// private final String serverUrl; -// -// private final Integer serverPort; -// -// private WebSocketListener webSocketListener; -// -// public WebSocketClient(String serverUrl, Integer serverPort) { -// this.serverPort = serverPort; -// this.serverUrl = serverUrl; -// } -// -// public void addWebSocketListener(WebSocketListener webSocketListener){ -// this.webSocketListener = webSocketListener; -// } -// -// -// public void connect() { -// -// SocketHints hints = new SocketHints(); -// hints.connectTimeout = 15000; -// hints.socketTimeout = 15000; -// -//// hints.tcpNoDelay = true; -// -// socket = Gdx.net.newClientSocket(Net.Protocol.TCP, serverUrl, serverPort, null); -// -// if (socket != null) { -// webSocketListener.onConnect("Connection opened"); -// } -// -// new Thread(new Runnable() { -// @Override -// public void run() { -// if (socket != null) { -// try { -// BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); -// String message; -// while ((message = reader.readLine()) != null) { -// webSocketListener.onMessageReceived(message); -// } -// } catch (IOException e) { -// e.printStackTrace(); -// } finally { -// close(); -// } -// } -// } -// }).start(); -// } -// -// public void sendMessage(String message) { -// if (socket != null && socket.isConnected()) { -// try { -// Gdx.app.log("CLIENT SEND", " send: " + message); -// -// byte[] messageBytes = message.getBytes("UTF-8"); -// socket.getOutputStream().write(messageBytes); -// socket.getOutputStream().flush(); -// -// } catch (IOException e) { -// Gdx.app.error("WebSocket Error", "Failed to send message: " + message, e); -// } -// } else { -// Gdx.app.error("WebSocket Error", "Socket is null or not connected"); -// } -// } -// -// public void close() { -// if (socket != null) { -// webSocketListener.onClose(code, "Connection closed"); -// socket.dispose(); -// } -// } -//}