Code Monkey home page Code Monkey logo

os2l's Introduction

os2l

NodeJS implementation of the Open Sound to Light protocol.

The standard is defined here. This package was only tested on Windows with VirtualDJ.

Installation

npm install os2l

Usage

For servers

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);
});

For clients

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);
});

Hosting on Windows

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.

Hosting on Linux

To work on Linux, "Avahi" is needed for DNS-SD. (Not tested)

Hosting on MacOS

On MacOS it will work by default. (Not tested)

API

OS2LServer

let server = new OS2LServer({
  port: 1806, // Port for the server to listen on
  doPublish: true // (optional) Use DNS-DS?
});

Event: error

Emitted when an error occours. After this event was called the server will stop and needs to be opened manually via server.start().

Event: warning

Emitted when something happens that should not happen but the server can stay open.

Event: connection

Emitted when a connection from a client was made.

Event: closed

Emitted after the server was closed. Is also called when the server stops because of an error.

Event: btnOn

Emitted when a button is pressed. First argument is the name of the button.

Event: btnOff

Emitted when a button is released. First argument is the name of the button.

Event: cmd

Emitted when a command was send by a client. First argument is the received object.

Event: btn

Emitted when a client changes the state of a button. First argument is the received object.

Event: beat

Emitted when a client sends a beat packet. First argument is the received object.

Event: data

Emitted when anything comes from the client. First argument is the received object. This event can be used to extend the protocol.

server.start()

Starts the server

server.stop()

Stops the server

server.feedback(name, state, page)

Sends feedback to all clients. The arguments are defined in the standard.

OSL2Client

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?
});

Event: error

Emitted after an error occours.

Event: connected

Emitted after a connection was made.

Event: closed

Emitted after the connection ended.

Event: feedback

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.

client.beat(change, pos, bpm)

Sends a beat to the server. Arguments are defined in the standard.

client.buttonOff(name)

Sends a btnOff event to the server. First argument is the name of the button.

client.buttonOn(name)

Sends a btnOn event to the server. First argument is the name of the button.

client.close()

Closes the connection.

client.command(id, param)

Sends a command to the server. id (Integer) is the id of the command and param a number between 0 and 1.

client.connect()

Connects to the server. When no server data is given, this method searches for the server with DNS-SD.

client.custom(object)

Sends a custom object to the server. This method can be used to extend the protocol.

License

MIT

os2l's People

Contributors

dependabot[bot] avatar functiondj avatar lordvonadel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

os2l's Issues

.start() requires a callback function to work

os2l/OS2LServer.js

Lines 113 to 118 in 4039db1

this.net.listen(this.port, () => {
if (callback) {
callback();
resolve();
}
});

It checks if the callback parameter is speficified (not null) and will only then resolve the promise.
Moving the resolve() outside that block should resolve the issue, but i'm not sure so i'm not doing a PR.

Users can fix this issue by just passing a empty callback function to .start() for the time being:
await server.start(() => {})

Potential Open Stage Control Integration

I was wondering if this could integrate as a module for Open Stage Control?

I'll admit I'm brand new to scripting so I'm not sure if what I'm asking is even possible.

I'm looking to build something similar to the Unofficial ETC Sound 2 Light but with the OS2L protocol integrated.

It looks like this would be an awesome backbone used in tandem with Open Stage Control since they are both written with Java Script.

Not working with VirtualDJ 2021

I've tried the example code and many different configuration combinations in both VDJ and the module and couldn't get it to pick anything from VDJ up. Sunlite Suite 3 picks up the BPM from VDJ. Bonjour is installed, i tested both with and without direct IP and port.
Am i doing something wrong? Virtual DJ is version 8.4-64 b5874. Both NodeJS and VirtualDJ have network access.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.