UNPKG

@telnyx/react-native-voice-sdk

Version:
79 lines (78 loc) 3.15 kB
import { EventEmitter } from 'eventemitter3'; import type { CallOptions } from './call-options'; import type { ClientOptions } from './client-options'; import { Call } from './call'; import type { InviteEvent } from './messages/call'; type TelnyxRTCEvents = { 'telnyx.client.ready': () => void; 'telnyx.client.error': (error: Error) => void; 'telnyx.call.incoming': (call: Call, msg: InviteEvent) => void; }; export declare class TelnyxRTC extends EventEmitter<TelnyxRTCEvents> { options: ClientOptions; call: Call | null; sessionId: string | null; private connection; private loginHandler; private keepAliveHandler; constructor(opts: ClientOptions); /** * Initiates a new call. * @param options The options for the new call. * @example * ```typescript * import { TelnyxRTC } from '@telnyx/react-native-voice-sdk'; * const telnyxRTC = new TelnyxRTC({ loginToken: 'your_login_token' }); * await telnyxRTC.connect(); * const call = await telnyxRTC.newCall({ * destinationNumber: '+1234567890', * callerIdNumber: '+0987654321', * callerIdName: 'My Name', * customHeaders: [{ name: 'X-Custom-Header', value: 'value' }], * }); * console.log('Call initiated:', call); * * @returns a Promise that resolves to the Call instance. * @throws Error if no connection or session ID exists. */ newCall: (options: CallOptions) => Promise<Call>; /** * * @returns A Promise that resolves when the connection is established. * @throws Error if the connection already exists or login fails. * @example * ```typescript * import { TelnyxRTC } from '@telnyx/react-native-voice-sdk'; * const telnyxRTC = new TelnyxRTC({ loginToken: 'your_login_token' }); * await telnyxRTC.connect(); * console.log('Connected to Telnyx RTC'); * ``` * Connects to the Telnyx RTC service. * This method initializes the connection, logs in using the provided options, * and sets up the necessary event listeners. * It emits a 'telnyx.client.ready' event when the connection is successfully established. * If a connection already exists, it logs a warning and does not create a new connection. * If the login fails, it logs an error and throws an exception. * @see {@link ClientOptions} for the options that can be passed to the constructor. */ connect(): Promise<void>; /** * Disconnects from the Telnyx RTC service. * This method closes the WebSocket connection and removes all event listeners. * If no connection exists, it logs a warning. * @example * ```typescript * import { TelnyxRTC } from '@telnyx/react-native-voice-sdk'; * const telnyxRTC = new TelnyxRTC({ loginToken: 'your_login_token' }); * await telnyxRTC.connect(); * // ... use the TelnyxRTC instance ... * telnyxRTC.disconnect(); * console.log('Disconnected from Telnyx RTC'); * ``` */ disconnect(): void; get connected(): boolean; private onSocketMessage; private handleCallInvite; } export {};