Relay.Calling.PlayAction

View as Markdown

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

Methods

getControlId

Return the UUID to identify the playing.

Parameters

None

Returns

string - UUID to identify the action.

Examples

Start the play and print the controlId.

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) {
4 echo $action->getControlId();
5});

getPayload

Return the payload sent to Relay to initiate the request. Useful to inspect what you sent to perform this action.

Parameters

None

Returns

Object - Payload sent to Relay.

Examples

Start the play and print out the payload.

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) {
4 print_r($action->getPayload());
5});

getResult

Returns the final result of the playing.

Parameters

None

Returns

Relay.Calling.PlayResult - Final result of the playing.

Examples

Start the play and grab the result when it’s completed.

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) {
4 // .. later in the code since it's an async method
5 if ($action->isCompleted()) {
6 $result = $action->getResult();
7 }
8});

getState

Return the current state of the playing.

Parameters

None

Returns

string - Current state of the playing.

Examples

Start the play and print the state.

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) {
4 echo $action->getState();
5});

isCompleted

Return true if the playing has finished, false otherwise.

Parameters

None

Returns

Boolean - True/False accordingly to the state.

Examples

Start the play and check if it has finished.

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) {
4 if ($action->isCompleted()) {
5
6 }
7});

pause

Pause the playback immediately.

Parameters

None

Returns

React\Promise\Promise - Promise object that will be fulfilled with a Relay.Calling.PlayPauseResult object.

Examples

Start playing an audio file and pause it.

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) {
4 // For demonstration purposes only..
5 $action->pause()->done(function($pauseResult) {
6 if ($pauseResult->successful) {
7
8 }
9 });
10});

resume

Resume the playback immediately.

Parameters

None

Returns

React\Promise\Promise - Promise object that will be fulfilled with a Relay.Calling.PlayResumeResult object.

Examples

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

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) {
4 // For demonstration purposes only..
5 $action->pause()->done(function($pauseResult) use ($action) {
6 // .. later in the code..
7 $action->resume()->done(function($resumeResult) {
8
9 });
10 });
11});

Note: you can avoid the callback hell using these methods in a Relay.Consumer.

stop

Stop the action immediately.

Parameters

None

Returns

React\Promise\Promise - Promise object that will be fulfilled with a Relay.Calling.StopResult object.

Examples

Start the play and stop it if an Agent is not available.

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) use ($globalAgent) {
4 if ($globalAgent->isAvailable() === false) {
5 $action->stop()->done(function($stopResult) {
6
7 });
8 }
9});

volume

Control the volume of the playback.

Parameters

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

Returns

React\Promise\Promise - Promise object that will be fulfilled with a Relay.Calling.PlayVolumeResult object.

Examples

Start the play and increase the playback volume.

1<?php
2
3$call->playAudioAsync('https://cdn.signalwire.com/default-music/welcome.mp3')->done(function($action) {
4 // For demonstration purposes only..
5 $action->volume(5.0)->done(function($volumeResult) {
6 if ($volumeResult->successful) {
7
8 }
9 });
10});