CallTap

View as Markdown

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.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const call = await client.voice.dialPhone({
6 to: process.env.TO_NUMBER,
7 from: process.env.FROM_NUMBER,
8 timeout: 30
9})
10
11const tap = await call.tapAudio({
12 direction: "both",
13 device: {
14 type: "ws",
15 uri: "wss://2769-100-7-113-61.ngrok-free.app",
16 }
17}).onStarted();
18
19// wait 10 seconds then stop the tap
20
21setTimeout(async () => {
22 console.log("Stopping tap");
23 await tap.stop();
24}, 10000);
25
26// wait for the tap to end
27await tap.ended();
28console.log("Tap ended");
29
30await call.playTTS({
31 text: "Tap ended"
32});
33
34// hangup the call
35call.hangup();

Properties

id
string

The unique ID for this tap session.

state
"tapping" | "finished"

The current state of the tap session.

hasEnded
boolean

Whether the tap has ended. Returns true if the state is "finished".

Methods

ended

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

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
4
5const call = await client.voice.dialPhone({
6 from: "+1xxxxxxxxxx",
7 to: "+1yyyyyyyyyy",
8 timeout: 30
9});
10
11const tap = await call.tapAudio({
12 direction: "both",
13 device: {
14 type: "ws",
15 uri: "wss://example.domain.com/endpoint"
16 },
17 listen: {
18 onStarted: () => console.log("Tap started"),
19 onEnded: () => console.log("Tap ended")
20 }
21}).onStarted();
22
23// Wait for tap to finish
24await tap.ended();
25console.log("Tap session completed");

stop

Stops the tapping.

Returns

Promise<CallTap>

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

Example

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "your-project-id", token: "your-api-token" });
4
5const call = await client.voice.dialPhone({
6 from: "+1xxxxxxxxxx",
7 to: "+1yyyyyyyyyy",
8 timeout: 30
9});
10
11// Start tapping audio to an RTP endpoint
12const tap = await call.tapAudio({
13 direction: "both",
14 device: {
15 type: "rtp",
16 addr: "192.0.2.1",
17 port: "5000",
18 codec: "PCMU"
19 }
20}).onStarted();
21
22console.log("Tap started with ID:", tap.id);
23
24// Stop the tap after processing
25await tap.stop();
26console.log("Tap stopped");

Events

onStarted

  • CallTap.listen({ onStarted: Callback }})

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

Parameters

tap
CallTapRequired

The tap that started. See CallTap.

onEnded

  • CallTap.listen({ onEnded: Callback }})

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

Parameters

tap
CallTapRequired

The tap that ended. See CallTap.