Broadcast an already parsed JSON payload

This commit is contained in:
D. Berge
2020-09-25 18:26:04 +02:00
parent 55cb3856c3
commit ab2cf81327
2 changed files with 6 additions and 3 deletions

View File

@@ -51,9 +51,6 @@ new Vue({
this.ws.addEventListener("message", (ev) => {
const msg = JSON.parse(ev.data);
if (msg.payload) {
msg.payload = JSON.parse(msg.payload);
}
this.setServerEvent(msg);
});

View File

@@ -7,6 +7,12 @@ const channels = {};
async function notify (data) {
if (data.channel in channels) {
data._received = new Date();
try {
const json = JSON.parse(data.payload);
data.payload = json;
} catch {
// Ignore the error
}
for (const listener of channels[data.channel]) {
listener(data);
}