GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 31c2e9...11e814 )
by Vladimir
25s
created

src/public/js/app.js   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 32
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 32
rs 10
wmc 4
mnd 1
bc 4
fnc 3
bpm 1.3333
cpm 1.3333
noi 2
1
/** global: io */
2
const socket = io.connect();
3
const streamId = window.location.pathname.substring(1);
4
let autoScrool = true;
5
6
/**
7
 * Gets element with log message data.
8
 *
9
 * @param {String} data Log message data.
10
 */
11
function getCodeElement(data) {
12
  const c = document.createElement('code');
13
  c.className = 'code blink hljs json';
14
  c.innerHTML = JSON.stringify(data, null, "\t"); // eslint-disable-line
15
  /** global: hljs */
16
  hljs.highlightBlock(c);
17
18
  const pre = document.createElement('pre');
19
  pre.appendChild(c);
20
21
  return pre;
22
}
23
24
/**
25
 * Gets element with ip address.
26
 *
27
 * @param {String} ip Ip address.
28
 */
29
function getIpElement(ip) {
30
  const s = document.createElement('span');
31
  s.className = 'ip';
32
  s.innerHTML = ip;
33
34
  return s;
35
}
36
37
/**
38
 * Gets element with current date.
39
 */
40
function getDateElement() {
41
  const s = document.createElement('span');
42
  s.className = 'date';
43
  s.innerHTML = (new Date()).toLocaleDateString(
44
    'en-GB',
45
    { hour: '2-digit', minute: '2-digit', second: '2-digit' },
46
  );
47
48
  return s;
49
}
50
51
/**
52
 * Gets element with tags content.
53
 *
54
 * @param {Object} data LOG.NEW payload.
55
 */
56
function getTags(data) {
57
  const d = document.createElement('div');
58
  d.className = 'tags';
59
  d.appendChild(getDateElement());
60
  d.appendChild(getIpElement(data.ip));
61
62
  return d;
63
}
64
65
/**
66
 * Renders new log message.
67
 *
68
 * @param {Object} data LOG.NEW payload.
69
 */
70
function renderJson(data) {
71
  const p = document.createElement('p');
72
  p.appendChild(getTags(data));
73
  p.appendChild(getCodeElement(data.data));
74
  document.getElementById('root').appendChild(p);
75
76
  if (autoScrool === true) {
77
    window.scrollTo(0, document.body.scrollHeight);
78
  }
79
}
80
81
/**
82
 * Auto-scrolling to latest data.
83
 */
84
window.addEventListener('onscroll', () => {
85
  autoScrool = (
86
    (window.innerHeight + window.scrollY) >= document.body.offsetHeight
87
  );
88
});
89
90
/**
91
 * Handler for WebSocket 'connect' event.
92
 * Emits 'join' event which is intended to join WebSocket room for current streamId.
93
 */
94
socket.on('connect', () => {
95
  socket.emit('join', streamId);
96
});
97
98
/**
99
 * Handler for new data.
100
 * Renders data on web page (add to the bottom).
101
 *
102
 * @event LOG.NEW
103
 */
104
socket.on('log', (data) => {
105
  if (data.format === 'json') {
106
    renderJson(data);
107
  }
108
});
109