Skip to main content

CallTap

Represents a current or past tapping of a call.

Obtain instances of this class by starting a Tap with one of the following methods:

Example

As soon as the other party answers the phone, start transmitting the audio of the call to an external service.

import { SignalWire } from "@signalwire/realtime-api";

const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })


const call = await client.voice.dialPhone({
to: process.env.TO_NUMBER,
from: process.env.FROM_NUMBER,
timeout: 30
})

const tap = await call.tapAudio({
direction: "both",
device: {
type: "ws",
uri: "wss://2769-100-7-113-61.ngrok-free.app",
}
}).onStarted();

// wait 10 seconds then stop the tap

setTimeout(async () => {
console.log("Stopping tap");
await tap.stop();
}, 10000);

// wait for the tap to end
await tap.ended();
console.log("Tap ended");


await call.playTTS({
text: "Tap ended"
});

// hangup the call
call.hangup();

Properties

id

The unique ID for this tapping.

Syntax: CallTap.id()

Returns: string


Methods

ended

ended(): Promise<CallTap>

Returns a promise that is resolved only after this tap finishes (or is stopped).

Returns

Promise<CallTap>

A promise that resolves to CallTap object when the tap session has been ended.

Example

const tap = await call.tapAudio({
direction: "both",
device: {
type: "ws",
uri: "wss://example.domain.com/endpoint",
listen: {
// tap event listener
}
},
});

stop

stop(): Promise<CallTap>

Stops the tapping.

Returns

Promise<CallTap>

A promise that resolves to CallTap object when the tap session has been stopped.

Example

const tap = await call.tapAudio({
direction: "both",
device: {
type: "ws",
uri: "wss://example.domain.com/endpoint",
},
});

await tap.stop();

Events

onStarted

CallCollect.listen({ onStarted: Callback }})

Emitted when the tapping starts. Your event handler will receive an instance of CallTap.

Parameters

NameTypeDescription
tapCallTapThe tap that started.

onEnded

CallCollect.listen({ onEnded: Callback }})

Emitted when the tapping ends. Your event handler will receive an instance of CallTap.

Parameters

NameTypeDescription
tapCallTapThe tap that ended.