const EventEmitter = require('events');
const pubsub = new EventEmitter();
wss.on('connection', ws => {
pubsub.on('test', (payload, _ws) => {
if (_ws !== ws) {
return;
}
ws.send(payload);
});
ws.on('message', message => {
const { event, payload } = message;
pubsub.emit(event, payload, ws);
});
})
const EventEmitter = require('events');
const pubsub = new EventEmitter();
wss.on('connection', ws => {
ws.on('message', message => {
const { event, payload } = message;
pubsub.emit(event, payload, ws);
});
});
pubsub.on('test', (payload, _ws) => {
_ws.send(payload);
});
const EventEmitter = require('events');
const pubsub = new EventEmitter();
wss.on('connection', ws => {
ws.on('message', message => {
const { event, payload } = message;
pubsub.emit(event, { payload, ws });
});
});
pubsub.on('test', ({ payload, ws }) => {
ws.send(payload);
});
const EventEmitter = require('events');
const pubsub = new EventEmitter();
wss.on('connection', ws => {
ws.on('message', message => {
const { event, payload } = message;
pubsub.emit(event, payload, outcome => ws.send(outcome));
});
});
pubsub.on('test', (payload, send) => {
send(payload);
});