Skip to content

Instantly share code, notes, and snippets.

@philhartung
Last active November 8, 2023 20:28
Show Gist options
  • Save philhartung/4d4113bade49706cfd4d89ef82793f19 to your computer and use it in GitHub Desktop.
Save philhartung/4d4113bade49706cfd4d89ef82793f19 to your computer and use it in GitHub Desktop.
Quick and dirty AES67/Dante SAP/SDP Discovery Service. Change sdpConfig and addr accordingly
var dgram = require('dgram');
var socket = dgram.createSocket({ type: 'udp4', reuseAddr: true });
const PORT = 9875;
const MULTICAST_ADDR = '239.255.255.255';
//options, need to be changed
var addr = '127.0.0.1';
var multicastAddr = '239.69.0.119';
socket.bind(PORT, function(){
socket.setMulticastInterface(addr);
});
var constructSDPMsg = function(){
var sapHeader = Buffer.alloc(8);
var sapContentType = Buffer.from('application/sdp\0');
var ip = addr.split('.');
//write version/options
sapHeader.writeUInt8(0x20);
//write hash
sapHeader.writeUInt16LE(0xefef, 2);
//write ip
sapHeader.writeUInt8(parseInt(ip[0]), 4);
sapHeader.writeUInt8(parseInt(ip[1]), 5);
sapHeader.writeUInt8(parseInt(ip[2]), 6);
sapHeader.writeUInt8(parseInt(ip[3]), 7);
var sdpConfig = [
'v=0',
'o=- 10 0 IN IP4 '+addr,
's=Name',
'c=IN IP4 '+multicastAddr+'/15',
't=0 0',
'a=clock-domain:PTPv2 0',
'm=audio 5004 RTP/AVP 98',
'c=IN IP4 '+multicastAddr+'/15',
'a=rtpmap:98 L24/48000/2',
'a=source-filter: incl IN IP4 '+multicastAddr+' '+addr,
'a=sync-time:0',
'a=framecount:128',
'a=ptime:1',
'a=mediaclk:direct=0',
'a=ts-refclk:ptp=IEEE1588-2008:00-00-00-00-00-00-00-00:0',
'a=recvonly',
''
];
var sdpBody = Buffer.from(sdpConfig.join('\r\n'));
return Buffer.concat([sapHeader, sapContentType, sdpBody]);
}
var sendSDPMsg = function(){
var sdpBuf = constructSDPMsg();
socket.send(sdpBuf, PORT, MULTICAST_ADDR, function(err){});
}
sendSDPMsg();
setInterval(function(){
sendSDPMsg();
}, 30*1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment