Options
Menu

Class AudioHelper

Provides input and output audio-based functionality in one convenient class.

Hierarchy

  • EventEmitter
    • AudioHelper

Index

Events

Static deviceChangeEvent

  • deviceChangeEvent(lostActiveDevices: MediaDeviceInfo[]): void
  • Emitted when the available set of Devices changes.

    example

    device.audio.on('deviceChange', lostActiveDevices => { })

    Parameters

    • lostActiveDevices: MediaDeviceInfo[]

      An array containing any Devices that were previously active that were lost as a result of this deviceChange event.

    Returns void

Static inputVolumeEvent

  • inputVolumeEvent(inputVolume: number): void
  • Emitted on requestAnimationFrame (up to 60fps, depending on browser) with the current input and output volumes, as a percentage of maximum volume, between -100dB and -30dB. Represented by a floating point number.

    example

    device.audio.on('inputVolume', volume => { })

    Parameters

    • inputVolume: number

      A floating point number between 0.0 and 1.0 inclusive.

    Returns void

Properties

availableInputDevices

availableInputDevices: Map<string, MediaDeviceInfo> = new Map()

A Map of all audio input devices currently available to the browser by their device ID.

availableOutputDevices

availableOutputDevices: Map<string, MediaDeviceInfo> = new Map()

A Map of all audio output devices currently available to the browser by their device ID.

isOutputSelectionSupported

isOutputSelectionSupported: boolean

False if the browser does not support HTMLAudioElement.setSinkId() or MediaDevices.enumerateDevices() and Twilio cannot facilitate output selection functionality.

isVolumeSupported

isVolumeSupported: boolean

False if the browser does not support AudioContext and Twilio can not analyse the volume in real-time.

ringtoneDevices

ringtoneDevices: OutputDeviceCollection

The current set of output devices that incoming ringtone audio is routed through. These are the sounds that may play while the user is away from the machine or not wearing their headset. It is important that this audio is heard. If all specified devices lost, this Set will revert to contain only the "default" device.

speakerDevices

speakerDevices: OutputDeviceCollection

The current set of output devices that call audio ([voice, outgoing, disconnect, dtmf]) is routed through. These are the sounds that are initiated by the user, or played while the user is otherwise present at the endpoint. If all specified devices are lost, this Set will revert to contain only the "default" device.

Static defaultMaxListeners

defaultMaxListeners: number

Accessors

audioConstraints

  • get audioConstraints(): MediaTrackConstraints | null
  • The currently set audio constraints set by setAudioConstraints(). Starts as null.

    Returns MediaTrackConstraints | null

inputDevice

  • get inputDevice(): MediaDeviceInfo | null
  • The active input device. Having no inputDevice specified by setInputDevice() will disable input selection related functionality.

    Returns MediaDeviceInfo | null

inputStream

  • get inputStream(): MediaStream | null

processedStream

  • get processedStream(): MediaStream | null

Methods

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

addProcessor

  • Adds an AudioProcessor object. Once added, the AudioHelper will route the input audio stream through the processor before sending the audio stream to Twilio. Only one AudioProcessor can be added at this time.

    See the AudioProcessor interface for an example.

    Parameters

    Returns Promise<void>

disconnect

  • disconnect(doEnable?: undefined | false | true): boolean
  • Enable or disable the disconnect sound.

    Parameters

    • Optional doEnable: undefined | false | true

      Passing true will enable the sound and false will disable the sound. Not passing this parameter will not alter the enable-status of the sound.

    Returns boolean

    The enable-status of the sound.

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

incoming

  • incoming(doEnable?: undefined | false | true): boolean
  • Enable or disable the incoming sound.

    Parameters

    • Optional doEnable: undefined | false | true

      Passing true will enable the sound and false will disable the sound. Not passing this parameter will not alter the enable-status of the sound.

    Returns boolean

    The enable-status of the sound.

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

outgoing

  • outgoing(doEnable?: undefined | false | true): boolean
  • Enable or disable the outgoing sound.

    Parameters

    • Optional doEnable: undefined | false | true

      Passing true will enable the sound and false will disable the sound. Not passing this parameter will not alter the enable-status of the sound.

    Returns boolean

    The enable-status of the sound.

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

removeProcessor

setAudioConstraints

  • setAudioConstraints(audioConstraints: MediaTrackConstraints): Promise<void>
  • Set the MediaTrackConstraints to be applied on every getUserMedia call for new input device audio. Any deviceId specified here will be ignored. Instead, device IDs should be specified using {@link AudioHelper#setInputDevice}. The returned Promise resolves when the media is successfully reacquired, or immediately if no input device is set.

    Parameters

    • audioConstraints: MediaTrackConstraints

      The MediaTrackConstraints to apply.

    Returns Promise<void>

setInputDevice

  • setInputDevice(deviceId: string): Promise<void>
  • Replace the current input device with a new device by ID.

    Parameters

    • deviceId: string

      An ID of a device to replace the existing input device with.

    Returns Promise<void>

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

unsetAudioConstraints

  • unsetAudioConstraints(): Promise<void>
  • Unset the MediaTrackConstraints to be applied on every getUserMedia call for new input device audio. The returned Promise resolves when the media is successfully reacquired, or immediately if no input device is set.

    Returns Promise<void>

unsetInputDevice

  • unsetInputDevice(): Promise<void>
  • Unset the input device, stopping the tracks. This should only be called when not in a connection, and will not allow removal of the input device during a live call.

    Returns Promise<void>

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc