npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

osc-js

v2.4.1

Published

OSC library for Node.js and the browser, with customizable Plugin API for WebSocket, UDP or bridge networking

Downloads

2,364

Readme

osc-js

osc-js is an Open Sound Control library for JavaScript applications (UMD module for Node, Browser etc.) with address pattern matching and timetag handling. Sends messages via UDP, WebSocket or both (bridge mode) and offers a customizable Plugin API for network protocols.

Wiki | Basic Usage | Documentation | Plugin API

Features

  • UMD Module running in Node.js, Electron, Chrome Apps, browser or any other JS environment
  • Can be used with Webpack and Browserify
  • TypeScript definitions
  • No dependencies (except of ws in Node.js or similar environments)
  • Receive sender information from incoming messages
  • Built-in UDP, WebSocket networking support as plugins
  • Special bridge plugin for easy communication between UDP- and WebSocket clients
  • Plugin API for custom network protocols
  • Featuring all OSC 1.0 specifications
  • OSC Address pattern matching
  • Time-critical OSC Bundles with Timetags
  • Extended (nonstandard) argument types

Documentation

Read more about osc-js and how to use it in the Wiki and Documentation.

Example

const osc = new OSC()

osc.on('/param/density', (message, rinfo) => {
  console.log(message.args)
  console.log(rinfo)
})

osc.on('*', message => {
  console.log(message.args)
})

osc.on('/{foo,bar}/*/param', message => {
  console.log(message.args)
})

osc.on('open', () => {
  const message = new OSC.Message('/test', 12.221, 'hello')
  osc.send(message)
})

osc.open({ port: 9000 })

Installation and Usage

Recommended installation via npm: npm i osc-js or yarn add osc-js.

Import the library const OSC = require('osc-js') or add the script lib/osc.js or lib/osc.min.js (minified version) for usage in a browser.

Plugins

osc-js offers a plugin architecture for extending it's networking capabilities. The library comes with four built-in plugins. This is propably all you need for an OSC application:

  • WebsocketClientPlugin (default)
  • WebsocketServerPlugin
  • DatagramPlugin for UDP network messaging
  • BridgePlugin useful Bridge between WebSocket- and UDP Clients

Configuration and examples of every plugin can be read here: Wiki.

Example: WebSocket Server

Register the plugin when creating the OSC instance:

const osc = new OSC({ plugin: new OSC.WebsocketServerPlugin() })
osc.open() // listening on 'ws://localhost:8080'

Example: OSC between MaxMSP/PD/SC etc. and your browser

  1. Write a simple webpage. The library will use a WebSocket client by default.
<button id="send">Send Message</button>
<script type="text/javascript" src="lib/osc.min.js"></script>
<script type="text/javascript">
  var osc = new OSC();
  osc.open(); // connect by default to ws://localhost:8080

  document.getElementById('send').addEventListener('click', () => {
    var message = new OSC.Message('/test/random', Math.random());
    osc.send(message);
  });
</script>
  1. Write a Node app (the "bridge" between your UDP and WebSocket clients).
const OSC = require('osc-js')

const config = { udpClient: { port: 9129 } }
const osc = new OSC({ plugin: new OSC.BridgePlugin(config) })

osc.open() // start a WebSocket server on port 8080
  1. Create your Max/MSP patch (or PD, SuperCollider etc.).
[udpreceive 9129] // incoming '/test/random' messages with random number

Custom solutions with Plugin API

It is possible to write more sophisticated solutions for OSC applications without loosing the osc-js interface (including its message handling etc.). Read the Plugin API documentation for further information.

class MyCustomPlugin {
  // ... read docs for implementation details
}

const osc = new OSC({ plugin: MyCustomPlugin() })
osc.open()

osc.on('/test', message => {
  // use event listener with your plugin
})

Usage without plugins

The library can be used without the mentioned features in case you need to write and read binary OSC data. See this example below for using the Low-Level API (even though the library already has a solution for handling UDP like in this example):

const dgram = require('dgram')
const OSC = require('osc-js')

const socket = dgram.createSocket('udp4')

// send a messsage via udp
const message = new OSC.Message('/some/path', 21)
const binary = message.pack()
socket.send(new Buffer(binary), 0, binary.byteLength, 41234, 'localhost')

// receive a message via UDP
socket.on('message', data => {
  const msg = new OSC.Message()
  msg.unpack(data)
  console.log(msg.args)
})

Development

osc-js uses Babel for ES6 support, ESDoc for documentation, Mocha + Chai for testing and Rollup for generating the UMD module.

Clone the repository and install all dependencies:

git clone [email protected]:adzialocha/osc-js.git
cd osc-js
npm install

Testing

npm run test for running the tests. npm run test:watch for running specs during development. Check code style with npm run lint.

Deployment

npm run build for exporting UMD module in lib folder.

Contributors

ESDocs

npm run docs for generating a docs folder with HTML files documenting the library. Read them online here: https://adzialocha.github.io/osc-js

License

MIT License MIT