diff --git a/lib/routes.js b/lib/routes.js index 5c24697..dccb477 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -100,7 +100,11 @@ const setupRoutes = function setupRoutes() { // #138. handle emitted events that don't have a listener registered, and forward the message // onto the client via the socket - this.on('unhandled', ({ eventName, data }) => send(prep({ action: eventName, data }))); + const unhandled = ({ eventName, data }) => send(prep({ action: eventName, data })); + this.on('unhandled', unhandled); + socket.on('close', () => { + this.off('unhandled', unhandled); + }); send(prep({ action: 'connected' })); }