+ /* Now that a client has connected, first we need to stream all of
+ * the existing spectators and players (if any). */
+ if (this._spectators.length > 0) {
+ const spectators_json = JSON.stringify(this.spectators);
+ const spectators_data = `event: spectators\ndata: ${spectators_json}\n\n`;
+ response.write(spectators_data);
+ }
+
+ if (this._players.length > 0) {
+ const players_json = JSON.stringify(this.registered_players);
+ const players_data = `event: players\ndata: ${players_json}\n\n`;
+ response.write(players_data);
+ }
+
+ /* And we need to inform the client of the current game phase.
+ *
+ * In fact, we need to cycle through each phase transition from the
+ * beginning so the client can see each.
+ */
+ var old_phase = null;
+ for (var phase = GamePhase.JOIN; phase <= this.phase; phase++) {
+ var event_data = this.game_phase_event_data(old_phase, phase);
+ response.write("event: game-phase\n" + "data: " + event_data + "\n\n");
+ old_phase = phase;
+ }
+ }