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

refactor(transport): Consolidate transport interface #1002

Merged
merged 25 commits into from Sep 13, 2021
Merged

Conversation

delucis
Copy link
Member

@delucis delucis commented Sep 2, 2021

This PR refactors the transport interface to simplify the task of implementing new transports. (I’ve developed it out of the attempt at a peer-to-peer transport — I think eventually I’ll publish the P2P transport as a separate package.) This refactor moves various logic common to all transport implementations to the base Transport class and moves responsibility for interacting with the client’s Redux store to the client itself, making the transport “thinner”, primarily responsible for passing the master’s output to the client. It also renames some of the class methods to hopefully clarify their purpose.

Breaking Changes

If anyone had figured out how to write a custom transport, it will definitely break. I don’t know how likely that is as we don’t export many of the things you’d ideally need access to to create a custom transport.

Checklist

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

Pass options object to P2P transport to use when instantiating the `Peer` connection.
Previously, different transport implementations received a reference to the client’s Redux store and duplicated logic to map update data from the master to an action which they dispatched to the store. This centralises this in the client, keeping the store a client-only concept and exposing a single callback to transport implementations that expects to receive the same `TransportData` emitted by the master. In this way, transports should be “thinner”, focusing on implementing the glue between a client and a master.
- `onAction` → `sendAction`
- `onChatMessage` → `sendChatMessage`
Rename internal `callback` property to `connectionStatusCallback` to better describe purpose.
@delucis delucis changed the title feat(transport): Add peer-to-peer transport refactor(transport): Consolidate transport interface Sep 5, 2021
@delucis delucis marked this pull request as ready for review September 5, 2021 22:58
nicolodavis
nicolodavis previously approved these changes Sep 7, 2021
Copy link
Member

@nicolodavis nicolodavis left a comment

Choose a reason for hiding this comment

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

Thanks for fixing my terrible naming conventions :)

Looks good to me. I don't think we should be too concerned about this being a breaking change.

@delucis
Copy link
Member Author

delucis commented Sep 7, 2021

Haha, I’m not sure if they were terrible 😄

My guess was just that the original class organically grew beyond its initial scope. I guess I should maybe also rename subscribe to subscribeToConnectionStatus while I’m at it.

@nicolodavis
Copy link
Member

Haha, I’m not sure if they were terrible

My guess was just that the original class organically grew beyond its initial scope. I guess I should maybe also rename subscribe to subscribeToConnectionStatus while I’m at it.

Yeah, I think that would help distinguish it from subscribing to the game state.

@delucis delucis merged commit 510a082 into main Sep 13, 2021
@delucis delucis deleted the delucis/feat/p2p branch September 13, 2021 22:13
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.

None yet

2 participants