-
Notifications
You must be signed in to change notification settings - Fork 102
#13: scoped rooms #19
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
Conversation
disclaimer:
|
matchbox_server/src/signaling.rs
Outdated
@@ -37,11 +37,22 @@ type PeerRequest = matchbox::PeerRequest<serde_json::Value>; | |||
type PeerEvent = matchbox::PeerEvent<serde_json::Value>; | |||
|
|||
#[derive(Debug, Clone, PartialEq, Eq)] | |||
pub(crate) enum RequestedRoom { | |||
pub(crate) enum RoomType { |
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.
I renamed that so it can easily be embedded in a more customizable struct RequestedRoom
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.
Hey, sorry, I didn't actually see the pr earlier today when I commented on #13.
As discussed I feel like having the next_n functionality an optional query parameter makes a lot of sense, so the API would be
wss://match.example.com/{id}?next={n}
Especially if we'd want to tuck on other features as well in query parameters. There isn't much reason to treat the next_n rooms like a special citizen.
One question though, is what we do if one peer tries to connect to
wss://match.example.com/abcd?next=2
while somebody else tries to connect to
wss://match.example.com/abcd
I guess we'd have to make the query parameter part of the key for the room? Idk, I'm open to suggestions here.
Yeah I think a I'm working on it :) |
…ging together and
@@ -453,8 +463,159 @@ mod tests { | |||
} | |||
} | |||
|
|||
#[tokio::test] | |||
async fn match_different_id_same_next() { |
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.
here we check
- player a -> scope_1?next=2
- player b -> scope_2?next=2
- player c -> scope_1?next=2
- player d -> scope_2?next=2
} | ||
} | ||
#[tokio::test] | ||
async fn match_same_id_different_next() { |
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.
here we check
- player a -> scope_1?next=2
- player b -> scope_1?next=3
- player c -> scope_1?next=2
- player d -> scope_1?next=3
- player e -> scope_1?next=3
@@ -452,9 +459,212 @@ mod tests { | |||
_ = &mut timeout => {} | |||
} | |||
} | |||
#[tokio::test] | |||
async fn match_pair_and_other_alone_room_without_next() { |
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.
Here we check:
- player a -> scope_1?next=2
- player b -> scope_1
- player c -> scope_1?next=2
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.
The matchbox_demo example needs to be updated now (to use the new next API), and I had a couple of tiny nits, but otherwise, this looks really great!
It's really awesome to have this so well tested with all the corner-cases we discussed.
matchbox_server/src/signaling.rs
Outdated
let mut client_a = warp::test::ws() | ||
.path("/room_name?next=2") | ||
.handshake(api.clone()) | ||
// .handshake(ws_echo()) |
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.
nit: Should probably get rid of these commented out lines
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.
other nit, that PR adds a lot of duplicatd code for tests ; I guess it's usual so why not, but it might be a good time to split in another file for tests ?
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.
I feel that in tests it's far better to err on the side of simple rather than dry. imo it's only worth it if the test becomes easier to read and debug.
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.
I'm ok with repetition in tests 👍.
I especially want to be clear that signalling.rs
sees its line count going from 460 to 650, so it might be a good time to consider moving tests out of that file.
I updated matchbox_demo ; it worked fine locally 🎉 . I didn't update documentation because I didn't find any place where the "next" logic is mentionned, I guess most information is from your blog and the example. I conclude it probably belong to another issue or Pull Request to add documentation. |
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.
I updated matchbox_demo ; it worked fine locally tada .
I didn't update documentation because I didn't find any place where the "next" logic is mentionned, I guess most information is from your blog and the example. I conclude it probably belong to another issue or Pull Request to add documentation.
Yeah, seems like it's not documented in the repo.
It'd probably be a good idea to add some api docs.
Great work!
Merging. I think moving tests to a separate file is a good idea, and documentation as well. More PRs always welcome ;) |
Implements #13
This also allows to scope rooms with id.
I adapted a test to use scopes, but we might want to create separate tests rather than changing the existing one.