Relay.Calling.PlayAction
This object returned from one of asynchronous play methods that represents a playing currently active on a call.
Properties​
Property | Type | Description |
---|---|---|
result | Relay.Calling.PlayResult | Final result of playing |
state | string | Current state of playing |
completed | boolean | Whether the playing has finished |
payload | object | Payload sent to Relay to start playing |
controlId | string | UUID 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.
// Promise to wait some seconds..
const sleep = (seconds) => new Promise(resolve => setTimeout(resolve, seconds*1000))
async function main() {
const playAction = await call.playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')
await sleep(5)
const pauseResult = await playAction.pause()
}
main().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.
// Promise to wait some seconds..
const sleep = (seconds) => new Promise(resolve => setTimeout(resolve, seconds*1000))
async function main() {
const playAction = await call.playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')
await sleep(5)
const pauseResult = await playAction.pause()
await sleep(5)
const resumeResult = await playAction.resume()
}
main().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.
async function main() {
const playAction = await call.playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')
setTimeout(async () => {
const stopResult = await playAction.stop()
}, 5000)
}
main().catch(console.error)
volume​
Control the volume of the playback.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
volume | number | ✓ | Volume 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.
async function main() {
const playAction = await call.playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')
const volumeResult = await playAction.volume(5.0)
}
main().catch(console.error)