pass data through
This commit is contained in:
12
api/index.js
12
api/index.js
@@ -19,7 +19,7 @@ var api_connected = false;
|
|||||||
|
|
||||||
function send_events_to_clients(data) {
|
function send_events_to_clients(data) {
|
||||||
sse_clients.forEach((client) =>
|
sse_clients.forEach((client) =>
|
||||||
client.response.write(`data: ${JSON.stringify(data)}\n\n`)
|
client.response.write(`${JSON.stringify(data)}\n\n`)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,15 +59,7 @@ var connect_to_api = function () {
|
|||||||
ws.on("message", function message(message) {
|
ws.on("message", function message(message) {
|
||||||
try {
|
try {
|
||||||
var msg = JSON.parse(message);
|
var msg = JSON.parse(message);
|
||||||
if (msg.type == "STATUS") {
|
send_events_to_clients(msg);
|
||||||
last_status = msg.data;
|
|
||||||
send_events_to_clients(message);
|
|
||||||
} else if (msg.type == "IMAGE") {
|
|
||||||
console.log("got picture");
|
|
||||||
// console.log(msg.image);
|
|
||||||
last_image = msg.image;
|
|
||||||
received_picture = true;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("could not parse as json");
|
console.log("could not parse as json");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user