Skip to content

#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

Merged
merged 6 commits into from
Feb 12, 2022
Merged

#13: scoped rooms #19

merged 6 commits into from
Feb 12, 2022

Conversation

Vrixyz
Copy link
Contributor

@Vrixyz Vrixyz commented Feb 9, 2022

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.

@Vrixyz
Copy link
Contributor Author

Vrixyz commented Feb 9, 2022

disclaimer:

  • Code is a bit messy: unnamed tuples, and using Option<String> for scope.. but I think it show a good approach
  • I didn't test in real application, I'm trusting tests here 🤞

@@ -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 {
Copy link
Contributor Author

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

Copy link
Owner

@johanhelsing johanhelsing left a 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.

@Vrixyz
Copy link
Contributor Author

Vrixyz commented Feb 10, 2022

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 wss://match.example.com/abcd?next=2 is just a different room from wss://match.example.com/abcd

I'm working on it :)

@Vrixyz Vrixyz requested a review from johanhelsing February 10, 2022 20:54
@@ -453,8 +463,159 @@ mod tests {
}
}

#[tokio::test]
async fn match_different_id_same_next() {
Copy link
Contributor Author

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() {
Copy link
Contributor Author

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() {
Copy link
Contributor Author

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

Copy link
Owner

@johanhelsing johanhelsing left a 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.

let mut client_a = warp::test::ws()
.path("/room_name?next=2")
.handshake(api.clone())
// .handshake(ws_echo())
Copy link
Owner

@johanhelsing johanhelsing Feb 11, 2022

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

Copy link
Contributor Author

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 ?

Copy link
Owner

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.

Copy link
Contributor Author

@Vrixyz Vrixyz Feb 11, 2022

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.

@Vrixyz
Copy link
Contributor Author

Vrixyz commented Feb 11, 2022

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.

@Vrixyz Vrixyz requested a review from johanhelsing February 11, 2022 21:03
Copy link
Owner

@johanhelsing johanhelsing left a 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!

@johanhelsing johanhelsing merged commit 8a4b3a6 into johanhelsing:main Feb 12, 2022
@johanhelsing
Copy link
Owner

Merging. I think moving tests to a separate file is a good idea, and documentation as well. More PRs always welcome ;)

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.

2 participants