I’m creating a simple matchmaking system for a game in Meteor, my architecture is pretty simple: I have a server side collection (waitingList) that inserts user ids while they are waiting…
When a user joins the list, it will check if there is another user on the list, if there is, it should confirm if both players are ready and then creates the game.
On socket.io this would be very simple, since each user is in it’s own “room” I’d just broadcast the message to both user rooms and get them both to receive a “Are you ready” confirmation.
I’m new to meteor, and I’m a bit lost, how could I send confirm just for the two users selected on the list and not for all the users that are currently waiting?
Using pub/sub allows you to group delivery of data any way you like. By user at the most granular, through groups of users (rooms, if you like), groups of other properties of your data, all the way to everybody gets everything.
Instead of broadcasting messages, you publish data.
If you observe the collection you can add some logic to detect whether you have enough people. And then code action to it. Works a bit like a trigger.
So: First insert -> Do: WaitingList.find({filter on group if you want}).count() < 2 -> Ignore
Second insert -> Do: WaitingList.find({filter on group if you want}).count() === 2 -> Update both users for example by inserting groupId into their user record.
That will trigger both players to join the room.
You can also observe on the client, when you detect that you get a group assigned you could redirect to the game, show a message, etc.