mirror of
https://github.com/stagehacks/Cue-View.git
synced 2026-08-05 05:47:46 +00:00
add a queue for all sent messages
This commit is contained in:
+19
-2
@@ -44,6 +44,7 @@ function registerDevice(newDevice, discoveryMethod) {
|
||||
lastDrawn: 0,
|
||||
lastHeartbeat: 0,
|
||||
lastMessage: 0,
|
||||
sendQueue: [],
|
||||
heartbeatInterval: PLUGINS.all[newDevice.type].heartbeatInterval,
|
||||
heartbeatTimeout: PLUGINS.all[newDevice.type].heartbeatTimeout,
|
||||
draw() {
|
||||
@@ -130,7 +131,12 @@ function initDeviceConnection(id) {
|
||||
device.lastMessage = Date.now();
|
||||
});
|
||||
device.send = (address, args) => {
|
||||
device.connection.send({ address, args });
|
||||
const addr = address;
|
||||
const arg = args;
|
||||
device.sendQueue.push({ address: addr, args: arg });
|
||||
};
|
||||
device.sendNow = (data) => {
|
||||
device.connection.send(data);
|
||||
};
|
||||
} else if (plugins[type].config.connectionType === 'TCPsocket') {
|
||||
device.connection = new net.Socket();
|
||||
@@ -159,6 +165,9 @@ function initDeviceConnection(id) {
|
||||
});
|
||||
device.send = (data) => {
|
||||
// log("SOCK OUT", data);
|
||||
device.sendQueue.push(data);
|
||||
};
|
||||
device.sendNow = (data) => {
|
||||
device.connection.write(data);
|
||||
};
|
||||
} else if (plugins[type].config.connectionType === 'UDPsocket') {
|
||||
@@ -175,6 +184,9 @@ function initDeviceConnection(id) {
|
||||
});
|
||||
|
||||
device.send = (data) => {
|
||||
device.sendQueue.push(data);
|
||||
};
|
||||
device.sendNow = (data) => {
|
||||
device.connection.send(Buffer.from(data), device.port, device.addresses[0], (err) => {
|
||||
// console.log(err);
|
||||
});
|
||||
@@ -324,9 +336,14 @@ function heartbeat() {
|
||||
}
|
||||
d.lastHeartbeat = Date.now();
|
||||
}
|
||||
|
||||
if (d.sendQueue.length > 0 && d.sendNow) {
|
||||
d.sendNow(d.sendQueue[0]);
|
||||
d.sendQueue.shift();
|
||||
}
|
||||
});
|
||||
}
|
||||
setInterval(heartbeat, 100);
|
||||
setInterval(heartbeat, 50);
|
||||
|
||||
function isDeviceAlreadyAdded(newDevice) {
|
||||
let deviceAlreadyAdded = false;
|
||||
|
||||
Reference in New Issue
Block a user