UNPKG

@signalwire/realtime-api

Version:
417 lines 13.3 kB
import { CallingCallConnectEventParams, CallingCall, VoiceCallDisconnectReason, CallingCallWaitForState, CallingCallState, VoiceCallConnectMethodParams, VoiceCallConnectPhoneMethodParams, VoiceCallConnectSipMethodParams } from '@signalwire/core'; import { ListenSubscriber } from '../ListenSubscriber'; import { CallCollectMethodParams, CallDetectDigitParams, CallDetectFaxParams, CallDetectMachineParams, CallDetectMethodParams, CallPlayAudioMethodarams, CallPlayMethodParams, CallPlayRingtoneMethodParams, CallPlaySilenceMethodParams, CallPlayTTSMethodParams, CallPromptAudioMethodParams, CallPromptMethodParams, CallPromptRingtoneMethodParams, CallPromptTTSMethodParams, CallRecordAudioMethodParams, CallRecordMethodParams, CallTapAudioMethodParams, CallTapMethodParams, RealTimeCallEvents, RealTimeCallListeners, RealtimeCallListenersEventsMapping } from '../types'; import { Voice } from './Voice'; interface CallOptions { voice: Voice; payload?: CallingCall; connectPayload?: CallingCallConnectEventParams; listeners?: RealTimeCallListeners; } export declare class Call extends ListenSubscriber<RealTimeCallListeners, RealTimeCallEvents> { private _voice; private _context; private _peer; private _payload; private _connectPayload; protected _eventMap: RealtimeCallListenersEventsMapping; constructor(options: CallOptions); /** Unique id for this voice call */ get id(): string | undefined; get callId(): string | undefined; get state(): CallingCallState | undefined; get callState(): CallingCallState | undefined; get tag(): string | undefined; get nodeId(): string | undefined; get device(): import("@signalwire/core").CallingCallDevice | undefined; /** The type of call. Only phone and sip are currently supported. */ get type(): "" | "phone" | "sip"; /** The phone number that the call is coming from. */ get from(): any; /** The phone number you are attempting to call. */ get to(): any; get headers(): any; get active(): boolean; get connected(): boolean; get direction(): import("@signalwire/core").CallingCallDirection | undefined; get context(): string | undefined; get connectState(): "connected" | "disconnected" | "failed" | "connecting" | undefined; get peer(): Call | undefined; /** @internal */ set peer(callInstance: Call | undefined); /** @internal */ setPayload(payload: CallingCall): void; /** @internal */ setConnectPayload(payload: CallingCallConnectEventParams): void; /** * Hangs up the call. * @param reason Optional reason for hanging up * * @example * * ```js * call.hangup(); * ``` */ hangup(reason?: VoiceCallDisconnectReason): Promise<void>; /** * Pass the incoming call to another consumer. * * @example * * ```js * call.pass(); * ``` */ pass(): Promise<void>; /** * Answers the incoming call. * * @example * * ```js * voice.client.listen({ * topics: ['home'], * onCallReceived: async (call) => { * try { * await call.answer() * console.log('Inbound call answered') * } catch (error) { * console.error('Error answering inbound call', error) * } * } * }) * ``` */ answer(): Promise<this>; /** * Play one or multiple media in a Call and waits until the playing has ended. * * The play method is a generic method for all types of media, see * {@link playAudio}, {@link playSilence}, {@link playTTS} or * {@link playRingtone} for more specific usages. * * @param params a media playlist. See {@link Voice.Playlist}. * * @example * * ```js * await call.play(new Voice.Playlist({ volume: 1.0 }).add( * Voice.Playlist.TTS({ * text: 'Welcome to SignalWire! Please enter your 4 digits PIN', * }) * )) * ``` */ play(params: CallPlayMethodParams): import("./CallPlayback").CallPlaybackPromise; /** * Plays an audio file. * * @example * * ```js * const playback = await call.playAudio({ url: 'https://cdn.signalwire.com/default-music/welcome.mp3' }); * ``` */ playAudio(params: CallPlayAudioMethodarams): import("./CallPlayback").CallPlaybackPromise; /** * Plays some silence. * * @example * * ```js * const playback = await call.playSilence({ duration: 3 }); * ``` */ playSilence(params: CallPlaySilenceMethodParams): import("./CallPlayback").CallPlaybackPromise; /** * Plays a ringtone. * * @example * * ```js * const playback = await call.playRingtone({ name: 'it' }); * ``` */ playRingtone(params: CallPlayRingtoneMethodParams): import("./CallPlayback").CallPlaybackPromise; /** * Plays text-to-speech. * * @example * * ```js * const playback = await call.playTTS({ text: 'Welcome to SignalWire!' }); * ``` */ playTTS(params: CallPlayTTSMethodParams): import("./CallPlayback").CallPlaybackPromise; /** * Generic method to record a call. Please see {@link recordAudio}. */ record(params: CallRecordMethodParams): import("./CallRecording").CallRecordingPromise; /** * Records the audio from the call. * * @example * * ```js * const recording = await call.recordAudio({ direction: 'both' }) * ``` */ recordAudio(params?: CallRecordAudioMethodParams): import("./CallRecording").CallRecordingPromise; /** * Generic method to prompt the user for input. Please see {@link promptAudio}, {@link promptRingtone}, {@link promptTTS}. */ prompt(params: CallPromptMethodParams): import("./CallPrompt").CallPromptPromise; /** * Play an audio while collecting user input from the call, such as `digits` or `speech`. * * @example * * Prompting for digits and waiting for a result: * * ```js * const prompt = await call.promptAudio({ * url: 'https://cdn.signalwire.com/default-music/welcome.mp3', * digits: { * max: 5, * digitTimeout: 2, * terminators: '#*' * } * }) * const { type, digits, terminator } = await prompt.ended() * ``` */ promptAudio(params: CallPromptAudioMethodParams): import("./CallPrompt").CallPromptPromise; /** * Play a ringtone while collecting user input from the call, such as `digits` or `speech`. * * @example * * Prompting for digits and waiting for a result: * * ```js * const prompt = await call.promptRingtone({ * name: 'it', * duration: 10, * digits: { * max: 5, * digitTimeout: 2, * terminators: '#*' * } * }) * const { type, digits, terminator } = await prompt.ended() * ``` */ promptRingtone(params: CallPromptRingtoneMethodParams): import("./CallPrompt").CallPromptPromise; /** * Say some text while collecting user input from the call, such as `digits` or `speech`. * * @example * * Prompting for digits and waiting for a result: * * ```js * const prompt = await call.promptTTS({ * text: 'Please enter your PIN', * digits: { * max: 5, * digitTimeout: 2, * terminators: '#*' * } * }) * const { type, digits, terminator } = await prompt.ended() * ``` */ promptTTS(params: CallPromptTTSMethodParams): import("./CallPrompt").CallPromptPromise; /** * Play DTMF digits to the other party on the call. * * @example * * ```js * await call.sendDigits('123') * ``` */ sendDigits(digits: string): Promise<Call>; /** * Intercept call media and stream it to the specified WebSocket endpoint. * Prefer using {@link tapAudio} if you only need to tap audio. * * @example * * ```js * const tap = await call.tapAudio({ * audio: { * direction: 'both', * }, * device: { * type: 'ws', * uri: 'wss://example.domain.com/endpoint', * }, * }) * ``` */ tap(params: CallTapMethodParams): import("./CallTap").CallTapPromise; /** * Intercept call audio and stream it to the specified WebSocket endpoint. * * @example * * ```js * const tap = await call.tapAudio({ * direction: 'both', * device: { * type: 'ws', * uri: 'wss://example.domain.com/endpoint', * }, * }) * * await tap.stop() * ``` */ tapAudio(params: CallTapAudioMethodParams): import("./CallTap").CallTapPromise; /** * Attempt to connect an existing call to a new outbound call. You can wait * until the call is disconnected by calling {@link waitForDisconnected}. * * This is a generic method that allows you to connect to multiple devices in * series, parallel, or combinations of both with the use of a * {@link Voice.DeviceBuilder}. For simpler use cases, prefer using * {@link connectPhone} or {@link connectSip}. * * @example * * Connecting to a new SIP call. * * ```js * const plan = new Voice.DeviceBuilder().add( * Voice.DeviceBuilder.Sip({ * from: 'sip:user1@domain.com', * to: 'sip:user2@domain.com', * timeout: 30, * }) * ) * * const peer = await call.connect(plan) * ``` */ connect(params: VoiceCallConnectMethodParams): Promise<any>; /** * Attempt to connect an existing call to a new outbound phone call. You can * wait until the call is disconnected by calling {@link waitForDisconnected}. * * @example * * ```js * const peer = await call.connectPhone({ * from: '+xxxxxx', * to: '+yyyyyy', * timeout: 30 * }) * ``` */ connectPhone({ ringback, maxPricePerMinute, ...params }: VoiceCallConnectPhoneMethodParams): Promise<any>; /** * Attempt to connect an existing call to a new outbound SIP call. You can * wait until the call is disconnected by calling {@link waitForDisconnected}. * * @example * * ```js * const peer = await call.connectPhone({ * from: 'sip:user1@domain.com', * to: 'sip:user2@domain.com', * timeout: 30 * }) * ``` */ connectSip({ ringback, maxPricePerMinute, ...params }: VoiceCallConnectSipMethodParams): Promise<any>; disconnect(): Promise<void>; /** * @deprecated use {@link disconnected} instead. */ waitForDisconnected(): () => Promise<void>; disconnected(): Promise<this>; /** * Generic method. Please see {@link amd}, {@link detectFax}, {@link detectDigit}. */ detect(params: CallDetectMethodParams): import("./CallDetect").CallDetectPromise; /** * Detects the presence of an answering machine. * * @example * * ```js * const detect = await call.amd() * const result = await detect.ended() * * console.log('Detect result:', result.type) * ``` */ amd(params?: CallDetectMachineParams): import("./CallDetect").CallDetectPromise; /** * Alias for amd() */ detectAnsweringMachine: (params?: CallDetectMachineParams) => import("./CallDetect").CallDetectPromise; /** * Detects the presence of a fax machine. * * @example * * ```js * const detect = await call.detectFax() * const result = await detect.ended() * * console.log('Detect result:', result.type) * ``` */ detectFax(params?: CallDetectFaxParams): import("./CallDetect").CallDetectPromise; /** * Detects digits in the audio stream. * * @example * * ```js * const detect = await call.detectDigit() * const result = await detect.ended() * * console.log('Detect result:', result.type) * ``` */ detectDigit(params?: CallDetectDigitParams): import("./CallDetect").CallDetectPromise; /** * Collect user input from the call, such as `digits` or `speech`. * * @example * * Collect digits and waiting for a result: * * ```js * const collectObj = await call.collect({ * digits: { * max: 5, * digitTimeout: 2, * terminators: '#*' * } * }) * const { digits, terminator } = await collectObj.ended() * ``` */ collect(params: CallCollectMethodParams): import("./CallCollect").CallCollectPromise; /** * Returns a promise that is resolved only after the current call is in one of * the specified states. * * @returns true if the requested states have been reached, false if they * won't be reached because the call ended. * * @example * * ```js * await call.waitFor('ended') * ``` */ waitFor(params: CallingCallWaitForState | CallingCallWaitForState[]): Promise<unknown>; } export {}; //# sourceMappingURL=Call.d.ts.map