Skip to main content

Class: VonageMediaProcessor

Class wrapping features provided by ml-transformers.

Hierarchy

Methods

profile

Static profile(duration): Promise<WebglProfilerReporter>

Parameters

NameType
durationnumber

Returns

Promise<WebglProfilerReporter>


create

Static create(config): Promise<VonageMediaProcessor>

Asynchronous constructor of VonageMediaProcessor

Parameters

NameTypeDescription
configBackgroundOptionsInitial MediaProcessorConfig to use

Returns

Promise<VonageMediaProcessor>

Promise resolved with an initialized MediaProcessorConfig


mixin

Static mixin(emitteryPropertyName, methodNames?): <T>(klass: T) => T

In TypeScript, it returns a decorator which mixins Emittery as property emitteryPropertyName and methodNames, or all Emittery methods if methodNames is not defined, into the target class.

Example

import Emittery from 'emittery';

@Emittery.mixin('emittery')
class MyClass {}

const instance = new MyClass();

instance.emit('event');

Parameters

NameType
emitteryPropertyNamestring | symbol
methodNames?readonly string[]

Returns

fn

▸ <T>(klass): T

In TypeScript, it returns a decorator which mixins Emittery as property emitteryPropertyName and methodNames, or all Emittery methods if methodNames is not defined, into the target class.

Example

import Emittery from 'emittery';

@Emittery.mixin('emittery')
class MyClass {}

const instance = new MyClass();

instance.emit('event');
Type parameters
NameType
Textends (...arguments_: readonly any[]) => any
Parameters
NameType
klassT
Returns

T

Inherited from

Emittery.mixin


setBackgroundOptions

setBackgroundOptions(options): Promise<void>

change the background option during run time using this function. while using this function the media-processor will not be destroyed. while using this function the library promise a full resource cleanup.

Parameters

NameType
optionsBackgroundOptions

Returns

Promise<void>


enable

enable(): Promise<void>

Enable the processing

Returns

Promise<void>


disable

disable(): Promise<void>

Disable the processing

Returns

Promise<void>


setTrackExpectedRate

setTrackExpectedRate(rate): void

Sets the expected rate of the track per second. The media processor will use this number for calculating drops in the rate. This could happen when the transformation will take more time than expected. This will not cause an error, just warning to the client. Mostly: Video: 30 frames per second Audio: 50 audio data per second for OPUS

Parameters

NameTypeDescription
ratenumbernumber holds the predicted track rate. -1 for disable this monitor.

Returns

void


getConnector

getConnector(): MediaProcessorConnector

Getter for MediaProcessorConnectorInterface connector attribute.

Returns

MediaProcessorConnector

  • MediaProcessorConnectorInterface feed this return value to any vonage SDK that supports this API

profile

profile(duration): Promise<ResolvedWebglQuery[]>

Parameters

NameType
durationnumber

Returns

Promise<ResolvedWebglQuery[]>


on

on<Name>(eventName, listener): UnsubscribeFunction

Subscribe to one or more events.

Using the same listener multiple times for the same event will result in only one method call per emitted event.

Example

import Emittery from 'emittery';

const emitter = new Emittery();

emitter.on('🦄', data => {
console.log(data);
});

emitter.on(['🦄', '🐶'], data => {
console.log(data);
});

emitter.emit('🦄', '🌈'); // log => '🌈' x2
emitter.emit('🐶', '🍖'); // log => '🍖'

Type parameters

NameType
Nameextends keyof EventDataMap | keyof OmnipresentEventData

Parameters

NameType
eventNameName | readonly Name[]
listener(eventData: EventDataMap & OmnipresentEventData[Name]) => void | Promise<void>

Returns

UnsubscribeFunction

An unsubscribe method.

Inherited from

Emittery.on


events

events<Name>(eventName): AsyncIterableIterator<EventDataMap[Name]>

Get an async iterator which buffers data each time an event is emitted.

Call return() on the iterator to remove the subscription.

Example

import Emittery from 'emittery';

const emitter = new Emittery();
const iterator = emitter.events('🦄');

emitter.emit('🦄', '🌈1'); // Buffered
emitter.emit('🦄', '🌈2'); // Buffered

iterator
.next()
.then(({value, done}) => {
// done === false
// value === '🌈1'
return iterator.next();
})
.then(({value, done}) => {
// done === false
// value === '🌈2'
// Revoke subscription
return iterator.return();
})
.then(({done}) => {
// done === true
});

In practice you would usually consume the events using the for await statement. In that case, to revoke the subscription simply break the loop.

Example

import Emittery from 'emittery';

