lbry.tech/app/dist/scripts/sockets.js

47 lines
1,003 B
JavaScript
Raw Normal View History

2018-08-29 01:57:18 +02:00
/* global $, log, ws */ "use strict";
2018-07-16 23:06:37 +02:00
2018-08-29 01:57:18 +02:00
// const log = console.log; // eslint-disable-line
2018-07-12 23:07:16 +02:00
ws.onmessage = socket => {
const data = JSON.parse(socket.data);
switch (true) {
case data.message === "updated html":
$(data.selector).html(data.html);
$("#emailMessage").val("");
2018-07-12 23:07:16 +02:00
break;
2018-07-17 21:40:25 +02:00
case data.message === "notification": // TODO: Make work with appending so multiple notifications can be sent
$("#flash-container").html(`<div class="flash active${data.type ? " " + data.type : ""}">${data.details}</div>`);
setTimeout(() => {
$("#flash-container").html("");
}, 2100);
break;
2018-07-12 23:07:16 +02:00
default:
2018-07-16 23:06:37 +02:00
log(data);
2018-07-12 23:07:16 +02:00
break;
}
};
2018-07-16 23:06:37 +02:00
function send(msg) { // eslint-disable-line
socketReady(ws, () => ws.send(msg));
}
function socketReady(socket, callback) {
setTimeout(() => {
if (socket.readyState === 1) {
if (callback !== undefined) callback();
return;
} else {
socketReady(socket, callback);
}
}, 5);
}