Handling players connecting
Player Silencing allows you to control what happens when a new player joins the game while the game is in an active game round without additional game code.
It ensures that newly joined players are not known to the game until the game round is finished.
With player silencing disabled: New players will be added to your game as soon as they connect to the game, invoking onConnect and requiring your game to manually handle and ignore messages as well as visualizing the correct state on the game controller.
With player silencing enabled: New players will be informed that they need to wait for the game round to finish on their controller. Your screen and controller will only invoke onConnect after the game round is no longer active, which is controlled by your screen calling setActivePlayers(0).
Player Silencing works by keeping track of new devices connecting while the game is in an active game round.
The onConnect event of such devices will be delayed until the game round is no longer active.
Once the active game round is no longer active, all waiting onConnect events will be executed, unless the device has disconnected already.
Player Silencing allows you to be sure that after a game round is started, newly joining players are requested to wait until the game round is finished. This does not require additional game code to prevent an impact to the game experience or the game rounds outcome.
If your game is designed to allow players to join at any time, then player silencing is not for you.
To enable and use player silencing, all you need to do is to configure AirConsole to use it on the screen.
- Web Setup: Include silence_inactive_players: true when calling the constructor:
- Unity Setup: Enable the checkboxSilence Playerson the AirConsole component in the scene.

After enabling playing silence, you can control when new players can join using setActivePlayers.
Once player silencing is enabled, during any phase of your game where you setActivePlayers to anything but 0, new joining players will be silenced. After setActivePlayers(0) is called, the game will be in a waiting state and new players will be added to the game. Players that are already waiting to join will now be added and onConnect is called for them.
We will use the Pong Example Game, to explain player silencing and how it applies :
- We initialize AirConsole including thesilence_inactive_players: trueflag when creating the AirConsole object, signaling that new players to automatically wait during active gameplay.
- The game is initially in the LOBBY state, waiting for players.
- Once 2 devices are connected and the master device starts the game, the game switches to the GAME state.
- Entering the GAME state executes setActivePlayers(2), starting the active Pong gameplay.
- If any additional device connects while in the GAME state, the new device will be silenced and the controller will inform the user with the following screen.
- After the game ends, the screen enters the LOBBY state, which calls setActivePlayers(0) to mark no controller as active player.
- After setActivePlayers(0) all players that joined while the GAME was ongoing will now join the game, showing the currently active controller
We provide a full example implementation as a 2 player Pong game with dedicated game states.
- LOBBY: New players automatically join the pre-game waiting state until the main controller decides its time to start. In this state, setActivePlayers(0) was called.
- GAME: In this state, new players need to wait to join (they are silenced). In this state, setActivePlayers(2) was called.
You can find this example Pong Game at https://github.com/AirConsole/games-pong
