drashland/wocket

Multiuser in Deno-Deploy

nhrones opened this issue · 6 comments

Summary

What:
Deploy multi-region/isolate communication
Explain what the feature is
A way to bridge clients from multiple deploy isolates
Why:
WebSocket multi-player games or multi-region chat ...
Explain why this feature should be implemented
Current method is pinned to users on a single isolate.

Acceptance Criteria

??
Below is a list of tasks that must be completed before this issue can be closed.

  • Write documentation
  • Write unit tests
  • Write integration tests
  • {add more checkboxes required by this issue as needed}

Example Pseudo Code (for implementation)

Wocket >> BroadcastChannel >> Wocket
Syncronize Wocket collections/state accost isolates??

// Add example pseudo code for implementation

Hi @nhrones, I’m not entirely sure what you mean? It should support being used for a chat app or a multi player game, after all its just a matter of every client (eg each user in a chat or a game) sending a message to a single endpoint (the server)

Hello @ebebbington For Deno Deploy multiuser, even though each user connects using the same URL, they may end up on different region/isolates. The only way for them to connect is by way of BroadcastChannel.
My Dicegame faced this issue. When testing from Atlanta on my laptop, often one instance would deploy from us-east1 and another instance from us-east4. In this case the instances are actually on two separate servers(isolates). As you can see, it would be very difficult to synchronize clients/state across servers.
That is why I rewrote my app so all state/sync is at the client. I then couple each servers client-socket with a BroadcastChannel instance listening on the same channel. This effectively bridges all sockets in the same isolate, and all isolates on a single network.
see the slideshow: https://nhrones.github.io/DeployRtc/
My game has almost the same logic you use for Wocket Server in each instance. this keeps game state auto-synchronized.
See the game: https://rtc-dice-app-server.deno.dev/
I have a 4 player version of this game that uses just the WebSockets/BroadcastChannel (not the RtcDatachannel). This 4 player app suffers from the fact that Deploy isolates may disconnect at any time unexpectedly (A known issue). That is why I'm migrating to RtcDataChannels.

I just want to say, your Wocket is a very capable and well written lib. I have ported that game from Silverlight C# to Java, then to Node, and on to Deno. All using sockets. Yours is by far the best experience. I'm rewriting a version of my game to leverage Wocket, to run on a Deno-server, not Deploy-Isolate.

Ok I see what you mean, and that’s really great to hear :) would you mind showing how it could be possible using the BroadcastChannel API? Just a way to visualise the code a bit more, and we’re also welcome to PR’s if you wanted to attempt this yourself

After studying Wocket, I feel It would not be practical to add this. The issue would be synchronizing state between isolates. Your Client collect(Map) contains WebSocket instances. These could not be serialized to be duplicated on isolates.
Personally, I'm going to give up on using Deploy for real-time multiuser games. There are to many non-determinism issues with both the isolates and the sockets. I'll rewrite what I have to use Deno/Wocket on a hosting service.
Sorry for all the fuss.
Nick

no need to apologize @nhrones ! thank you for bringing up this issue. it's definitely an interesting one and personally i may come back to this (just to tinker around) since this is an area im unfamiliar with

No problems :) +1 with what crookse said as well