Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
OSC library for Node.js and the browser, with customizable Plugin API for WebSocket, UDP or bridge networking
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
ws
in Node.js or similar environments)Read more about osc-js and how to use it in the Wiki and Documentation.
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 })
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.
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 messagingBridgePlugin
useful Bridge between WebSocket- and UDP ClientsConfiguration and examples of every plugin can be read here: Wiki.
Register the plugin when creating the OSC instance:
const osc = new OSC({ plugin: new OSC.WebsocketServerPlugin() })
osc.open() // listening on 'ws://localhost:8080'
<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>
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
[udpreceive 9129] // incoming '/test/random' messages with random number
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
})
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)
})
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 git@github.com:adzialocha/osc-js.git
cd osc-js
npm install
npm run test
for running the tests.
npm run test:watch
for running specs during development. Check code style with npm run lint
.
npm run build
for exporting UMD module in lib
folder.
npm run docs
for generating a docs
folder with HTML files documenting the library. Read them online here: https://adzialocha.github.io/osc-js
MIT License MIT
FAQs
OSC library for Node.js and the browser, with customizable Plugin API for WebSocket, UDP or bridge networking
The npm package osc-js receives a total of 298 weekly downloads. As such, osc-js popularity was classified as not popular.
We found that osc-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.