-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverws.js
23 lines (20 loc) · 860 Bytes
/
serverws.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(function (root, factory) {
if (typeof define === 'function' && define.amd) define([], factory); // AMD. Register as an anonymous module.
else if (typeof module === 'object' && module.exports) module.exports = factory(); // Node. CommonJS-like environments that support module.exports, like Node.
else factory({ }); // Browser globals (root is window)
}(typeof self !== 'undefined' ? self : this, function (exports = { }) {
const socket = new WebSocket(`ws://${location.host}`);
socket.addEventListener('message', (event) => {
const data = event.data;
if (/reload\-/i.test(data)) {
console.warn(data);
location.reload();
}
});
socket.addEventListener('open', () => {
console.log('Connected to the server');
});
socket.addEventListener('close', () => {
console.log('Disconnected from the server');
});
}));