const app = require('./app') const Game = require('./game') game = new Game() game.start() app.ws('/game', (ws, req) => { const send = (frame) => { try { ws.send(frame) } catch(err) { console.warn(err) teardown() } } const teardown = () => { console.log('Detaching') game.off('frame', send) } game.on('frame', send) ws.on('close', () => teardown) }) app.listen().catch((err) => { console.log(err.toString()) process.exit(1) })