-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.js
29 lines (22 loc) · 865 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
var io = require('socket.io-client');
function connect() {
var socket = io.connect('http://' + window.location.host, {
'reconnect': true,
'reconnection delay': 5000,
'max reconnection attempts': Infinity
});
socket.on('update:view', function (id, data) {
var div = document.createElement('div'),
element = document.getElementById(id);
div.innerHTML = data;
element.parentNode.replaceChild(div.firstChild, element);
});
socket.on('connect', function () {
document.getElementById('backend-connection').innerHTML = '';
});
socket.on('disconnect', function () {
document.getElementById('backend-connection').innerHTML = '<div class="alert alert-danger row"><strong>Error:</strong> Backend Disconnected</div>';
});
}
window.onload = connect;