I am evaluating PeerJS in order to implement a simple two-player online game. It seems that once I transfer the id of one player’s connection to the other, they can open a channel via PeerJS and are good to go.
But if two players want to play that do not know each other, what is the most elegant way to make a match there? Is there a way to ask the PeerJS broker for a list of all connected clients, possibly with some metadata (such as „status:wants-to-play”) attached? Or is ther ea way to broadcast to all clients?
Using PeerServer you can grab two events,
connectionanddisconnect. Using this you can create a internal list, which you can then have your application grab from.Partial example:
Then, in your clientside code you can AJAX
/connected-peopleand use that list.For metadata you could expand on the code above to add a user status and a way of updating that status.
Hope this helps!
EDIT At the time of writing the event was named
connect. It is now namedconnection.(Also I'm now going to play with PeerJS for like six hours. I hope you realize what you've done.)