OSC
Test:
Constructor Summary
Public Constructor | ||
public |
constructor(options: object) Create an OSC instance with given options |
Member Summary
Private Members | ||
private |
|
|
private |
|
Method Summary
Public Methods | ||
public |
close(): * Close connection. |
|
public |
Unsubscribe an event listener |
|
public |
Listen to a status-change event or incoming OSC message with address pattern matching |
|
public |
Open network socket with plugin. |
|
public |
Send an OSC Packet, Bundle or Message. |
|
public |
Returns the current status of the connection. |
Public Constructors
public constructor(options: object) source
Create an OSC instance with given options
Params:
Name | Type | Attribute | Description |
options | object |
|
Custom options |
options.discardLateMessages | boolean |
|
Ignore incoming messages when given timetag lies in the past |
options.plugin | Plugin |
|
Add a connection plugin to this interface, defaults to a plugin with Websocket client. Open README.md for further information on how to handle plugins or how to write your own with the Plugin API |
Example:
const osc = new OSC() // default options with Websocket client
const osc = new OSC({ discardLateMessages: true })
const websocketPlugin = new OSC.WebsocketClientPlugin()
const osc = new OSC({ plugin: websocketPlugin })
Public Methods
public close(): * source
Close connection. This method is used by plugins and is not available without (see Plugin API for more information)
Return:
* |
Test:
public off(eventName: string, subscriptionId: number): boolean source
Unsubscribe an event listener
Example:
const listenerId = osc.on('error', message => {
console.log(message)
})
osc.off('error', listenerId) // unsubscribe from error event
Test:
public on(eventName: string, callback: function): number source
Listen to a status-change event or incoming OSC message with address pattern matching
Example:
// will be called when server receives /in!trument/* for example
osc.on('/instrument/1', message => {
console.log(message)
})
// will be called for every message since it uses the wildcard symbol
osc.on('*', message => {
console.log(message)
})
// will be called on network socket error
osc.on('error', message => {
console.log(message)
})
Test:
public open(options: object): * source
Open network socket with plugin. This method is used by plugins and is not available without (see Plugin API for more information)
Params:
Name | Type | Attribute | Description |
options | object |
|
Custom global options for plugin instance |
Return:
* |
Example:
const osc = new OSC({ plugin: new OSC.DatagramPlugin() })
osc.open({ host: '127.0.0.1', port: 8080 })
Test:
public send(packet: Packet | Bundle | Message | TypedMessage, options: object): * source
Send an OSC Packet, Bundle or Message. This method is used by plugins and is not available without (see Plugin API for more information)
Return:
* |
Example:
const osc = new OSC({ plugin: new OSC.DatagramPlugin() })
osc.open({ host: '127.0.0.1', port: 8080 })
const message = new OSC.Message('/test/path', 55.1, 57)
osc.send(message)
// send message again to custom address
osc.send(message, { host: '192.168.178.115', port: 9001 })
Test:
public status(): number source
Returns the current status of the connection. See STATUS for different possible states. This method is used by plugins and is not available without (see Plugin API for more information)
Example:
import OSC, { STATUS } from 'osc'
const osc = new OSC()
if (osc.status() === STATUS.IS_CONNECTING) {
// do something
}