const uuid = require('uuid'); const Listener = function({ app, messenger }) { this.app = app; this.messenger = messenger; }; Listener.prototype.onConnect = function(ws, req) { console.log("THIS2:") console.log(this) // Store an ID on the socket connection. ws.id = uuid.v4(); this.messenger.subscribe(ws); this.app.onConnect(ws, req); ws.on('message', (rawBody) => { this.app.onMessage(ws, rawBody); }); ws.on('close', () => { this.app.onDisconnect(ws); this.messenger.unsubscribe(ws); }); }; module.exports = Listener;