NodeJS implementation of the Open Sound to Light protocol.
The standard is defined here. This package was only tested on Windows with VirtualDJ.
npm install os2l
Usually the DMX software:
const { OS2LServer} = require("os2l");
// All options are optional
let server = new OS2LServer({
port: 5000 // TCP Port to listen on
});
// Register events
server.on("error", err => {
console.error(err);
});
server.on("btnOn", name => {
if (name == "fog") {
// ... code for starting a fog machine
server.feedback("fog", "on");
}
});
server.on("btnOff", name => {
if (name == "fog") {
// ... code for stopping a fog machine
server.feedback("fog", "off");
}
});
server.on("beat", data => {
// Toggle light or something
});
// Start the server
server.start().then(() => {
console.log("Server is now listening on port: ", server.port);
});
Usually the audio software:
const {OS2LClient} = require("os2l");
let client = new OS2LClient();
client.on("error", err => console.error(err));
client.on("feedback", data => {
// Let a button light up or something
});
client.connect().then(() => {
client.buttonOn("hi");
client.beat(true, 1, 120);
});
To host on windows, "Bonjour Print Services" or the SDK needs to be installed on the host system. It is needed for DNS service discovery. When addresses and ports are given manually, this is not needed.
I don't like that we need to depend on an Apple product for this to work. A DNS-SD service is already implemented in windows 10 but is not accessible to us. This is a good starting point to dig deeper and maybe find a solution.
To work on Linux, "Avahi" is needed for DNS-SD. (Not tested)
On MacOS it will work by default. (Not tested)
The characters {
and }
in strings like button names may produce errors during parsing of incoming packet data. However, when starting with an open bracket and matching the count with closing brackets after that should work. So a name like Very{cool}button
is still a valid parsable name.
let server = new OS2LServer({
port: 1806, // Port for the server to listen on
doPublish: true // (optional) Use DNS-DS?
});
Emitted when an error occours. After this event was called the server will stop and needs to be opened manually via server.start()
.
Emitted when something happens that should not happen but the server can stay open.
Emitted when a connection from a client was made.
Emitted after the server was closed. Is also called when the server stops because of an error.
Emitted when a button is pressed. First argument is the name of the button.
Emitted when a button is released. First argument is the name of the button.
Emitted when a command was send by a client. First argument is the received object.
Emitted when a client changes the state of a button. First argument is the received object.
Emitted when a client sends a beat packet. First argument is the received object.
Emitted when anything comes from the client. First argument is the received object. This event can be used to extend the protocol.
Starts the server
Stops the server
Sends feedback to all clients. The arguments are defined in the standard.
let client = new OS2LClient({
port: 1806, // (optional) The port to connect to
host: "localhost", // (optional) Hostname of the server
useDNS_SD: false, // (optional) Use DNS-SD? Is this is set to true, host and port are determined automatically.
autoReconnect: true, // (optional) Reconnect after connection lost?
autoReconnectInterval: 1000 // (optional) Milliseconds between tries when auto reconnect in true
});
Emitted after an error occours.
Emitted after a connection was made.
Emitted after the connection ended.
Emitted when the server sends feedback. The arguments are name, state and page. When no page was given this argument is undefined as this argument is optional to the standard.
Sends a beat to the server. Arguments are defined in the standard.
Sends a btnOff
event to the server. First argument is the name of the button.
Sends a btnOn
event to the server. First argument is the name of the button.
Closes the connection.
Sends a command to the server. id
(Integer) is the id of the command and param
a number between 0 and 1.
Connects to the server. When no server data is given, this method searches for the server with DNS-SD.
Sends a custom object to the server. This method can be used to extend the protocol.