Home Reference Source Test
import EventHandler from 'osc-js/src/events.js'
public class | source

EventHandler

Test:

Constructor Summary

Public Constructor
public

constructor(options: object)

Create an EventHandler instance

Member Summary

Public Members
public
Private Members
private
private
private

Method Summary

Public Methods
public

notify(args: ...*): boolean

Notify the EventHandler of incoming OSC messages or status changes (open, close, error).

public

off(name: string, subscriptionId: number): boolean

Unsubscribe listener from event notification or address handler

public

on(name: string, callback: function): number

Subscribe to a new address or event you want to listen to

Private Methods
private

call(name: string, data: *): boolean

Internally used method to invoke listener callbacks.

private

dispatch(packet: Packet): boolean

Internally used method to dispatch OSC Packets.

Public Constructors

public constructor(options: object) source

Create an EventHandler instance

Params:

NameTypeAttributeDescription
options object

Custom options

Public Members

public uuid: number source

Private Members

private addressHandlers: array source

private eventHandlers: object source

private options: object source

Public Methods

public notify(args: ...*): boolean source

Notify the EventHandler of incoming OSC messages or status changes (open, close, error). Handles OSC address patterns and executes timed messages. Use binary arrays when handling directly incoming network data. Packet's or Messages can also be used

Params:

NameTypeAttributeDescription
args ...*

The OSC address pattern / event name as string}. For convenience and Plugin API communication you can also use Message or Packet instances or ArrayBuffer, Buffer instances (low-level access). The latter will automatically be unpacked When using a string you can also pass on data as a second argument (any type). All regarding listeners will be notified with this data. As a third argument you can define a javascript timestamp (number or Date instance) for timed notification of the listeners.

Return:

boolean

Success state of notification

Example:

const socket = dgram.createSocket('udp4')
socket.on('message', (message) => {
  this.notify(message)
})
this.notify('error', error.message)
const message = new OSC.Message('/test/path', 55)
this.notify(message)
const message = new OSC.Message('/test/path', 55)
// override timestamp
this.notify(message.address, message, Date.now() + 5000)

Test:

public off(name: string, subscriptionId: number): boolean source

Unsubscribe listener from event notification or address handler

Params:

NameTypeAttributeDescription
name string

The OSC address or event name

subscriptionId number

Subscription id to identify the handler

Return:

boolean

Success state

Test:

public on(name: string, callback: function): number source

Subscribe to a new address or event you want to listen to

Params:

NameTypeAttributeDescription
name string

The OSC address or event name

callback function

Callback function on notification

Return:

number

Subscription identifier (needed to unsubscribe)

Test:

Private Methods

private call(name: string, data: *): boolean source

Internally used method to invoke listener callbacks. Uses regular expression pattern matching for OSC addresses

Params:

NameTypeAttributeDescription
name string

OSC address or event name

data *
  • optional

The data of the event

Return:

boolean

Success state

private dispatch(packet: Packet): boolean source

Internally used method to dispatch OSC Packets. Extracts given Timetags and dispatches them accordingly

Params:

NameTypeAttributeDescription
packet Packet

Return:

boolean

Success state