nanka iroiro
This commit is contained in:
20
src/api/stream/server.ts
Normal file
20
src/api/stream/server.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as websocket from 'websocket';
|
||||
import Xev from 'xev';
|
||||
|
||||
const ev = new Xev();
|
||||
|
||||
export default function homeStream(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', () => {
|
||||
console.log('yooo');
|
||||
ev.removeListener('stats', onStats);
|
||||
});
|
||||
}
|
@ -8,6 +8,7 @@ import isNativeToken from './common/is-native-token';
|
||||
|
||||
import homeStream from './stream/home';
|
||||
import messagingStream from './stream/messaging';
|
||||
import serverStream from './stream/server';
|
||||
|
||||
module.exports = (server: http.Server) => {
|
||||
/**
|
||||
@ -20,6 +21,11 @@ module.exports = (server: http.Server) => {
|
||||
ws.on('request', async (request) => {
|
||||
const connection = request.accept();
|
||||
|
||||
if (request.resourceURL.pathname === '/server') {
|
||||
serverStream(request, connection);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await authenticate(connection, request.resourceURL.query.i);
|
||||
|
||||
if (user == null) {
|
||||
|
Reference in New Issue
Block a user