Total Complexity | 4 |
Complexity/F | 2 |
Lines of Code | 33 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | const io = require('socket.io-client'); |
||
2 | |||
3 | const app = require('./../app'); |
||
4 | const renderJson = require('./../lib'); |
||
5 | |||
6 | const socket = io.connect(); |
||
7 | |||
8 | /** |
||
9 | * Handler for WebSocket 'connect' event. |
||
10 | * Emits 'join' event which is intended to join WebSocket room for current streamId. |
||
11 | */ |
||
12 | socket.on('connect', () => { |
||
13 | socket.emit('join', app.getStreamId()); |
||
14 | }); |
||
15 | |||
16 | /** |
||
17 | * Handler for new data. |
||
18 | * Renders data on web page (add to the bottom). |
||
19 | * |
||
20 | * @event LOG.NEW |
||
21 | */ |
||
22 | socket.on('log', (data) => { |
||
23 | // It is only way to render proper data because socket.io rooms disabled here |
||
24 | // @see https://github.com/cn007b/log/blob/master/src/routes/index.js#L49 |
||
25 | if (data.streamId !== app.getStreamId()) { |
||
26 | return; |
||
27 | } |
||
28 | |||
29 | if (data.format === 'json') { |
||
30 | /** global: app */ |
||
31 | renderJson(data, app.getAutoScroll()); |
||
32 | } |
||
33 | }); |
||
34 |