1 /* Base class providing common code for game engine implementations. */
6 this.next_client_id = 1;
10 const id = this.next_client_id;
11 this.clients.push({id: id,
13 this.next_client_id++;
19 this.clients = this.clients.filter(client => client.id !== id);
22 /* Send a string to all clients */
23 broadcast_string(str) {
24 this.clients.forEach(client => client.response.write(str + '\n'));
27 /* Send an event to all clients.
29 * An event has both a declared type and a separate data block.
30 * It also ends with two newlines (to mark the end of the event).
32 broadcast_event(type, data) {
33 this.broadcast_string(`event: ${type}\ndata: ${data}\n`);
38 module.exports = Game;