diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-06-09 04:14:26 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-06-09 04:14:26 +0900 |
| commit | c78945436e39121f46e083eac7a6572ca2efe2d2 (patch) | |
| tree | b26036a9f38bda54b865e704f8bcd477f2caac0e /src/server/api/stream | |
| parent | サーバーの統計情報をメモリに記憶するようにするなど (diff) | |
| download | sharkey-c78945436e39121f46e083eac7a6572ca2efe2d2.tar.gz sharkey-c78945436e39121f46e083eac7a6572ca2efe2d2.tar.bz2 sharkey-c78945436e39121f46e083eac7a6572ca2efe2d2.zip | |
#1686
Diffstat (limited to 'src/server/api/stream')
| -rw-r--r-- | src/server/api/stream/notes-stats.ts | 35 | ||||
| -rw-r--r-- | src/server/api/stream/server-stats.ts (renamed from src/server/api/stream/server.ts) | 0 |
2 files changed, 35 insertions, 0 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.ts b/src/server/api/stream/server-stats.ts index 342170a21e..342170a21e 100644 --- a/src/server/api/stream/server.ts +++ b/src/server/api/stream/server-stats.ts |