Skip to content

Commit c309eb0

Browse files
committed
refactor(webeditor): replace the websocket client with reverb and http rpc
1 parent 836bb50 commit c309eb0

14 files changed

Lines changed: 1182 additions & 1306 deletions

pom.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<fastinv.version>3.1.2</fastinv.version>
3131
<jetbrains-annotations.version>26.1.0</jetbrains-annotations.version>
3232
<gson.version>2.14.0</gson.version>
33-
<java-websocket.version>1.6.0</java-websocket.version>
33+
<pusher-client.version>2.4.4</pusher-client.version>
3434
<hikaricp.version>7.1.0</hikaricp.version>
3535
<mysql-connector.version>26.7.0</mysql-connector.version>
3636
<itemsadder-api.version>4.0.10</itemsadder-api.version>
@@ -175,11 +175,12 @@
175175
<version>${fastinv.version}</version>
176176
</dependency>
177177

178-
<!-- Java-WebSocket, client connection to the web editor -->
178+
<!-- Pusher protocol client, subscribes to the web editor's Reverb channel.
179+
Pulls Java-WebSocket in transitively, which is why that relocation stays. -->
179180
<dependency>
180-
<groupId>org.java-websocket</groupId>
181-
<artifactId>Java-WebSocket</artifactId>
182-
<version>${java-websocket.version}</version>
181+
<groupId>com.pusher</groupId>
182+
<artifactId>pusher-java-client</artifactId>
183+
<version>${pusher-client.version}</version>
183184
</dependency>
184185

185186
<!-- MySQL sync -->
@@ -323,6 +324,7 @@
323324
<includes>
324325
<include>net.wesjd:anvilgui</include>
325326
<include>fr.mrmicky:fastinv</include>
327+
<include>com.pusher:pusher-java-client</include>
326328
<include>org.java-websocket:Java-WebSocket</include>
327329
<include>com.zaxxer:HikariCP</include>
328330
<include>com.mysql:mysql-connector-j</include>
@@ -345,6 +347,10 @@
345347
<pattern>org.java_websocket</pattern>
346348
<shadedPattern>net.blueva.menu.libraries.websocket</shadedPattern>
347349
</relocation>
350+
<relocation>
351+
<pattern>com.pusher</pattern>
352+
<shadedPattern>net.blueva.menu.libraries.pusher</shadedPattern>
353+
</relocation>
348354
</relocations>
349355
<filters>
350356
<filter>

src/main/java/net/blueva/menu/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import net.blueva.menu.managers.java.MenuManager;
1919
import net.blueva.menu.sync.MenuSyncService;
2020
import net.blueva.menu.webeditor.WebEditorManager;
21-
import net.blueva.menu.webeditor.WebEditorManager.WebEditorEnvironment;
21+
import net.blueva.menu.webeditor.WebEditorEnvironment;
2222
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
2323
import org.bukkit.Bukkit;
2424
import org.bukkit.ChatColor;

src/main/java/net/blueva/menu/common/dto/SessionDTO.java

Lines changed: 0 additions & 146 deletions
This file was deleted.

src/main/java/net/blueva/menu/common/protocol/MessageType.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main/java/net/blueva/menu/common/protocol/WebSocketMessage.java

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package net.blueva.menu.webeditor;
2+
3+
import com.google.gson.JsonObject;
4+
5+
/**
6+
* Reverb connection details, handed to the plugin when it registers and
7+
* refreshed on every heartbeat.
8+
*
9+
* @param key public application key of the Pusher protocol
10+
* @param host host serving the WebSocket endpoint
11+
* @param port port serving the WebSocket endpoint
12+
* @param useTls whether the endpoint is served over TLS
13+
* @param authEndpoint URL that authorises subscriptions to private channels
14+
*/
15+
public record RealtimeSettings(String key, String host, int port, boolean useTls, String authEndpoint) {
16+
17+
public static RealtimeSettings fromJson(JsonObject json) {
18+
if (json == null || !json.has("key") || json.get("key").isJsonNull()) {
19+
return null;
20+
}
21+
22+
String scheme = json.has("scheme") && !json.get("scheme").isJsonNull()
23+
? json.get("scheme").getAsString()
24+
: "https";
25+
26+
return new RealtimeSettings(
27+
json.get("key").getAsString(),
28+
json.has("host") && !json.get("host").isJsonNull() ? json.get("host").getAsString() : null,
29+
json.has("port") && !json.get("port").isJsonNull() ? json.get("port").getAsInt() : 443,
30+
"https".equalsIgnoreCase(scheme),
31+
json.has("authEndpoint") && !json.get("authEndpoint").isJsonNull()
32+
? json.get("authEndpoint").getAsString()
33+
: null
34+
);
35+
}
36+
37+
public boolean isUsable() {
38+
return key != null && !key.isBlank() && host != null && !host.isBlank() && authEndpoint != null;
39+
}
40+
}

0 commit comments

Comments
 (0)