disconnect

View as Markdown

disconnect

  • disconnect(): Promise<void>

Disconnects the connected peer from the call.

Returns

Promise<void>

Example

In this example, we answer an incoming call and connect the call to a peer call. Once connected to the peer, we play a TTS message to the peer and then disconnect the peer. Once the peer is disconnected, we play a TTS message to the inbound call leg and then 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
7await voiceClient.listen({
8 topics: ['office'],
9 onCallReceived: async (call) => {
10 // Answer the call
11 call.answer();
12 // Connect call to a new peer
13 let peer = await call.connectPhone({
14 from: call.from,
15 to: "Destination Number Here"
16 })
17 // Play TTS to the peer
18 await peer.playTTS({ text: 'Hello from SignalWire!' });
19 // Disconnect the peer call
20 call.disconnect();
21 await call.playTTS({ text: 'Disconnecting Peer!' });
22 console.log("The Peer and Call have been disconnected, but the calls are still active.")
23 // Hangup the peer call
24 await peer.playTTS({ text: 'Ending Peer Session' });
25 peer.hangup();
26 // Hangup the call
27 await call.playTTS({ text: 'Ending Call Session' });
28 call.hangup();
29 }
30})