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
Conversation
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`
…ack to base class
Rename internal `callback` property to `connectionStatusCallback` to better describe purpose.
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.
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.
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 |
Yeah, I think that would help distinguish it from subscribing to the game state. |
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
main
).