main
Jurij Podgoršek 2022-05-07 16:27:19 +02:00
parent 40d869c098
commit 0272c5851f
1 changed files with 16 additions and 14 deletions

View File

@ -7,7 +7,8 @@ const PORT = 6676
// Do we have a problem, shall we debug? // Do we have a problem, shall we debug?
const DEBUG = { const DEBUG = {
osc: true, osc: true,
udp: false udp: false,
midi: true
} }
// MIDI out // MIDI out
@ -246,12 +247,6 @@ const sendAll = (msg, info, oscWS, osclients) => {
}, info, oscWS, osclients) }, info, oscWS, osclients)
} }
if (MIDI) {
if (msg.address == '/midi') {
mo.send(msg.args)
}
}
osclients.forEach( client => { osclients.forEach( client => {
if (client && oscWS != client) { if (client && oscWS != client) {
// console.log("sending", msg, info) // console.log("sending", msg, info)
@ -270,16 +265,23 @@ const sendAll = (msg, info, oscWS, osclients) => {
let osclients = [] let osclients = []
wss.on('connection', function (ws) { wss.on('connection', function (ws) {
console.log('new client connection') console.log('new client connection', ws._socket.remoteAddress)
let oscWS = new osc.WebSocketPort({ let oscWS = new osc.WebSocketPort({
socket: ws, socket: ws
metadata: false
}); });
// Vsi OSC sem grejo naprej na kliente OSC // Vsi OSC sem grejo naprej na kliente OSC
oscWS.on('packet', (packet, info) => { oscWS.on('message', ({ address, args}, info) => {
// Broadcast adjust msg console.log('fasal sem', address, args)
const [address, args] = packet if (MIDI) {
if (address == '/midi') {
if (DEBUG.midi) {
console.log('midi SEND', args)
}
mo.send(args)
}
}
sendAll({ address, args}, info, oscWS, osclients) sendAll({ address, args}, info, oscWS, osclients)
}) })
@ -292,7 +294,7 @@ wss.on('connection', function (ws) {
osclients.push(oscWS) osclients.push(oscWS)
oscWS.on('close', () => { oscWS.on('close', () => {
console.log('closing socket', oscWS) console.log('closing socket', oscWS.socket.remoteAddress)
osclients = osclients.filter(ws => ws !== oscWS) osclients = osclients.filter(ws => ws !== oscWS)
}) })
}) })