Class Call

A Call is the representation of an audio or video call between two browsers, SIP clients or phone numbers. The call object is created whenever a new call is initiated, either by you or the remote caller. You can access and act upon calls initiated by a remote caller in a telnyx.notification event handler.

Examples

To create a new call, i.e. dial:

const call = client.newCall({
// Destination is required and can be a phone number or SIP URI
destinationNumber: '18004377950',
callerNumber: '‬155531234567',
});

To answer an incoming call:

client.on('telnyx.notification', (notification) => {
const call = notification.call;

if (notification.type === 'callUpdate' && call.state === 'ringing') {
call.answer();
}
});

Both the outgoing and incoming call has methods that can be hooked up to your UI.

// Hangup or reject an incoming call
call.hangup();

// Send digits and keypresses
call.dtmf('1234');

// Call states that can be toggled
call.hold();
call.muteAudio();

Hierarchy

  • default
    • Call

Properties

direction: Direction

The direction of the call. Can be either inbound or outbound.

id: string = ''

The call identifier.

prevState: string = ''

The previous state of the call. See Call.state for all possible values.

state: string = ...

The state of the call.

Value Description
new New call has been created in the client.
trying It's attempting to call someone.
requesting The outbound call is being sent to the server.
recovering The previous call is recovering after the page refreshes. If the user refreshes the page during a call, it will automatically join the latest call.
ringing Someone is attempting to call you.
answering You are attempting to answer this inbound call.
early It receives the media before the call has been answered.
active Call has become active.
held Call has been held.
hangup Call has ended.
destroy Call has been destroyed.
purge Call has been purged.

Accessors

  • get localStream(): MediaStream
  • Gets the local stream of the call. This can be used in a video/audio element to play the local media. See MediaStream.

    Returns MediaStream

    Examples

    const stream = call.localStream;
    document.querySelector('audio').srcObject = stream;
  • get remoteStream(): MediaStream
  • Gets the remote stream of the call. This can be used in a video/audio element to play the remote media. See MediaStream.

    Returns MediaStream

    Examples

    const stream = call.remoteStream;
    document.querySelector('audio').srcObject = stream;
  • get telnyxIDs(): {
        telnyxCallControlId: string;
        telnyxLegId: string;
        telnyxSessionId: string;
    }
  • Gets Telnyx call IDs, if using Telnyx Call Control services. You can use these IDs to identify specific calls in your application code.

    Returns {
        telnyxCallControlId: string;
        telnyxLegId: string;
        telnyxSessionId: string;
    }

    • telnyxCallControlId: string
    • telnyxLegId: string
    • telnyxSessionId: string

    Examples

    const { telnyxCallControlId, telnyxSessionId, telnyxLegId } = call.telnyxIDs;
    

Methods

  • Starts the process to answer the incoming call.

    Parameters

    • params: AnswerParams = {}

    Returns void

    Examples

    call.answer()
    
  • Turns off the remote stream audio.

    Returns void

    Examples

    call.deaf()
    
  • Sends dual-tone multi-frequency (DTMF) signal

    Parameters

    • dtmf: string

      Single DTMF key

    Returns void

    Examples

    call.dtmf('0');
    call.dtmf('1');
    call.dtmf('*');
    call.dtmf('#');
  • Registers callback for stats.

    Parameters

    • callback: Function
    • constraints: any

    Returns void

  • Holds the call.

    Returns Promise<any>

    Promise that resolves or rejects based on server response

    Examples

    Using async/await:

    await call.hold()
    console.log(call.state) // => 'held'

    Using ES6 Promises:

    call.hold().then(() => {
    console.log(call.state) // => 'held'
    });
  • Turns off audio output, i.e. makes it so other call participants cannot hear your audio.

    Returns void

    Examples

    call.muteAudio();
    
  • Turns off the video output, i.e. hides video from other call participants.

    Returns void

    Examples

    call.muteVideo();
    

    Deprecated

  • Changes the audio input device (i.e. microphone) used for the call.

    Parameters

    • deviceId: string

      The target audio input device ID

    Returns Promise<void>

    Promise that resolves if the audio input device has been updated

    Examples

    Using async/await:

    await call.setAudioInDevice('abc123')
    

    Using ES6 Promises:

    call.setAudioInDevice('abc123').then(() => {
    // Do something using new audio input device
    });

    Usage with .getAudioInDevices:

    let result = await client.getAudioInDevices();

    if (result.length) {
    call.setAudioInDevice(result[1].deviceId);
    }
  • Changes the audio output device (i.e. speaker) used for the call.

    Parameters

    • deviceId: string

      The target audio output device ID

    Returns Promise<boolean>

    Promise that returns a boolean

    Examples

    Using async/await:

    await call.setAudioOutDevice('abc123')
    

    Using ES6 Promises:

    call.setAudioOutDevice('abc123').then(() => {
    // Do something using new audio output device
    });

    Usage with .getAudioOutDevices:

    let result = await client.getAudioOutDevices();

    if (result.length) {
    await call.setAudioOutDevice(result[1].deviceId);
    }
  • Changes the video device (i.e. webcam) used for the call.

    Parameters

    • deviceId: string

      the target video device ID

    Returns Promise<void>

    Promise that resolves if the video device has been updated

    Examples

    Using async/await:

    await call.setVideoDevice('abc123')
    

    Using ES6 Promises:

    call.setVideoDevice('abc123').then(() => {
    // Do something using new video device
    });

    Usage with .getVideoDevices:

    let result = await client.getVideoDevices();

    if (result.length) {
    await call.setVideoDevice(result[1].deviceId);
    }

    Deprecated

  • Toggles the audio output on/off.

    Returns void

    Examples

    call.toggleAudioMute();
    
  • Toggles the remote stream audio.

    Returns void

    Examples

    call.toggleDeaf()
    
  • Toggles hold state of the call.

    Returns Promise<any>

    Promise that resolves or rejects based on server response

    Examples

    Using async/await:

    await call.toggleHold()
    console.log(call.state) // => 'held'

    await call.toggleHold()
    console.log(call.state) // => 'active'
  • Toggles the video output on/off.

    Returns void

    Examples

    call.toggleVideoMute();
    

    Deprecated

  • Turns on the remote stream audio.

    Returns void

    Examples

    call.undeaf()
    
  • Removes hold from the call.

    Returns Promise<any>

    Promise that resolves or rejects based on server response

    Examples

    Using async/await:

    await call.unhold()
    console.log(call.state) // => 'active'

    Using ES6 Promises:

    call.unhold().then(() => {
    console.log(call.state) // => 'active'
    });
  • Turns on audio output, i.e. makes it so other call participants can hear your audio.

    Returns void

    Examples

    call.unmuteAudio();
    
  • Turns on the video output, i.e. makes video visible to other call participants.

    Returns void

    Examples

    call.unmuteVideo();
    

    Deprecated