Skip to main content

Relay.Calling.PlayAction

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.

// 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

ParameterTypeRequiredDescription
volumenumber✓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)