Skip to content

openrv-web / EventsAPI

Class: EventsAPI

Defined in: api/EventsAPI.ts:67

Constructors

Constructor

new EventsAPI(session, _viewer): EventsAPI

Defined in: api/EventsAPI.ts:72

Parameters

session

Session

_viewer

ViewerProvider

Returns

EventsAPI

Methods

dispose()

dispose(): void

Defined in: api/EventsAPI.ts:284

Clean up all listeners and internal subscriptions. After calling this, the EventsAPI instance should not be used.

Returns

void


emitError()

emitError(message, code?): void

Defined in: api/EventsAPI.ts:276

Emit an error event (for internal use by other API modules).

Parameters

message

string

Human-readable error description.

code?

string

Optional machine-readable error code.

Returns

void


getEventNames()

getEventNames(): OpenRVEventName[]

Defined in: api/EventsAPI.ts:160

Get the list of all valid event names that can be subscribed to.

Returns

OpenRVEventName[]

An array of valid event name strings.

Example

ts
const names = openrv.events.getEventNames();

off()

off<K>(event, callback): void

Defined in: api/EventsAPI.ts:122

Unsubscribe a specific callback from an event.

Type Parameters

K

K extends OpenRVEventName

Parameters

event

K

The event name to unsubscribe from.

callback

EventCallback<OpenRVEventData[K]>

The exact callback reference that was passed to on.

Returns

void

Example

ts
openrv.events.off('frameChange', myHandler);

on()

on<K>(event, callback): () => void

Defined in: api/EventsAPI.ts:92

Subscribe to an event. The callback is invoked each time the event fires.

Type Parameters

K

K extends OpenRVEventName

Parameters

event

K

The event name to listen for (see OpenRVEventName).

callback

EventCallback<OpenRVEventData[K]>

Handler function receiving the event-specific data payload.

Returns

An idempotent unsubscribe function. Call it to stop listening.

(): void

Returns

void

Throws

If event is not a valid event name or callback is not a function.

Example

ts
const unsub = openrv.events.on('frameChange', (d) => console.log(d.frame));
unsub(); // stop listening

once()

once<K>(event, callback): () => void

Defined in: api/EventsAPI.ts:139

Subscribe to an event, firing the callback only once then automatically unsubscribing.

Type Parameters

K

K extends OpenRVEventName

Parameters

event

K

The event name to listen for.

callback

EventCallback<OpenRVEventData[K]>

Handler function invoked once with the event data.

Returns

An unsubscribe function (can be called early to cancel before it fires).

(): void

Returns

void

Throws

If event is not a valid event name or callback is not a function.

Example

ts
openrv.events.once('sourceLoaded', (d) => console.log(d.name));

Released under the MIT License.