this.broadcast_event(type, JSON.stringify(obj));
}
+ game_state_json() {
+ return JSON.stringify(this.state, stringify_replacer);
+ }
+
handle_events(request, response) {
/* These headers will keep the connection open so we can stream events. */
const headers = {
/* Finally, if this game class has a "state" property, stream that
* current state to the client. */
if (this.state) {
- const state_json = JSON.stringify(this.state, stringify_replacer);
- response.write(`event: game-state\ndata: ${state_json}\n\n`);
+ response.write(`event: game-state\ndata: ${this.game_state_json()}\n\n`);
}
}