Relay.Calling.PlayAction

View as Markdown

This object returned from one of asynchronous play methods that represents a playing currently active on a call.

Properties

PropertyTypeDescription
resultRelay.Calling.PlayResultFinal result of playing
statestringCurrent state of playing
completedbooleanWhether the playing has finished
payloadobjectPayload sent to Relay to start playing
controlIdstringUUID to identify the playing

Methods

pause

Pause the playback immediately.

Parameters

None

Returns

Promise<PlayPauseResult> - Promise object that will be fulfilled with a Relay.Calling.PlayPauseResult object.

Examples

Start playing an audio file and pause it after 5 seconds.

1// Promise to wait some seconds..
2const sleep = (seconds) => new Promise(resolve => setTimeout(resolve, seconds*1000))
3
4async function main() {
5 const playAction = await call.playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')
6 await sleep(5)
7 const pauseResult = await playAction.pause()
8}
9
10main().catch(console.error)

resume

Resume the playback immediately.

Parameters

None

Returns

Promise<PlayResumeResult> - Promise object that will be fulfilled with a Relay.Calling.PlayResumeResult object.

Examples

Start playing an audio file, stop it and then resume it after 5 seconds.

1// Promise to wait some seconds..
2const sleep = (seconds) => new Promise(resolve => setTimeout(resolve, seconds*1000))
3
4async function main() {
5 const playAction = await call.playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')
6 await sleep(5)
7 const pauseResult = await playAction.pause()
8 await sleep(5)
9 const resumeResult = await playAction.resume()
10}
11
12main().catch(console.error)

stop

Stop the action immediately.

Parameters

None

Returns

Promise<StopResult> - Promise object that will be fulfilled with a Relay.Calling.StopResult object.

Examples

Start playing an audio file and stop it after 5 seconds.

1async function main() {
2 const playAction = await call.playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')
3
4 setTimeout(async () => {
5 const stopResult = await playAction.stop()
6 }, 5000)
7}
8
9main().catch(console.error)

volume

Control the volume of the playback.

Parameters

ParameterTypeRequiredDescription
volumenumberVolume value between -40dB and +40dB where 0 is unchanged

Returns

Promise<PlayVolumeResult> - Promise object that will be fulfilled with a Relay.Calling.PlayVolumeResult object.

Examples

Start playing an audio file and increase the playback volume.

1async function main() {
2 const playAction = await call.playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')
3 const volumeResult = await playAction.volume(5.0)
4}
5
6main().catch(console.error)