You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
992 B
JavaScript
38 lines
992 B
JavaScript
1 year ago
|
const express = require('express');
|
||
|
const osc = require('osc-min');
|
||
|
const dgram = require('dgram');
|
||
|
|
||
|
const app = express();
|
||
|
const oscHost = '192.168.2.1'; // IP address of the OSC destination
|
||
|
const oscPort = 8000; // Port number of the OSC destination
|
||
|
|
||
|
app.get('/trigger-blink', (req, res) => {
|
||
|
// Create the OSC message
|
||
|
const oscMessage = osc.toBuffer({
|
||
|
address: '/blink',
|
||
|
args: [1]
|
||
|
});
|
||
|
|
||
|
// Create a UDP socket
|
||
|
const udpSocket = dgram.createSocket('udp4');
|
||
|
|
||
|
// Send the OSC message
|
||
|
udpSocket.send(oscMessage, 0, oscMessage.length, oscPort, oscHost, (err) => {
|
||
|
if (err) {
|
||
|
console.error('Error sending OSC message:', err);
|
||
|
res.status(500).send('Error sending OSC message');
|
||
|
} else {
|
||
|
console.log('OSC message sent successfully');
|
||
|
res.send('OSC message sent successfully');
|
||
|
}
|
||
|
|
||
|
// Close the UDP socket
|
||
|
udpSocket.close();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
// Start the server
|
||
|
app.listen(8000, () => {
|
||
|
console.log('Server is running on port 8000');
|
||
|
});
|