summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/stream/server.ts20
-rw-r--r--src/api/streaming.ts6
2 files changed, 26 insertions, 0 deletions
diff --git a/src/api/stream/server.ts b/src/api/stream/server.ts
new file mode 100644
index 0000000000..6de5337499
--- /dev/null
+++ b/src/api/stream/server.ts
@@ -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);
+ });
+}
diff --git a/src/api/streaming.ts b/src/api/streaming.ts
index e1d79481d3..c71132100c 100644
--- a/src/api/streaming.ts
+++ b/src/api/streaming.ts
@@ -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) {