Code Monkey home page Code Monkey logo

osc-msg's Introduction

osc-msg

Build Status NPM Version License

OSC message decoder/encoder with fault tolerant

Features

  • Not throw an exception if processing with a broken message
  • Useful decoding options, bundle and strip
  • Works in both Node.js and browsers

Installation

npm:

npm install osc-msg

API

  • oscmsg.decode(buffer: Buffer, opts={}): object
    • opts.strict: strictly validation mode
    • opts.strip: decode into raw values
    • opts.bundle: decode as a bundle
    • aliases: fromBuffer, toObject
  • oscmsg.encode(object: object, opts={}): Buffer
    • opts.strict: strictly validation mode
    • opts.integer: use an integer when auto cast
    • aliases: fromObject, toBuffer

Examples

decode

const dgram = require("dgram");
const oscmsg = require("osc-msg");

const socket = dgram.createSocket("udp4");

socket.on("message", (buffer) => {
  const bundle = oscmsg.decode(buffer, { strict: true, strip: true, bundle: true });

  if (bundle.error) {
    return;
  }

  bundle.elements.forEach((message) => {
    console.log(JSON.stringify(message));    
  });
});

socket.bind(RECV_PORT);

encode

const dgram = require("dgram");
const oscmsg = require("osc-msg");

const message = {
  address: "/foo",
  args: [
    { type: "integer", value: 0 },
    { type: "float", value: 1.5 }
  ]
};
const buffer = oscmsg.encode(message);
const socket = dgram.createSocket("udp4");

socket.send(buffer, 0, buffer.length, SEND_PORT, "127.0.0.1");

Javascript representations of the OSC types

compatible interfaces with osc-min

  • OSC Message
{
  "address": string,
  "args": [ arg1, arg2, ...argN ],
  "oscType": "message"
}

Where args is an array of OSC Arguments. oscType is optional. args can be a single element.

  • OSC Arguments
{ "type": string, "value": any }

Where the type is one of the following:

  • string - string value

  • float - numeric value

  • integer - numeric value

  • blob - Buffer-like value

  • true - value is boolean true

  • false - value is boolean false

  • null - no value

  • bang - no value (this is the I type tag)

  • timetag - [ uint32, uint32 ]

  • array - array of OSC Arguments

  • OSC Bundle

{
  "timetag": number,
  "elements": [ element1, element2, ...elementN ],
  "oscType": "bundle"
}

Where the timetag is a javascript-native numeric value of the timetag, and elements is an array of either an OSC Bundle or an OSC Message The oscType field is optional, but is always returned by api functions.

See also

License

MIT

osc-msg's People

Contributors

mohayonao avatar

Watchers

 avatar

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.