lint topos
This commit is contained in:
@ -12,10 +12,14 @@ wss.on("connection", function (ws) {
|
||||
const message = JSON.parse(data);
|
||||
sendOscMessage(
|
||||
formatAndTypeMessage(message),
|
||||
message.address,
|
||||
message.port
|
||||
message.address,
|
||||
message.port,
|
||||
);
|
||||
console.log(
|
||||
`> Message sent to ${message.address}:${message.port}: ${JSON.stringify(
|
||||
message.args,
|
||||
)}`,
|
||||
);
|
||||
console.log(`> Message sent to ${message.address}:${message.port}: ${JSON.stringify(message.args)}`)
|
||||
} catch (error) {
|
||||
console.error("> Error processing message:", error);
|
||||
}
|
||||
@ -24,12 +28,12 @@ wss.on("connection", function (ws) {
|
||||
|
||||
wss.on("error", function (error) {
|
||||
console.error("> Server error:", error);
|
||||
})
|
||||
});
|
||||
|
||||
wss.on("close", function () {
|
||||
// Close the websocket server
|
||||
wss.close();
|
||||
console.log("> Closing websocket server")
|
||||
console.log("> Closing websocket server");
|
||||
});
|
||||
|
||||
let udpPort = new osc.UDPPort({
|
||||
@ -37,7 +41,7 @@ let udpPort = new osc.UDPPort({
|
||||
localPort: 3000,
|
||||
metadata: true,
|
||||
remoteAddress: "0.0.0.0",
|
||||
remotePort: 57120,
|
||||
remotePort: 57120,
|
||||
});
|
||||
udpPort.on("error", function (error) {
|
||||
console.error("> UDP Port error:", error);
|
||||
@ -51,7 +55,7 @@ udpPort.open();
|
||||
|
||||
function sendOscMessage(message, address, port) {
|
||||
try {
|
||||
udpPort.options.remotePort = port
|
||||
udpPort.options.remotePort = port;
|
||||
message.address = address;
|
||||
udpPort.send(message);
|
||||
} catch (error) {
|
||||
@ -61,21 +65,19 @@ function sendOscMessage(message, address, port) {
|
||||
|
||||
const formatAndTypeMessage = (message) => {
|
||||
let newMessage = {};
|
||||
delete message.args['address'];
|
||||
delete message.args['port'];
|
||||
delete message.args["address"];
|
||||
delete message.args["port"];
|
||||
newMessage.address = message.address;
|
||||
newMessage.timestamp = osc.timeTag(message.timetag);
|
||||
|
||||
args = [...Object.entries(message.args)].flat().map((arg) => {
|
||||
if (typeof arg === 'string')
|
||||
return {type: 's', value: arg};
|
||||
if (typeof arg === 'number')
|
||||
return {type: 'f', value: arg};
|
||||
if (typeof arg === 'boolean')
|
||||
return value ? {type: 's', value: 1} : {type: 's', value: 0};
|
||||
})
|
||||
if (typeof arg === "string") return { type: "s", value: arg };
|
||||
if (typeof arg === "number") return { type: "f", value: arg };
|
||||
if (typeof arg === "boolean")
|
||||
return value ? { type: "s", value: 1 } : { type: "s", value: 0 };
|
||||
});
|
||||
|
||||
newMessage.args = args
|
||||
newMessage.args = args;
|
||||
|
||||
return newMessage;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user