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.

54 lines
1.4 KiB
JavaScript

1 year ago
const osc = require('osc-min');
const dgram = require('dgram');
const oscHost = '127.0.0.1'; // IP address of the OSC destination
const oscPort = 8080; // Port number of the OSC destination
// Function to send the OSC message
function sendOSCMessage() {
// Create the OSC message
const oscMessage = osc.toBuffer({
address: '/blink',
args: [1]
});
1 year ago
// Create a UDP socket
const udpSocket = dgram.createSocket('udp4');
1 year ago
1 year ago
// Send the OSC message
udpSocket.send(oscMessage, 0, oscMessage.length, oscPort, oscHost, (err) => {
if (err) {
console.error('Error sending OSC message:', err);
} else {
console.log('OSC message sent successfully');
}
1 year ago
1 year ago
// Close the UDP socket
udpSocket.close();
});
}
1 year ago
1 year ago
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
1 year ago
// Handle socket.io events
io.on('connection', (socket) => {
console.log('A client connected!');
1 year ago
socket.on('blink', () => {
console.log('Blink event received!');
sendOSCMessage(); // Send the OSC message when the 'blink' event is received
io.emit('blink'); // Emit the 'blink' event to all connected clients
});
1 year ago
// Add other event handlers here...
1 year ago
});
1 year ago
const port = 3000; // Specify your desired port number
server.listen(port, () => {
console.log(`Server is running on port ${port}`);
});