-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow multiplayer client creation to be overridden #246
allow multiplayer client creation to be overridden #246
Conversation
Can you describe a bit more what the alternative multiplayer client would do compared to the existing one? |
1 use libraries other then socket.io (which may have more robust connection support- including something like firebase-cloud-messaging) as I see it boardgame.io is conceptually 3 packages (at least):
I'm interested only in the first component (core logic), there is a good separation with the UI, but the multiplayer component is currently intertwined (and a good first step is just to allow for overriding it, maybe later there could be a clear interface for users to select between several multiplayer backends) (BTW another option is to provide a multiplayerClientFactory as a paramter, but I think clients with different Multiplayer behavior are of different types and inheritance better reflect that) |
Sounds good. I've been meaning to do this myself actually, so I'm glad you're taking the first step! I'd like to minimize any changes to the existing public API as much as possible. Will take a closer look later this week and send you more actionable feedback. |
@@ -134,7 +150,7 @@ class _ClientImpl { | |||
this.store = null; | |||
|
|||
if (multiplayer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just add a new option in the multiplayer
argument that allows specifying a custom client. Something like:
Client({
game: TicTacToe,
multiplayer: {
server: 'hostname:port',
clientImpl: <object>,
}
})
That way it's a tiny surgical change and the rest of the interface remains unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update as requested
Note that this interface does not reflect that serverUrl and socketOpt are parameters for a specific Multiplayer client type
18ebdad
to
e26a43e
Compare
server = multiplayer.server; | ||
} | ||
if ('clientImpl' in multiplayer) { | ||
MultiplayerClientImpl = multiplayer.clientImpl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we're missing a unit test that covers this line.
@nicolodavis closing this in favor of external transport refactor (still need GameMaster to be exported) |
Yep, sounds good. Will work on that. |
Checklist
master
).(I'm starting to experiment with an alternative multiplayer client, would be great if I could keep connection with source repo instead of forking it)
1- This allows inheritance by exposing Client class directly instead of wrapping a _ClientImpl.
2- 'new Multiplayer' is replace by a call to overridable function 'createMultiplayerClient'