Skip to content

Commit

Permalink
Merge pull request #59 from Bandwidth/DX-2862
Browse files Browse the repository at this point in the history
Added StreamParam for StartStream
  • Loading branch information
brianluisgomez authored Sep 20, 2022
2 parents a92620f + 1a86eeb commit f77566e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
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

0 comments on commit f77566e

Please sign in to comment.