Closed cBournhonesque closed 1 year ago
This is great! Will solve this issue: https://github.com/naia-lib/naia/issues/107
Hmm, after a bit more consideration, I really would like to go with another approach here.
I think the socket
crates should remain as is. If anything, I might like to return them to their own GitHub repo (it was like this a while ago, I took advice against my better judgement to combine them into this monorepo). They seem to perform very well as a single responsibility crate collection.
naia-socket
crates:
.. and that's it. Its only a transport layer implementation.
Now, naia_client
and naia_server
and other crates above that, I think should remain with the implementation you've come up with here. They could have webrtc_transport
, udp_transport
, quic_transport
, ect. feature flags.
Server.listen()
would be changed to fn listen<S: Into<Box<dyn naia_server::Socket>>>(socket: S)
and likewise
Client.connect()
would be changed to fn connect<S: Into<Box<dyn naia_client::Socket>>>(socket: S)
Then, like you've done, there would be, in both the client
and server
directories, a transports
directory with webrtc.rs
udp.rs
quic.rs
that contain the trait implementations for their respective sockets.
The key here is that naia_client
and naia_server
should be able to compile without any *_transport
feature flag enabled. I've really wanted to allow people to be able to swap out the transport layer with anything they want, even if it's defined in their own crate or a third party crate. I think this will be a better organization going forward, and I'd rather jump straight to my ideal.
Thank you for your effort on this, it'll help me jumpstart the process when I tackle this soon :+1:
The goal of this PR is to make naia compatible with any unreliable transport layer (WebRtc, UDP, QUIC).
This is accomplished by enabling feature-flags in the
naia-socket
crates.Transport layers will need to implement a couple things:
SocketConfig
object used to create aSocket
Socket
needs to implement all the methods that are currently implemented by the webrtc sockets (most notablylisten
,get_sender
andget_receiver
).(ideally there would be a trait, but it didn't seem worth the effort yet, it would be clearer once we actually try to bring a different transport layer)
Migration Guide
webrtc
is enabled by default.