Skip to content
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

Closed

Conversation

amitport
Copy link
Contributor

@amitport amitport commented Aug 1, 2018

Checklist

  • Use a separate branch in your local repo (not master).
  • Test coverage is 100% (or you have a story for why it's ok).

(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'

@nicolodavis
Copy link
Member

Can you describe a bit more what the alternative multiplayer client would do compared to the existing one?

@amitport
Copy link
Contributor Author

amitport commented Aug 1, 2018

1 use libraries other then socket.io (which may have more robust connection support- including something like firebase-cloud-messaging)
2 local multiplayer - client side server (for testing / tutorials / debugging / developing)

as I see it boardgame.io is conceptually 3 packages (at least):

  • 1 core logic where the biggest value is providing a (hopefully, eventually) poplar standard
  • 2 ui / react client
  • 3 multiplayer game session manager

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)

@nicolodavis
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

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

@amitport amitport force-pushed the overridable-multiplayer-client branch from 18ebdad to e26a43e Compare August 4, 2018 09:10
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) to 99.93% when pulling e26a43e on amitport:overridable-multiplayer-client into 1a90e7f on google:master.

server = multiplayer.server;
}
if ('clientImpl' in multiplayer) {
MultiplayerClientImpl = multiplayer.clientImpl;
Copy link
Member

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.

This was referenced Aug 8, 2018
@amitport
Copy link
Contributor Author

@nicolodavis closing this in favor of external transport refactor (still need GameMaster to be exported)

@amitport amitport closed this Aug 26, 2018
@nicolodavis
Copy link
Member

Yep, sounds good. Will work on that.

@nicolodavis
Copy link
Member

Relevant commits (that will be included in the next release):
d7a1213
137dd7c

@amitport amitport deleted the overridable-multiplayer-client branch October 30, 2019 12:22
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.

3 participants