summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/api/stream/hashtags-stats.ts35
-rw-r--r--src/server/api/streaming.ts6
2 files changed, 41 insertions, 0 deletions
diff --git a/src/server/api/stream/hashtags-stats.ts b/src/server/api/stream/hashtags-stats.ts
new file mode 100644
index 0000000000..47183467f5
--- /dev/null
+++ b/src/server/api/stream/hashtags-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('hashtagsStatsLog:' + msg.id, statsLog => {
+ connection.send(JSON.stringify({
+ type: 'statsLog',
+ body: statsLog
+ }));
+ });
+ ev.emit('requestHashtagsStatsLog', msg.id);
+ break;
+ }
+ });
+
+ ev.addListener('hashtagsStats', onStats);
+
+ connection.on('close', () => {
+ ev.removeListener('hashtagsStats', onStats);
+ });
+}
diff --git a/src/server/api/streaming.ts b/src/server/api/streaming.ts
index 2d4cfc108f..e4156096ef 100644
--- a/src/server/api/streaming.ts
+++ b/src/server/api/streaming.ts
@@ -14,6 +14,7 @@ import othelloGameStream from './stream/othello-game';
import othelloStream from './stream/othello';
import serverStatsStream from './stream/server-stats';
import notesStatsStream from './stream/notes-stats';
+import hashtagsStatsStream from './stream/hashtags-stats';
import requestsStream from './stream/requests';
import { ParsedUrlQuery } from 'querystring';
import authenticate from './authenticate';
@@ -39,6 +40,11 @@ module.exports = (server: http.Server) => {
return;
}
+ if (request.resourceURL.pathname === '/hashtags-stats') {
+ hashtagsStatsStream(request, connection);
+ return;
+ }
+
if (request.resourceURL.pathname === '/requests') {
requestsStream(request, connection);
return;