Last active
May 28, 2024 00:07
-
-
Save oligriffiths/9b810a442d8c939191e662ab6a7e6b9e to your computer and use it in GitHub Desktop.
Resolume artnet proxy to batch universes and send with sequencing
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
// Install: yarn add @rtf-dm/artnet-lib | |
import dgram from "dgram"; | |
import { DmxPacket } from "./node_modules/@rtf-dm/artnet-lib/build/core/packets/dmx-packet.js"; | |
import { SyncPacket } from "./node_modules/@rtf-dm/artnet-lib/build/core/packets/sync-packet.js"; | |
console.log('Starting...'); | |
const LEDS = 100; | |
const PORT = 6454; | |
(async () => { | |
const localSocket = dgram.createSocket({ type: 'udp4', reuseAddr: true }); | |
const artReplySocket = dgram.createSocket({ type: 'udp4' }); | |
const sendSocket = dgram.createSocket({ type: 'udp4' }); | |
await sendSocket.connect(PORT, '192.168.1.11'); | |
let sequences = {}; | |
let sequenceId = 1; | |
const sendSync = () => { | |
const sync = new SyncPacket(); | |
const buffer = sync.encode(); | |
sendSocket.send(buffer, 0, buffer.length); | |
} | |
const onMessage = async (message, rinfo) => { | |
if (!DmxPacket.isArtNetPacket(message)) { | |
return; | |
} | |
if (DmxPacket.is(message)) { | |
const inPacket = (new DmxPacket).decode(message); | |
inPacket.sequence = sequenceId; | |
inPacket.dmxData = inPacket.dmxData.slice(0, LEDS * 3); | |
sequences[inPacket.subNet] = new DmxPacket(inPacket); | |
const keys = Object.keys(sequences); | |
if (keys.length === 12) { | |
// Send this sequence of universes | |
for (let i = 0; i < keys.length; i++) { | |
const universe = keys[i]; | |
const packet = sequences[universe]; | |
const buffer = packet.encode(); | |
sendSocket.send(buffer, 0, buffer.length); | |
} | |
// Send the sync message to output DMX to LEDs | |
sendSync(); | |
sequenceId++; | |
sequences = {}; | |
if (sequenceId > 255) { | |
sequenceId = 1; | |
} | |
} | |
} | |
}; | |
localSocket.on('listening', () => { | |
console.log('listening'); | |
localSocket.setBroadcast(true); | |
}); | |
localSocket.on('message', onMessage); | |
console.log('Binding...'); | |
localSocket.bind(PORT, '0.0.0.0'); // ArtDmx received on this address | |
process.on('SIGINT', function() { | |
sendSocket.close(); | |
artReplySocket.close(); | |
localSocket.close(); | |
process.exit() | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment