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 | /** global: io */ |
||
2 | const socket = io.connect(); |
||
3 | const streamId = window.location.pathname.substring(1); |
||
4 | |||
5 | /** |
||
6 | * Handler for WebSocket 'connect' event. |
||
7 | * Emits 'join' event which is intended to join WebSocket room for current streamId. |
||
8 | */ |
||
9 | socket.on('connect', () => { |
||
10 | socket.emit('join', streamId); |
||
11 | }); |
||
12 | |||
13 | /** |
||
14 | * Handler for new data. |
||
15 | * Renders data on web page (add to the bottom). |
||
16 | * |
||
17 | * @event LOG.NEW |
||
18 | */ |
||
19 | socket.on('log', (data) => { |
||
20 | /** global: gtag */ |
||
21 | gtag('event', 'got_new_log', {'count': 1}); |
||
22 | |||
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 !== streamId) { |
||
26 | gtag('event', 'stream_id_mismatch', {'streamIdMismatch': 1}); |
||
27 | return; |
||
28 | } |
||
29 | |||
30 | if (data.format === 'json') { |
||
31 | /** global: app */ |
||
32 | renderJson(data, app.autoScrool); |
||
33 | } |
||
34 | }); |
||
35 |