@vonage/media-processor
    Preparing search index...

    Class MediaProcessor

    Media processor class holding and running insertable streams pipeline. The class should be created on the proper thread. Options are:

    • Application main thread when media processing wants to be performed in the main thread.
    • Worker thread when media processing wants to be performed in a Web worker thread.

    Hierarchy

    Implements

    Index

    Constructors

    Properties

    debug: DebugOptions<EventDataMap>

    Debugging options for the current instance.

    isDebugEnabled: boolean

    Toggle debug mode for all instances.

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

    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
    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.

    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
    });
    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.

    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();

    Methods

    • 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.

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

      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
      });
    • Bind the given methodNames, or all Emittery methods if methodNames is not defined, into the target object.

      Parameters

      • target: Record<string, unknown>
      • OptionalmethodNames: readonly string[]

      Returns void

      import Emittery from 'emittery';

      const object = {};

      new Emittery().bindMethods(object);

      object.emit('event');
    • Clear all event listeners on the instance.

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

      Type Parameters

      Parameters

      • OptionaleventName: Name | readonly Name[]

      Returns void

    • Stops running the tranformation logic performed by the media processor instance.

      Returns Promise<void>

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

      Type Parameters

      • Name extends never

      Parameters

      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.

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

      Type Parameters

      Parameters

      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.

    • 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

      • Name extends never

      Parameters

      Returns Promise<void>

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

    • 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

      Parameters

      Returns Promise<void>

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

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

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

      Type Parameters

      Parameters

      Returns AsyncIterableIterator<EventDataMap[Name]>

      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.

      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.

      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
      });
    • The number of listeners for the eventName or all events if not specified.

      Type Parameters

      Parameters

      • OptionaleventName: Name | readonly Name[]

      Returns number

    • Remove one or more event subscriptions.

      Type Parameters

      • Name extends (keyof EventDataMap) | (keyof OmnipresentEventData)

      Parameters

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

      Returns void

      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
    • 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.

      Type Parameters

      • Name extends (keyof EventDataMap) | (keyof OmnipresentEventData)

      Parameters

      • eventName: Name | readonly Name[]
      • listener: (eventData: (EventDataMap & OmnipresentEventData)[Name]) => void | Promise<void>
      • Optionaloptions: { signal?: AbortSignal }

      Returns UnsubscribeFunction

      An unsubscribe method.

      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 => '🍖'
    • Subscribe to be notified about any event.

      Parameters

      Returns UnsubscribeFunction

      A method to unsubscribe.

    • Subscribe to one or more events only once. It will be unsubscribed after the first event that matches the predicate (if provided).

      Type Parameters

      • Name extends (keyof EventDataMap) | (keyof OmnipresentEventData)

      Parameters

      • eventName: Name | readonly Name[]

        The event name(s) to subscribe to.

      • Optionalpredicate: (eventData: (EventDataMap & OmnipresentEventData)[Name]) => boolean

        Optional predicate function to filter event data. The event will only be emitted if the predicate returns true.

      Returns EmitteryOncePromise<(EventDataMap & OmnipresentEventData)[Name]>

      The promise of event data when eventName is emitted and predicate matches (if provided). This promise is extended with an off method.

      import Emittery from 'emittery';

      const emitter = new Emittery();

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

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

      // With predicate
      emitter.once('data', data => data.ok === true).then(data => {
      console.log(data);
      //=> {ok: true, value: 42}
      });

      emitter.emit('🦄', '🌈'); // Logs `🌈` twice
      emitter.emit('🐶', '🍖'); // Nothing happens
      emitter.emit('data', {ok: false}); // Nothing happens
      emitter.emit('data', {ok: true, value: 42}); // Logs {ok: true, value: 42}
    • 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 In case of increased frame dropping rate a warning will be emitted according to info here. This is an optional method.

      Parameters

      • trackExpectedRate: number

        number holds the predicted track rate.

      Returns void

    • Sets an array of transfromer instances that will be hold and ran by the media processor instance. See example here

      Parameters

      • transformers: Transformer<any, any>[]

        An array of transformer instances.

      Returns Promise<void>

    • Starts running the tranformation logic performed by the media processor instance. When running an instance of this class on a Web worker thread the call for this function should be made by the user. See example here. When running an instance of this class on the application main thread there is no need to call this method given it will be called by the MediaProcessorConnector instance.

      Parameters

      • readable: ReadableStream

        Readable stream associated to the media source being processed.

      • writable: WritableStream

        Writable stream associated to the resulting media once processed.

      Returns Promise<void>

    • Starts running the tranformation logic performed by the media processor instance. Special case of transform for browsers implementing the proposed standard, which only works inside webworkers. Only Webkit for now..

      Parameters

      • track: MediaStreamTrack

        Track to be processed.

      Returns Promise<MediaStreamTrack>

      New track to be used.

    • 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.

      Parameters

      • emitteryPropertyName: string | symbol
      • OptionalmethodNames: readonly string[]

      Returns <T extends new (...arguments_: readonly any[]) => any>(klass: T) => T

      import Emittery from 'emittery';

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

      const instance = new MyClass();

      instance.emit('event');