Skip to content

Added StreamParam for StartStream #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Voice/Bxml/StartStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public function streamEventMethod($streamEventMethod) {
$this->streamEventMethod = $streamEventMethod;
}

/**
* Sets the <StreamParam/> tag. You may specify up to 12 <StreamParam/> elements nested within a <StartStream> tag. These elements define optional user specified parameters that will be sent to the destination URL when the stream is first started.
*
* @param list<StreamParam> $streamParams The list of StreamParam tags
*/
public function streamParams($streamParams) {
$this->streamParams = $streamParams;
}

public function toBxml($doc) {
$element = $doc->createElement("StartStream");

Expand Down Expand Up @@ -108,6 +117,12 @@ public function toBxml($doc) {
$element->setattribute("streamEventMethod", $this->streamEventMethod);
}

if(isset($this->streamParams)) {
foreach ($this->streamParams as $streamParam) {
$element->appendChild($streamParam->toBxml($doc));
}
}

return $element;
}
}
47 changes: 47 additions & 0 deletions src/Voice/Bxml/StreamParam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* StreamParam.php
*
* Implementation of the BXML StreamParam tag. You may specify up to 12 <StreamParam/> elements nested within a <StartStream> tag. These elements define optional user specified parameters that will be sent to the destination URL when the stream is first started.
*
* * @copyright Bandwidth INC
*/

namespace BandwidthLib\Voice\Bxml;

require_once "Verb.php";

class StreamParam extends Verb {

/**
* Sets the name attribute for StreamParam
*
* @param string $name (required) The name of this parameter, up to 256 characters.
*/
public function name($name) {
$this->name = $name;
}

/**
* Sets the value attribute for StreamParam
*
* @param string $value (required) The value of this parameter, up to 2048 characters.
*/
public function value($value) {
$this->value = $value;
}

public function toBxml($doc) {
$element = $doc->createElement("StreamParam");

if(isset($this->name)) {
$element->setAttribute("name", $this->name);
}

if(isset($this->value)) {
$element->setAttribute("value", $this->value);
}

return $element;
}
}
10 changes: 9 additions & 1 deletion tests/BxmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ public function testStopRecording() {
$this->assertEquals($expectedXml, $responseXml);
}
public function testStartStream() {
$streamParam1 = new BandwidthLib\Voice\Bxml\StreamParam();
$streamParam1->name("name1");
$streamParam1->value("value1");
$streamParam2 = new BandwidthLib\Voice\Bxml\StreamParam();
$streamParam2->name("name2");
$streamParam2->value("value2");
$startStream = new BandwidthLib\Voice\Bxml\StartStream();
$startStream->name("test");
$startStream->tracks("inbound");
Expand All @@ -360,11 +366,13 @@ public function testStartStream() {
$startStream->username("user");
$startStream->password("pass");
$startStream->streamEventUrl("https://url.com");
$startStream->streamParams(array($streamParam1, $streamParam2));


$response = new BandwidthLib\Voice\Bxml\Response();
$response->addVerb($startStream);

$expectedXml = '<?xml version="1.0" encoding="UTF-8"?><Response><StartStream destination="https://url.com" name="test" tracks="inbound" username="user" password="pass" streamEventUrl="https://url.com" streamEventMethod="POST"/></Response>';
$expectedXml = '<?xml version="1.0" encoding="UTF-8"?><Response><StartStream destination="https://url.com" name="test" tracks="inbound" username="user" password="pass" streamEventUrl="https://url.com" streamEventMethod="POST"><StreamParam name="name1" value="value1"/><StreamParam name="name2" value="value2"/></StartStream></Response>';
$responseXml = $response->toBxml();
$this->assertEquals($expectedXml, $responseXml);
}
Expand Down