const emitter = new Emittery();
const iterator = emitter.events('🦄');

emitter.emit('🦄', '🌈1'); // Buffered
emitter.emit('🦄', '🌈2'); // Buffered

// In an async context.
for await (const data of iterator) {
if (data === '🌈2') {
break; // Revoke the subscription when we see the value `🌈2`.
}
}

It accepts multiple event names.

Example

import Emittery from 'emittery';

const emitter = new Emittery();
const iterator = emitter.events(['🦄', '🦊']);

emitter.emit('🦄', '🌈1'); // Buffered
emitter.emit('🦊', '🌈2'); // Buffered

iterator
.next()
.then(({value, done}) => {
// done === false
// value === '🌈1'
return iterator.next();
})
.then(({value, done}) => {
// done === false
// value === '🌈2'
// Revoke subscription
return iterator.return();
})
.then(({done}) => {
// done === true
});

Type parameters

NameType
Nameextends keyof EventDataMap

Parameters

NameType
eventNameName | readonly Name[]

Returns

AsyncIterableIterator<EventDataMap[Name]>

Inherited from

Emittery.events


off

off<Name>(eventName, listener): void

Remove one or more event subscriptions.

Example

import Emittery from 'emittery';

const emitter = new Emittery();

const listener = data => {
console.log(data);
};

emitter.on(['🦄', '🐶', '🦊'], listener);
await emitter.emit('🦄', 'a');
await emitter.emit('🐶', 'b');
await emitter.emit('🦊', 'c');
emitter.off('🦄', listener);
emitter.off(['🐶', '🦊'], listener);
await emitter.emit('🦄', 'a'); // nothing happens
await emitter.emit('🐶', 'b'); // nothing happens
await emitter.emit('🦊', 'c'); // nothing happens

Type parameters

NameType
Nameextends keyof EventDataMap | keyof OmnipresentEventData

Parameters

NameType
eventNameName | readonly Name[]
listener(eventData: EventDataMap & OmnipresentEventData[Name]) => void | Promise<void>

Returns

void

Inherited from

Emittery.off


once

once<Name>(eventName): EmitteryOncePromise<EventDataMap & OmnipresentEventData[Name]>

Subscribe to one or more events only once. It will be unsubscribed after the first event.

Example

import Emittery from 'emittery';

const emitter = new Emittery();

emitter.once('🦄').then(data => {
console.log(data);
//=> '🌈'
});

emitter.once(['🦄', '🐶']).then(data => {
console.log(data);
});

emitter.emit('🦄', '🌈'); // Logs `🌈` twice
emitter.emit('🐶', '🍖'); // Nothing happens

Type parameters

NameType
Nameextends keyof EventDataMap | keyof OmnipresentEventData

Parameters

NameType
eventNameName | readonly Name[]

Returns

EmitteryOncePromise<EventDataMap & OmnipresentEventData[Name]>

The promise of event data when eventName is emitted. This promise is extended with an off method.

Inherited from

Emittery.once


emit

emit<Name>(eventName): Promise<void>

Trigger an event asynchronously, optionally with some data. Listeners are called in the order they were added, but executed concurrently.

Type parameters

NameType
Nameextends never

Parameters

NameType
eventNameName

Returns

Promise<void>

A promise that resolves when all the event listeners are done. Done meaning executed if synchronous or resolved when an async/promise-returning function. You usually wouldn't want to wait for this, but you could for example catch possible errors. If any of the listeners throw/reject, the returned promise will be rejected with the error, but the other listeners will not be affected.

Inherited from

Emittery.emit

emit<Name>(eventName, eventData): Promise<void>

Type parameters

NameType
Nameextends keyof EventDataMap

Parameters

NameType
eventNameName
eventDataEventDataMap[Name]

Returns

Promise<void>

Inherited from

Emittery.emit


emitSerial

emitSerial<Name>(eventName): Promise<void>

Same as emit(), but it waits for each listener to resolve before triggering the next one. This can be useful if your events depend on each other. Although ideally they should not. Prefer emit() whenever possible.

If any of the listeners throw/reject, the returned promise will be rejected with the error and the remaining listeners will not be called.

Type parameters

NameType
Nameextends never

Parameters

NameType
eventNameName

Returns

Promise<void>

A promise that resolves when all the event listeners are done.

Inherited from

Emittery.emitSerial

emitSerial<Name>(eventName, eventData): Promise<void>

Type parameters

NameType
Nameextends keyof EventDataMap

Parameters

NameType
eventNameName
eventDataEventDataMap[Name]

Returns

Promise<void>

Inherited from

Emittery.emitSerial


onAny

onAny(listener): UnsubscribeFunction

