playRingtone

View as Markdown

playRingtone

Plays a ringtone.

Parameters

params
objectRequired

Object containing the parameters for playing a ringtone.

name
RingtoneNameRequired

The name of the ringtone. See RingtoneName.

duration
number

Duration of ringtone to play in seconds. Defaults to 1 ringtone iteration.

volume
numberDefaults to 0

Volume value between -40dB and +40dB where 0 is unchanged.

listen
object

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

Returns

Promise<CallPlayback>

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

Example

In this example, we dial a phone number and play a ringtone for a duration of 10 seconds. Once the ringtone is finished playing, we 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 topics: ["office"],
10 onCallReceived: async (call) => {
11 console.log("Call received");
12 // Answer the call and play a ringtone. Listens for playback events. Ends the call after the ringtone is finished playing for 10 seconds.
13 call.answer();
14 await call.playRingtone({
15 duration: 10,
16 name: "it",
17 listen: {
18 onStarted: () => console.log("Ringtone started"),
19 onFailed: () => console.log("Ringtone failed"),
20 onUpdated: (event) => console.log("Ringtone updated", event.state),
21 onEnded: (event) => {
22 console.log("Ringtone ended", event);
23 call.hangup();
24 }
25 }
26 }).onStarted();
27 }
28});