Skip to content

Switch to websockets#133

Merged
Huskydog9988 merged 18 commits into
CivPlatform:mainfrom
Protonull:websockets
Apr 4, 2026
Merged

Switch to websockets#133
Huskydog9988 merged 18 commits into
CivPlatform:mainfrom
Protonull:websockets

Conversation

@Protonull

Copy link
Copy Markdown
Collaborator

This PR intends to replace the TCP connection with a websocket connection, which has various benefits like deferring framing to the websocket protocol, deferring encryption to TLS, etc.

@Protonull

Copy link
Copy Markdown
Collaborator Author

In terms of progress, I have been focusing on the client, but I have been battling perfectionism and scope creep. As you can see, the changes also include a refactor to the authentication process. But I have stashes that include changes to the config and the connection gui to better enforce contracts (eg: that sync addresses MUST be prefixed with ws:// or wss://). I'm also snagging on how to do state checking, reconnection, etc, thread-safely. Any help here would be appreciated.

Comment thread mapsync-server/pnpm-workspace.yaml
Huskydog9988 and others added 11 commits April 1, 2026 12:30
The point of all this hullabaloo is to prevent class-file collision. I believe Nexum uses the same websocket library? And who knows about other mods.

The reason for the library is that java.net.http's websocket client is just too finicky.
Basically, it became too much of a hassle. While I do think it's preferable to use Java's standard library, it's nonetheless too simple and too idiosyncratic.

For example, the each listener method takes a websocket parameter, implying an ability to use the same listener instance to manage multiple websockets, except that the interface provides no means to identify the passed-in websocket (such as its URI) without doing some nasty reflection. Nor does it provide a means to store relevant data onto the websocket instance (eg: the SyncClient or equivalent).

This could *potentially* be solved with mixins, but that's iffy and likely will not work since all the jdk internal classes are likely loaded before the mixin application process even happens.
Recomputing each sync connection on every chunk load was definitely a choice xD
@Protonull

Copy link
Copy Markdown
Collaborator Author

I believe it's approaching readiness for merging. Any testing and feedback would be appeciated.

@Huskydog9988

Copy link
Copy Markdown
Contributor

I've been unable to connect using the latest client and server builds together. The server doesn't even show a connect attempt, and I can't figure out why the client just seems to be voiding its attempt.

@Protonull

Copy link
Copy Markdown
Collaborator Author

When you switched the server over to websockets, you set the path to /ws, do you still have that set?

@Huskydog9988

Copy link
Copy Markdown
Contributor

Yep, I even disabled it on the server and tried again without it.

Stop using experimental type-erasure on dev script: we want development and production to resemble each other as closely as possible, except for debug logs, etc.
"test": "true",
"start": "node -r source-map-support/register dist/main.js",
"start:dev": "node --experimental-transform-types --inspect src/main.ts"
"start:dev": "node --inspect -r source-map-support/register dist/main.js"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the typescript config already disables any non ES native features, it is identical

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I switched it back because it randomly started refusing to start. No stacktrace or anything. I switched the start:dev script back and it worked. Odd.

I think I literally fell asleep while writing this...
@Protonull

Copy link
Copy Markdown
Collaborator Author

At this point I feel comfortable with merging it: there are some consequential changes I still need to make because of this, but they're outside the scope of this PR lest it become a near whole-mod refactor PR.

@Protonull Protonull marked this pull request as ready for review April 4, 2026 13:55
@Huskydog9988 Huskydog9988 merged commit b43def2 into CivPlatform:main Apr 4, 2026
3 checks passed
This was referenced Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants