Options
Menu

Class Device

Twilio Device. Allows registration for incoming calls, and placing outgoing calls.

Hierarchy

  • EventEmitter
    • Device

Index

Type aliases

Static ToggleableSound

ToggleableSound: Incoming | Outgoing | Disconnect

Names of all togglable sounds.

Constructors

constructor

Events

Static destroyedEvent

  • destroyedEvent(): void

Static errorEvent

Static incomingEvent

  • incomingEvent(call: Call): void
  • Emitted when an incoming Call is received. You can interact with the call object using its public APIs, or you can forward it to a different Device using Device.connect and Call.connectToken, enabling your application to receive multiple incoming calls for the same identity.

    Important: When forwarding a call, the token for target device instance needs to have the same identity as the token used in the device that originally received the call.

    example
    const receiverDevice = new Device(token, options);
    await receiverDevice.register();
    
    receiverDevice.on('incoming', (call) => {
      // Forward this call to a new Device instance using the call.connectToken string.
      forwardCall(call.connectToken);
    });
    
    // The forwardCall function may look something like the following.
    async function forwardCall(connectToken) {
      // For every incoming call, we create a new Device instance which we can
      // interact with, without affecting other calls.
      // IMPORTANT: The token for this new device needs to have the same identity
      // as the token used in the receiverDevice.
      const device = new Device(token, options);
      const call = await device.connect({ connectToken });
    
      // Destroy the device after the call is completed
      call.on('disconnect', () => device.destroy());
    }
    

    Parameters

    Returns void

Static registeredEvent

  • registeredEvent(): void

Static registeringEvent

  • registeringEvent(): void

Static tokenWillExpireEvent

  • tokenWillExpireEvent(device: Device): void
  • Emitted when the Device's token is about to expire. Use DeviceOptions.refreshTokenMs to set a custom warning time. Default is 10000 (10 seconds) prior to the token expiring.

    example

    device.on('tokenWillExpire', device => { const token = getNewTokenViaAjax(); device.updateToken(token); })

    Parameters

    Returns void

Static unregisteredEvent

  • unregisteredEvent(): void

Properties

Static defaultMaxListeners

defaultMaxListeners: number

Accessors

audio

calls

  • get calls(): Call[]

edge

  • get edge(): string | null

home

  • get home(): string | null

identity

  • get identity(): string | null
  • Returns the identity associated with the Device for incoming calls. Only populated when registered.

    Returns string | null

isBusy

  • get isBusy(): boolean

state

token

  • get token(): string | null

Static isSupported

  • get isSupported(): boolean

Static packageName

  • get packageName(): string

Static version

  • get version(): string

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

connect

destroy

  • destroy(): void

disconnectAll

  • disconnectAll(): void

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

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

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[]

register

  • register(): Promise<void>
  • Register the Device to the Twilio backend, allowing it to receive calls.

    Returns Promise<void>

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

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

unregister

  • unregister(): Promise<void>
  • Unregister the Device to the Twilio backend, disallowing it to receive calls.

    Returns Promise<void>

updateOptions

  • updateOptions(options?: Options): void

updateToken

  • updateToken(token: string): void
  • Update the token used by this Device to connect to Twilio. It is recommended to call this API after Device.tokenWillExpireEvent is emitted, and before or after a call to prevent a potential ~1s audio loss during the update process.

    Parameters

    • token: string

    Returns void

Static listenerCount

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

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Static runPreflight

Generated using TypeDoc