disconnected

View as Markdown

disconnected

  • disconnected(): Promise<Call>

Call this method after connecting a peer (e.g., using connect, connectPhone, or connectSip) to wait until the peer disconnects.

This is equivalent to calling peer.waitFor("ended") on the connected peer.

Returns

Promise<Call>

A promise that resolves to the Call object that you can use to control the call.

Example

In this example, we answer an incoming call and connect the call to a peer call. After connecting to the peer, we wait 3 seconds 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
18 // wait 3 seconds then disconnect the peer
19 setTimeout(() => {
20 console.log('Disconnecting Peer');
21 peer.hangup();
22 }, 3000);
23
24 await call.disconnected();
25
26 await call.playTTS({ text: 'Peer disconnected, ending call.' });
27 call.hangup();
28 }
29})