• Stars
    star
    256
  • Rank 159,219 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OSC library for Node.js, Electron, Chrome Apps, Webpages or any other JS application. It comes with a customizable Plugin API for WebSocket, UDP or bridge networking

osc-js

Build status npm version npm licence ESDoc status

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

More Repositories

1

angular-swipe

Simple vertical and horizontal swipe gesture directive for angular js
JavaScript
87
star
2

8bit

Notes on building a 8bit CPU
Assembly
50
star
3

hoffnung3000

Platform for decentralized, anonymized, self-curated festivals
JavaScript
36
star
4

tomomibot

Artificial intelligence bot for live voice improvisation
Python
30
star
5

document-generator

Generate your .pdf invoices, letters, documents, etc. with templates based on YAML, HTML & SCSS
JavaScript
23
star
6

random-animal-name-generator

It's a random animal name generator!
JavaScript
19
star
7

angular-watch-resource

Model Layer for AngularJS based on $watch pattern
JavaScript
14
star
8

tinychronicler

Travelling music robot
Jupyter Notebook
7
star
9

graffiti

Browser extension to tag the web
TypeScript
7
star
10

gnome-p2panda-workshop

Rust
7
star
11

kubismus

Experimental OSC Editor
JavaScript
7
star
12

it8951-video

Play videos on IT8951-controlled e-paper displays
Rust
6
star
13

solo-link-m4l

Max / M4L object for OSC communication and direct control of Ableton Live
6
star
14

p2p-chat

Simple p2p chat with mDNS discovery, append-only log data structure and replication protocol for learning purposes
Rust
6
star
15

fishy

Rust
5
star
16

cybernetic-gamelan-future-automaton

Network-based browser game for human laptop performers
JavaScript
5
star
17

swarm-animism

CTM HackLab 2018
JavaScript
3
star
18

doggodroid

Experiments with embedding aquadoggo inside a native Android app
Kotlin
3
star
19

mission-control-bridge

iOS app bridge (via usb) between local mission-control-server and firebase data
Objective-C
3
star
20

toy-hypercore

A toy p2p chat protocol implementation
Rust
3
star
21

NOR

OSC Interface for musical free improvisation in a highly artifical environment
JavaScript
2
star
22

homepage

My Homepage
SCSS
2
star
23

y-e-s

Platform for intermedial scores
JavaScript
2
star
24

bits-panda-fun

p2panda hacksession with bitspossessed
JavaScript
2
star
25

wolke

Deploy Nextcloud via Docker
Shell
2
star
26

mission-control-server

Intermedial BLATT 3000 lecture at UNM Festival 2016, Aarhus.
JavaScript
2
star
27

mission-control-app

Audience interaction webapp for BLATT 3000 lecture at UNM Festival 2016, Aarhus.
JavaScript
2
star
28

verantwortung3000

Platform for self curated festivals
Ruby
1
star
29

grinm-donaueschingen

GRINM @ Donaueschingen 2017
HTML
1
star
30

solo-controller

Solo EP (2015) - osc controller
JavaScript
1
star
31

kleiner

Simple PHP Web Framework
PHP
1
star
32

gif-stream

Client: Take pictures from peoples cameras in intervals, make a .gif, upload it to S3, make a massive collage out of this
JavaScript
1
star
33

dotfiles

My dotfiles
Shell
1
star
34

mediapipe

Experiments w. Mediapipe
Python
1
star
35

notebook

Jupyter notebooks for random experiments with audio processing, data analysis and machine learning
Jupyter Notebook
1
star
36

static-hedgedoc

Generate a static page from Hedgedoc Markdown document
Rust
1
star
37

splitter-orchester

Website of Splitter Orchester Berlin
TypeScript
1
star
38

dead-composers-api

Dead Composers API
PHP
1
star
39

time-tracker

Analyse worked time based on GitHub PRs, commits and issue events
JavaScript
1
star
40

solo

Miniatures for electric bass (2015)
JavaScript
1
star
41

kubismus-legacy

Compositional OSC environment for microscopical parameter-changes while having a macroscopical overview.
C++
1
star
42

gif-stream-server

Server: Take pictures from peoples cameras in intervals, make a .gif, upload it to S3, make a massive collage out of this
Go
1
star
43

solo-link

OSC Controller for Ableton Live
JavaScript
1
star