This is an example of a lobby for Multisynq games, implemented with Multisynq. It uses the game from step 9 of the Multiblaster Tutorial.
To use this lobby in your own game:
- rename your own game's main HTML file to
game.html
- copy the lobby's
index.html
next to your game'sgame.html
- in that
index.html
, edit theSession.join()
arguments (e.g. your API key, appId etc) - edit your own
game.html
using code from the lobby'sgame.html
-
add the
LobbyRelayModel
andLobbyRelayView
classes -
add the
joinSessionFromLobby()
function (replacing your oldSession.join()
, but adjust the arguments like API key etc) -
in your game's root model
init()
method, addLobbyRelayModel.create()
-
in your game's root view
constructor()
, addthis.lobbyRelay = new LobbyRelayView(this.wellKnownModel("lobbyRelay"));
-
in your game's root view
detach()
method, addthis.lobbyRelay.detach(); this.lobbyRelay = null;
-
That should do it. Launch index.html
in two browser windows, click the "Host New Game" button, enter a session name, and your game should start. The lobby in the other window should show the game session and allow you to join it.
The lobby has a Multisynq session that keeps track of players coming in, and sessions going on. It shows them in a list.
When a player joins a session, the game is loaded in an iframe fully covering the lobby itself, but the lobby session stays active in addition to the game session in the iframe. The game sends updates to the lobby via in-browser messages. That's how the lobby knows which sessions are active.
For each game session, all but one players leave the lobby session. One player acts as relay. This is so the number of users in the lobby session doesn't get too large.