Subscribe to be notified about any event.

Parameters

NameType
listener(eventName: keyof EventDataMap, eventData: WarnData | ErrorData | PipelineInfoData) => void | Promise<void>

Returns

UnsubscribeFunction

A method to unsubscribe.

Inherited from

Emittery.onAny


anyEvent

anyEvent(): AsyncIterableIterator<[keyof EventDataMap, WarnData | ErrorData | PipelineInfoData]>

Get an async iterator which buffers a tuple of an event name and data each time an event is emitted.

Call return() on the iterator to remove the subscription.

In the same way as for events, you can subscribe by using the for await statement.

Example

import Emittery from 'emittery';

const emitter = new Emittery();
const iterator = emitter.anyEvent();

emitter.emit('🦄', '🌈1'); // Buffered
emitter.emit('🌟', '🌈2'); // Buffered

iterator.next()
.then(({value, done}) => {
// done is false
// value is ['🦄', '🌈1']
return iterator.next();
})
.then(({value, done}) => {
// done is false
// value is ['🌟', '🌈2']
// revoke subscription
return iterator.return();
})
.then(({done}) => {
// done is true
});

Returns

AsyncIterableIterator<[keyof EventDataMap, WarnData | ErrorData | PipelineInfoData]>

Inherited from

Emittery.anyEvent


offAny

offAny(listener): void

Remove an onAny subscription.

Parameters

NameType
listener(eventName: keyof EventDataMap, eventData: WarnData | ErrorData | PipelineInfoData) => void | Promise<void>

Returns

void

Inherited from

Emittery.offAny


clearListeners

clearListeners<Name>(eventName?): void

Clear all event listeners on the instance.

If eventName is given, only the listeners for that event are cleared.

Type parameters

NameType
Nameextends keyof EventDataMap

Parameters

NameType
eventName?Name | readonly Name[]

Returns

void

Inherited from

Emittery.clearListeners


listenerCount

listenerCount<Name>(eventName?): number

The number of listeners for the eventName or all events if not specified.

Type parameters

NameType
Nameextends keyof EventDataMap

Parameters

NameType
eventName?Name | readonly Name[]

Returns

number

Inherited from

Emittery.listenerCount


bindMethods

bindMethods(target, methodNames?): void

Bind the given methodNames, or all Emittery methods if methodNames is not defined, into the target object.

Example

import Emittery from 'emittery';

const object = {};

new Emittery().bindMethods(object);

object.emit('event');

Parameters

NameType
targetRecord<string, unknown>
methodNames?readonly string[]

Returns

void

Inherited from

Emittery.bindMethods

Properties

isDebugEnabled

Static isDebugEnabled: boolean

Toggle debug mode for all instances.

Default: true if the DEBUG environment variable is set to emittery or *, otherwise false.

Example

import Emittery from 'emittery';

Emittery.isDebugEnabled = true;

const emitter1 = new Emittery({debug: {name: 'myEmitter1'}});
const emitter2 = new Emittery({debug: {name: 'myEmitter2'}});

emitter1.on('test', data => {
// …
});

emitter2.on('otherTest', data => {
// …
});

emitter1.emit('test');
//=> [16:43:20.417][emittery:subscribe][myEmitter1] Event Name: test
// data: undefined

emitter2.emit('otherTest');
//=> [16:43:20.417][emittery:subscribe][myEmitter2] Event Name: otherTest
// data: undefined

Inherited from

Emittery.isDebugEnabled


listenerAdded

Static Readonly listenerAdded: typeof listenerAdded

Fires when an event listener was added.

An object with listener and eventName (if on or off was used) is provided as event data.

Example

import Emittery from 'emittery';

const emitter = new Emittery();

emitter.on(Emittery.listenerAdded, ({listener, eventName}) => {
console.log(listener);
//=> data => {}

console.log(eventName);
//=> '🦄'
});

emitter.on('🦄', data => {
// Handle data
});

Inherited from

Emittery.listenerAdded


listenerRemoved

Static Readonly listenerRemoved: typeof listenerRemoved

Fires when an event listener was removed.

An object with listener and eventName (if on or off was used) is provided as event data.

Example

import Emittery from 'emittery';

const emitter = new Emittery();

const off = emitter.on('🦄', data => {
// Handle data
});

emitter.on(Emittery.listenerRemoved, ({listener, eventName}) => {
console.log(listener);
//=> data => {}

console.log(eventName);
//=> '🦄'
});

off();

Inherited from

Emittery.listenerRemoved


debug

debug: DebugOptions<EventDataMap>

Debugging options for the current instance.

Inherited from

Emittery.debug