Created
April 28, 2019 11:20
-
-
Save daveyijzermans/f0354858b3eb765e19361ab85a6bc55b to your computer and use it in GitHub Desktop.
Discover Focusrite Control Server on the network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PORT = 61392; | |
const dgram = require('dgram'); | |
const client = dgram.createSocket('udp4'); | |
// Make the discovery message | |
const msg = '<client-discovery app="SAFFIRE-CONTROL" version="4" device="iOS"/>'; | |
const hex = ('000000' + msg.length.toString(16)).substr(-6); | |
const announce = 'Length=' + hex + ' ' + msg; | |
// Start the udp socket | |
client.bind(PORT); | |
// Start a polling timer to broadcast the message every 1 second | |
client.on('listening', function () { | |
let address = client.address(); | |
console.log('UDP Client listening on ' + address.address + ":" + address.port); | |
client.setBroadcast(true) | |
client.setMulticastTTL(128); | |
setInterval(broadcast, 1000) | |
}); | |
// Send udp broadcast message on ports 30096, 30097 and 30098 | |
// The iOS client does this, so I'm just copying its behaviour. | |
const broadcast = () => | |
{ | |
let message = Buffer.from(announce); | |
client.send(message, 0, message.length, 30096, "255.255.255.255"); | |
client.send(message, 0, message.length, 30097, "255.255.255.255"); | |
client.send(message, 0, message.length, 30098, "255.255.255.255"); | |
} | |
// Focusrite Control Server sends back a xml-tag stylew message | |
client.on('message', function (message, remote) | |
{ | |
let str = message.toString(); | |
let ip = remote.address; | |
let port = str.match(/port\=\'([0-9]*)\'/)[1]; | |
console.log(str, ip, port) | |
// got it! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment