summaryrefslogtreecommitdiff
path: root/src/server/api/stream
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/stream')
-rw-r--r--src/server/api/stream/notes-stats.ts35
-rw-r--r--src/server/api/stream/server-stats.ts35
-rw-r--r--src/server/api/stream/server.ts19
3 files changed, 70 insertions, 19 deletions
diff --git a/src/server/api/stream/notes-stats.ts b/src/server/api/stream/notes-stats.ts
new file mode 100644
index 0000000000..739b325848
--- /dev/null
+++ b/src/server/api/stream/notes-stats.ts
@@ -0,0 +1,35 @@
+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
+ }));
+ };
+
+ connection.on('message', async data => {
+ const msg = JSON.parse(data.utf8Data);
+
+ switch (msg.type) {
+ case 'requestLog':
+ ev.once('notesStatsLog:' + msg.id, statsLog => {
+ connection.send(JSON.stringify({
+ type: 'statsLog',
+ body: statsLog
+ }));
+ });
+ ev.emit('requestNotesStatsLog', msg.id);
+ break;
+ }
+ });
+
+ ev.addListener('notesStats', onStats);
+
+ connection.on('close', () => {
+ ev.removeListener('notesStats', onStats);
+ });
+}
diff --git a/src/server/api/stream/server-stats.ts b/src/server/api/stream/server-stats.ts
new file mode 100644
index 0000000000..342170a21e
--- /dev/null
+++ b/src/server/api/stream/server-stats.ts
@@ -0,0 +1,35 @@
+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
+ }));
+ };
+
+ connection.on('message', async data => {
+ const msg = JSON.parse(data.utf8Data);
+
+ switch (msg.type) {
+ case 'requestLog':
+ ev.once('serverStatsLog:' + msg.id, statsLog => {
+ connection.send(JSON.stringify({
+ type: 'statsLog',
+ body: statsLog
+ }));
+ });
+ ev.emit('requestServerStatsLog', msg.id);
+ break;
+ }
+ });
+
+ ev.addListener('serverStats', onStats);
+
+ connection.on('close', () => {
+ ev.removeListener('serverStats', onStats);
+ });
+}
diff --git a/src/server/api/stream/server.ts b/src/server/api/stream/server.ts
deleted file mode 100644
index 4ca2ad1b10..0000000000
--- a/src/server/api/stream/server.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-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);
- });
-}