Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

osc-min

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

osc-min - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

dist/index.d.ts

65

package.json
{
"name": "osc-min",
"version": "1.1.2",
"main": "lib/index",
"version": "2.0.0",
"author": {

@@ -21,22 +20,18 @@ "name": "Russell McClellan",

},
"dependencies": {
"binpack": "~0"
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"devDependencies": {
"mocha": "2.*",
"docket": "0.0.5",
"coveralls": "*",
"blanket": "*",
"mocha-lcov-reporter": "*",
"coffee-script": ">=1.7.1 <2.0.0",
"browserify": "^6.1.0",
"uglify-js": "^2.4.15"
"@eslint/js": "^9.12.0",
"@types/jest": "^29.5.13",
"eslint": "^9.12.0",
"eslint-plugin-prefer-arrow-functions": "^3.4.1",
"globals": "^15.11.0",
"jest": "^29.7.0",
"markdown-magic": "^3.3.0",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3",
"typescript-eslint": "^8.8.1"
},
"config" : {
"blanket": {
"loader" : "./node-loaders/coffee-script",
"pattern" : "lib",
"data-cover-never": "node_modules"
}
},
"directories": {

@@ -50,15 +45,25 @@ "lib": "lib",

},
"type": "module",
"scripts": {
"test": "cake test",
"coverage": "cake coverage",
"coveralls": "cake coveralls",
"doc": "cake doc",
"prepublish" : "cake doc; coffee -c lib/osc-utilities.coffee",
"browserify" : "cake browserify"
"prepublish": "npm run build && npm run docs",
"build": "tsc",
"docs": "md-magic readme.md",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"lint": "eslint"
},
"_id": "osc-min@0.0.5",
"dist": {
"shasum": "ead2d1b1e7ff2382e4dad0f7aaa8aa20832118b1"
},
"_from": "osc-min@0.0.5"
"jest": {
"testEnvironment": "node",
"testRegex": "(/test/.*\\.test\\.ts$)",
"transform": {
"^.+.ts$": [
"ts-jest",
{
"tsconfig": {
"strict": false,
"strictNullChecks": true
}
}
]
}
}
}

@@ -1,2 +0,1 @@

[![build status](https://secure.travis-ci.org/russellmcc/node-osc-min.png)](http://travis-ci.org/russellmcc/node-osc-min) [![Coverage Status](https://coveralls.io/repos/russellmcc/node-osc-min/badge.png?branch=master)](https://coveralls.io/r/russellmcc/node-osc-min?branch=master) [![dependencies](https://david-dm.org/russellmcc/node-osc-min.png)](https://david-dm.org/russellmcc/node-osc-min)
# osc-min

@@ -6,7 +5,7 @@

This package provides some node.js utilities for working with
This package provides some node.js utilities for working with
[OSC](http://opensoundcontrol.org/), a format for sound and systems control.
Here we implement the [OSC 1.1][spec11] specification. OSC is a transport-independent
protocol, so we don't provide any server objects, as you should be able to
use OSC over any transport you like. The most common is probably udp, but tcp
Here we implement the [OSC 1.1][spec11] specification. OSC is a transport-independent
protocol, so we don't provide any server objects, as you should be able to
use OSC over any transport you like. The most common is probably udp, but tcp
is not unheard of.

@@ -16,47 +15,17 @@

----
## Installation
The easiest way to get osc-min is through [NPM](http://npmjs.org).
After install npm, you can install osc-min in the current directory with
```
npm install osc-min
```
If you'd rather get osc-min through github (for example, if you're forking
it), you still need npm to install dependencies, which you can do with
```
npm install
```
Once you've got all the dependencies you should be able to run the unit
tests with
```
npm test
npm run-script coverage
```
---
### For the browser
If you want to use this library in a browser, you can build a browserified file (`build/osc-min.js`) with
## Examples
```
npm install
npm run-script browserify
```
Further examples available in the `examples` folder.
----
## Examples
### A simple OSC printer;
```javascript
### A simple OSC server that prints any received messages
sock = udp.createSocket("udp4", function(msg, rinfo) {
var error, error1;
<!-- doc-gen CODE src="examples/printosc.mjs" lines="8-16" syntax="js" -->
```js
const sock = udp.createSocket("udp4", (msg) => {
try {
return console.log(osc.fromBuffer(msg));
} catch (error1) {
error = error1;
return console.log("invalid OSC packet");
console.log(osc.fromBuffer(msg));
} catch (e) {
console.log("invalid OSC packet", e);
}

@@ -66,37 +35,48 @@ });

sock.bind(inport);
```
### Send a bunch of args every two seconds;
```javascript
<!-- end-doc-gen -->
sendHeartbeat = function() {
var buf;
buf = osc.toBuffer({
### Send a message containing multiple arguments every 2 seconds
<!-- doc-gen CODE src="examples/oscheartbeat.mjs" lines="9-25" syntax="js" -->
```js
const sendHeartbeat = () => {
const buf = toBuffer({
address: "/heartbeat",
args: [
12, "sttttring", new Buffer("beat"), {
12,
"sttttring",
new TextEncoder().encode("beat"),
{
type: "integer",
value: 7
}
]
value: 7,
},
],
});
return udp.send(buf, 0, buf.length, outport, "localhost");
return udp.send(buf, 0, buf.byteLength, outport, "localhost");
};
setInterval(sendHeartbeat, 2000);
```
### A simple OSC redirecter;
```javascript
<!-- end-doc-gen -->
sock = udp.createSocket("udp4", function(msg, rinfo) {
var error, error1, redirected;
### A simple OSC re-director
<!-- doc-gen CODE src="examples/osc-redirect.mjs" lines="10-28" syntax="js"-->
```js
const sock = dgram.createSocket("udp4", (msg) => {
try {
redirected = osc.applyAddressTransform(msg, function(address) {
return "/redirect" + address;
});
return sock.send(redirected, 0, redirected.length, outport, "localhost");
} catch (error1) {
error = error1;
return console.log("error redirecting: " + error);
const redirected = osc.applyAddressTransform(
msg,
(address) => `/redirect${address}`
);
return sock.send(
redirected,
0,
redirected.byteLength,
outport,
"localhost"
);
} catch (e) {
return console.log(`error redirecting: ${e}`);
}

@@ -106,161 +86,94 @@ });

sock.bind(inport);
```
<!-- end-doc-gen -->
---
more examples are available in the `examples/` directory.
## Javascript representations of the OSC types.
----
## Exported functions
See the [spec][spec] for more information on the OSC types.
------
### .fromBuffer(buffer, [strict])
takes a node.js Buffer of a complete _OSC Packet_ and
outputs the javascript representation, or throws if the buffer is ill-formed.
- An _OSC Packet_ is an _OSC Message_ or an _OSC Bundle_.
`strict` is an optional parameter that makes the function fail more often.
- An _OSC Message_:
----
### .toBuffer(object, [strict])
takes a _OSC packet_ javascript representation as defined below and returns
a node.js Buffer, or throws if the representation is ill-formed.
{
oscType : "message"
address : "/address/pattern/might/have/wildcards"
args : [arg1,arg2]
}
See "JavaScript representations of the OSC types" below.
Where args is an array of _OSC Arguments_. `oscType` is optional.
`args` can be a single element.
----
### .toBuffer(address, args[], [strict])
alternative syntax for above. Assumes this is an _OSC Message_ as defined below,
and `args` is an array of _OSC Arguments_ or single _OSC Argument_
- An _OSC Argument_ is represented as a javascript object with the following layout:
----
### .applyAddressTransform(buffer, transform)
takes a callback that takes a string and outputs a string,
and applies that to the address of the message encoded in the buffer,
and outputs an encoded buffer.
{
type : "string"
value : "value"
}
If the buffer encodes an _OSC Bundle_, this applies the function to each address
in the bundle.
Where the `type` is one of the following:
There's two subtle reasons you'd want to use this function rather than
composing `fromBuffer` and `toBuffer`:
- Future-proofing - if the OSC message uses an argument typecode that
we don't understand, calling `fromBuffer` will throw. The only time
when `applyAddressTranform` might fail is if the address is malformed.
- Accuracy - javascript represents numbers as 64-bit floats, so some
OSC types will not be able to be represented accurately. If accuracy
is important to you, then, you should never convert the OSC message to a
javascript representation.
- `string` - string value
- `float` - numeric value
- `integer` - numeric value
- `color` - JS object containing `red`, `green`, `blue`, `alpha` in range 0-255
- `midi` - four-element array of numbers representing a midi packet of data
- `symbol` - string value
- `character` - a single-character string
- `double` - numeric value
- `bigint` - 64-bit `bigint` value (watch out, this will be truncated to 64 bits!)
- `blob` - `ArrayBuffer`, `DataView`, `TypedArray` or node.js `Buffer`
- `true` - value is boolean true
- `false` - value is boolean false
- `null` - no value
- `bang` - no value (this is the `I` type tag)
- `timetag` - Javascript `Date`
- `array` - array of _OSC Arguments_
----
### .applyMessageTransform(buffer, transform)
takes a function that takes and returns a javascript _OSC Message_ representation,
and applies that to each message encoded in the buffer,
and outputs a new buffer with the new address.
Note that `type` is always a string - i.e. `"true"` rather than `true`.
If the buffer encodes an osc-bundle, this applies the function to each message
in the bundle.
The following non-standard types are also supported:
See notes above for applyAddressTransform for why you might want to use this.
While this does parse and re-pack the messages, the bundle timetags are left
in their accurate and prestine state.
- `double` - numeric value (encodes to a float64 value)
----
### .timetagToDate(ntpTimeTag)
Convert a timetag array to a JavaScript Date object in your local timezone.
For messages sent to the `toBuffer` function, `type` is optional.
If the argument is not an object, it will be interpreted as either
`string`, `float`, `array` or `blob`, depending on its javascript type
(String, Number, Array, Buffer, respectively)
Received OSC bundles converted with `fromBuffer` will have a timetag array:
[secondsSince1970, fractionalSeconds]
This utility is useful for logging. Accuracy is reduced to milliseconds.
- An _OSC Bundle_ is represented as a javascript object with the following fields:
----
### .dateToTimetag(date)
Convert a JavaScript Date to a NTP timetag array [secondsSince1970, fractionalSeconds].
{
oscType : "bundle"
timetag : 7
elements : [element1, element]
}
`toBuffer` already accepts Dates for timetags so you might not need this function. If you need to schedule bundles with finer than millisecond accuracy then you could use this to help assemble the NTP array.
`oscType` "bundle"
----
### .timetagToTimestamp(timeTag)
Convert a timetag array to the number of seconds since the UNIX epoch.
`timetag` is one of:
- `Date` - a JavaScript Date object
- `Array` - `[numberOfSecondsSince1900, fractionalSeconds]`
Both values are `number`s. This gives full timing accuracy of 1/(2^32) seconds.
----
### .timestampToTimetag(timeStamp)
Convert a number of seconds since the UNIX epoch to a timetag array.
`elements` is an `Array` of either _OSC Message_ or _OSC Bundle_
## [spec]: http://opensoundcontrol.org/spec-1_0
----
## Javascript representations of the OSC types.
See the [spec][spec] for more information on the OSC types.
## Migrating from 1.0
+ An _OSC Packet_ is an _OSC Message_ or an _OSC Bundle_.
There have been a few breaking changes from the 1.0 version:
+ An _OSC Message_:
- We now provide type declarations for typescript compatibility
- We always enable the previously optional "strict" errors
- Many explicit error messages for passing in data of the wrong type have been removed. We encourage you to use typescript to prevent these sorts of errors.
- Functions that used to return `Buffer` now return `DataView`
- TimeTags must be specified as `Date`s or `[number, number]` arrays, and are always returned as `[number, number]` arrays. To convert between arrays and `Date`s, use `dateToTimetag` and `timetagToDate`.
- The two-argument version of `toBuffer` has been removed.
{
oscType : "message"
address : "/address/pattern/might/have/wildcards"
args : [arg1,arg2]
}
## License
Where args is an array of _OSC Arguments_. `oscType` is optional.
`args` can be a single element.
+ An _OSC Argument_ is represented as a javascript object with the following layout:
{
type : "string"
value : "value"
}
Where the `type` is one of the following:
+ `string` - string value
+ `float` - numeric value
+ `integer` - numeric value
+ `blob` - node.js Buffer value
+ `true` - value is boolean true
+ `false` - value is boolean false
+ `null` - no value
+ `bang` - no value (this is the `I` type tag)
+ `timetag` - numeric value
+ `array` - array of _OSC Arguments_
Note that `type` is always a string - i.e. `"true"` rather than `true`.
The following non-standard types are also supported:
+ `double` - numeric value (encodes to a float64 value)
For messages sent to the `toBuffer` function, `type` is optional.
If the argument is not an object, it will be interpreted as either
`string`, `float`, `array` or `blob`, depending on its javascript type
(String, Number, Array, Buffer, respectively)
+ An _OSC Bundle_ is represented as a javascript object with the following fields:
{
oscType : "bundle"
timetag : 7
elements : [element1, element]
}
`oscType` "bundle"
`timetag` is one of:
- `null` - meaning now, the current time.
By the time the bundle is received it will too late and depending
on the receiver may be discarded or you may be scolded for being late.
- `number` - relative seconds from now with millisecond accuracy.
- `Date` - a JavaScript Date object in your local time zone.
OSC timetags use UTC timezone, so do not try to adjust for timezones,
this is not needed.
- `Array` - `[numberOfSecondsSince1900, fractionalSeconds]`
Both values are `number`s. This gives full timing accuracy of 1/(2^32) seconds.
`elements` is an `Array` of either _OSC Message_ or _OSC Bundle_
[spec]: http://opensoundcontrol.org/spec-1_0
----
## License
Licensed under the terms found in COPYING (zlib license)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc