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] }); // 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); } else { console.log('OSC message sent successfully'); } // Close the UDP socket udpSocket.close(); }); } const express = require('express'); const app = express(); const server = require('http').createServer(app); const io = require('socket.io')(server); // Handle socket.io events io.on('connection', (socket) => { console.log('A client connected!'); 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 }); // Add other event handlers here... }); const port = 3000; // Specify your desired port number server.listen(port, () => { console.log(`Server is running on port ${port}`); });