UNPKG

@telnyx/react-native-voice-sdk

Version:
179 lines (177 loc) 6.37 kB
import { EventEmitter } from 'eventemitter3'; import type { CallOptions } from './call-options'; import { Connection } from './connection'; type CallEvents = { 'telnyx.call.state': (call: Call, state: CallState) => void; }; export type CallState = 'new' | 'ringing' | 'active' | 'ended' | 'held'; type CallConstructorParams = { connection: Connection; options: CallOptions; sessionId: string; direction: CallDirection; telnyxSessionId: string | null; telnyxLegId: string | null; telnyxCallControlId?: string | null; callId: string | null; callState?: CallState; }; export type CallDirection = 'inbound' | 'outbound'; export type CreateInboundCall = { connection: Connection; options: CallOptions; sessionId: string; telnyxSessionId: string; telnyxLegId: string; telnyxCallControlId?: string | null; remoteSDP: string; callId: string; }; export declare class Call extends EventEmitter<CallEvents> { direction: CallDirection; callId: string; telnyxSessionId: string | null; telnyxCallControlId: string | null; telnyxLegId: string | null; state: CallState; static createInboundCall({ connection, options, remoteSDP, sessionId, telnyxLegId, telnyxSessionId, callId, }: CreateInboundCall): Promise<Call>; private connection; private options; private peer; private sessionId; constructor({ connection, options, sessionId, direction, callId, telnyxLegId, telnyxSessionId, telnyxCallControlId, callState, }: CallConstructorParams); get remoteStream(): import("react-native-webrtc").MediaStream | undefined; get localStream(): import("react-native-webrtc").MediaStream | undefined; /** * Accept an incoming call * This method will attach the local audio stream, create an answer, * and send the answer message to the Telnyx platform. * It will also set the call state to 'active'. * @throws {Error} If the peer connection is not created * @returns {Promise<void>} A promise that resolves when the call is accepted */ answer: () => Promise<void>; /** * Hang up the call * This method will send a hangup request to the Telnyx platform, * close the peer connection, and set the call state to 'ended'. */ hangup: () => void; /** * Hold the call * This method will send a hold request to the Telnyx platform, * and set the call state to 'held'. * @throws {Error} If the hold action fails or if the response is invalid * @return {Promise<void>} A promise that resolves when the call is held */ hold: () => Promise<void>; /** * Unhold the call * This method will send an unhold request to the Telnyx platform, * and set the call state to 'active'. * @throws {Error} If the unhold action fails or if the response is invalid * @return {Promise<void>} A promise that resolves when the call is unheld */ unhold: () => Promise<void>; /** * * @param digits The DTMF digits to send * This method will send a DTMF request to the Telnyx platform, * and return the result of the DTMF action. * @throws {Error} If the DTMF response is invalid * @returns {Promise<string>} A promise that resolves with the DTMF result * @example * ```typescript * const result = await call.dtmf('1234'); * console.log(result); // 'SENT' or other result based on the DTMF action * ``` */ dtmf: (digits: string) => Promise<{ message: string; sessid: string; }>; /** * Mute the local audio stream * This method will set the local audio stream state to false, * effectively muting the audio. * @throws {Error} If the peer connection or local stream is not set * @returns {void} * @example * ```typescript * call.mute(); * console.log('Call muted'); * ``` * @see {@link Call.unmute} for unmuting the call. * @see {@link Call.deaf} for deafening the call. * @see {@link Call.undeaf} for undeafening the call. * */ mute: () => void; /** * Unmute the local audio stream * This method will set the local audio stream state to true, * effectively unmuting the audio. * @throws {Error} If the peer connection or local stream is not set * @returns {void} * @example * ```typescript * call.unmute(); * console.log('Call unmuted'); * ``` * @see {@link Call.mute} for muting the call. * @see {@link Call.deaf} for deafening the call. * @see {@link Call.undeaf} for undeafening the call. */ unmute: () => void; /** * Deafen the remote audio stream * This method will set the remote audio stream state to false, * effectively deafening the audio. * @throws {Error} If the peer connection or remote stream is not set * @returns {void} * @example * ```typescript * call.deaf(); * console.log('Call deafened'); * ``` * @see {@link Call.undeaf} for undeafening the call. * @see {@link Call.mute} for muting the call. * @see {@link Call.unmute} for unmuting the call. * */ deaf: () => void; /** * Undeafen the remote audio stream * This method will set the remote audio stream state to true, * effectively undeafening the audio. * @throws {Error} If the peer connection or remote stream is not set * @returns {void} * @example * ```typescript * call.undeaf(); * console.log('Call undeafened'); * ``` * @see {@link Call.deaf} for deafening the call. * @see {@link Call.mute} for muting the call. * @see {@link Call.unmute} for unmuting the call. * */ undeaf: () => void; /** * Get the Telnyx IDs associated with the call * This method returns an object containing the Telnyx session ID, leg ID, and call control ID. * @returns {Object} An object containing the Telnyx IDs */ get telnyxIds(): { telnyxSessionId: string | null; telnyxLegId: string | null; telnyxCallControlId: string | null; }; invite: () => Promise<void>; private setState; private onSocketMessage; private handleRingingEvent; private handleAnswerEvent; private handleHangupEvent; } export {};