summaryrefslogtreecommitdiff
path: root/src/server/api/stream/server.ts
blob: 4ca2ad1b10ac1314d67f6c0cbe60a5585cd42098 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import * as websocket from 'websocket';
import Xev from 'xev';

const ev = new Xev();

export default function(request: websocket.request, connection: websocket.connection): void {
	const onStats = stats => {
		connection.send(JSON.stringify({
			type: 'stats',
			body: stats
		}));
	};

	ev.addListener('stats', onStats);

	connection.on('close', () => {
		ev.removeListener('stats', onStats);
	});
}