You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

30 lines
601 B

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;