tap

View as Markdown

tap

Intercept call media and stream it to the specified WebSocket endpoint. Prefer using tapAudio if you only need to tap audio.

This is an experimental method. The destination must be a hosted WebSocket/RTP server, with an address that SignalWire can reach.

A current limitation of this method is that the destination device does not receive any metadata regarding the origin of the stream.

Parameters

params
objectRequired

Object containing the parameters for tapping the call.

device
TapDeviceRequired

Destination device. Can be either WebSocket or RTP. See TapDevice.

audio
objectRequired

An object with the configuration for audio tapping. See audio parameters below.

direction
"listen" | "speak" | "both"Required

Direction to tap. Can be "listen" (what the caller hears), "speak" (what the caller says), or "both".

listen
object

Callback to listen for events. List of tap events can be found here. Example event: onStarted.

Returns

Promise<CallTap>

A promise that resolves to a CallTap object that you can use to view the current state and results of the tap session.

Example

In this example, we dial a phone number and tap the call audio to a WebSocket endpoint. After the call is tapped, we play a TTS message to the caller, and then stop the tap and hangup the call.

1import { SignalWire } from "@signalwire/realtime-api";
2
3const client = await SignalWire({ project: "ProjectID Here", token: "Token Here" })
4
5const voiceClient = client.voice;
6
7// Listen for incoming calls
8await voiceClient.listen({
9
10 topics: ["office"],
11 onCallReceived: async (call) => {
12 console.log("Call received");
13 // Answer the call
14 await call.answer();
15
16 // Start a tap
17 const callTap = await call.tap({
18 device: {
19 type: "ws",
20 uri: "wss://example.domain.com/websocket_endpoint"
21 },
22 audio: {
23 direction: "both",
24 },
25 listen: {
26 onStarted: () => {
27 console.log("Tap started");
28 },
29 onEnded: () => {
30 console.log("Tap ended");
31 },
32 }
33 }).onStarted();
34 await call.playTTS({ text: "We are currently tapping the call audio." });
35 // Stop the tap
36 await callTap.stop();
37 call.hangup();
38 }
39});