2017-06-08 16:03:54 +00:00
|
|
|
import * as websocket from 'websocket';
|
|
|
|
import Xev from 'xev';
|
|
|
|
|
|
|
|
const ev = new Xev();
|
|
|
|
|
2018-03-07 02:40:40 +00:00
|
|
|
export default function(request: websocket.request, connection: websocket.connection): void {
|
2017-06-08 16:03:54 +00:00
|
|
|
const onStats = stats => {
|
|
|
|
connection.send(JSON.stringify({
|
|
|
|
type: 'stats',
|
|
|
|
body: stats
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
ev.addListener('stats', onStats);
|
|
|
|
|
|
|
|
connection.on('close', () => {
|
|
|
|
ev.removeListener('stats', onStats);
|
|
|
|
});
|
|
|
|
}
|