diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-06-11 06:48:25 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-06-11 06:48:25 +0900 |
| commit | dc3c80e3cef48bbbb1de2c5d8c6fb462b25de6e0 (patch) | |
| tree | 74f6a2b922bb07c646705aebe7f8908771cf2ef7 /src/server/api/stream | |
| parent | Update example.yml (diff) | |
| download | sharkey-dc3c80e3cef48bbbb1de2c5d8c6fb462b25de6e0.tar.gz sharkey-dc3c80e3cef48bbbb1de2c5d8c6fb462b25de6e0.tar.bz2 sharkey-dc3c80e3cef48bbbb1de2c5d8c6fb462b25de6e0.zip | |
wip
Diffstat (limited to 'src/server/api/stream')
| -rw-r--r-- | src/server/api/stream/hashtags-stats.ts | 35 |
1 files changed, 35 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); + }); +} |