Total Complexity | 4 |
Complexity/F | 1.33 |
Lines of Code | 32 |
Function Count | 3 |
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 | let autoScrool = true; |
||
|
|||
5 | |||
6 | /** |
||
7 | * Auto-scrolling to latest data. |
||
8 | */ |
||
9 | window.addEventListener('onscroll', () => { |
||
10 | autoScrool = ( |
||
11 | (window.innerHeight + window.scrollY) >= document.body.offsetHeight |
||
12 | ); |
||
13 | }); |
||
14 | |||
15 | /** |
||
16 | * Handler for WebSocket 'connect' event. |
||
17 | * Emits 'join' event which is intended to join WebSocket room for current streamId. |
||
18 | */ |
||
19 | socket.on('connect', () => { |
||
20 | socket.emit('join', streamId); |
||
21 | }); |
||
22 | |||
23 | /** |
||
24 | * Handler for new data. |
||
25 | * Renders data on web page (add to the bottom). |
||
26 | * |
||
27 | * @event LOG.NEW |
||
28 | */ |
||
29 | socket.on('log', (data) => { |
||
30 | if (data.format === 'json') { |
||
31 | renderJson(data); |
||
32 | } |
||
33 | }); |
||
34 |