Skip to content

Commit f77566e

Browse files
Merge pull request #59 from Bandwidth/DX-2862
Added StreamParam for StartStream
2 parents a92620f + 1a86eeb commit f77566e

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

src/Voice/Bxml/StartStream.php

+15
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public function streamEventMethod($streamEventMethod) {
7777
$this->streamEventMethod = $streamEventMethod;
7878
}
7979

80+
/**
81+
* 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.
82+
*
83+
* @param list<StreamParam> $streamParams The list of StreamParam tags
84+
*/
85+
public function streamParams($streamParams) {
86+
$this->streamParams = $streamParams;
87+
}
88+
8089
public function toBxml($doc) {
8190
$element = $doc->createElement("StartStream");
8291

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

120+
if(isset($this->streamParams)) {
121+
foreach ($this->streamParams as $streamParam) {
122+
$element->appendChild($streamParam->toBxml($doc));
123+
}
124+
}
125+
111126
return $element;
112127
}
113128
}

src/Voice/Bxml/StreamParam.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* StreamParam.php
4+
*
5+
* 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.
6+
*
7+
* * @copyright Bandwidth INC
8+
*/
9+
10+
namespace BandwidthLib\Voice\Bxml;
11+
12+
require_once "Verb.php";
13+
14+
class StreamParam extends Verb {
15+
16+
/**
17+
* Sets the name attribute for StreamParam
18+
*
19+
* @param string $name (required) The name of this parameter, up to 256 characters.
20+
*/
21+
public function name($name) {
22+
$this->name = $name;
23+
}
24+
25+
/**
26+
* Sets the value attribute for StreamParam
27+
*
28+
* @param string $value (required) The value of this parameter, up to 2048 characters.
29+
*/
30+
public function value($value) {
31+
$this->value = $value;
32+
}
33+
34+
public function toBxml($doc) {
35+
$element = $doc->createElement("StreamParam");
36+
37+
if(isset($this->name)) {
38+
$element->setAttribute("name", $this->name);
39+
}
40+
41+
if(isset($this->value)) {
42+
$element->setAttribute("value", $this->value);
43+
}
44+
45+
return $element;
46+
}
47+
}

tests/BxmlTest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ public function testStopRecording() {
352352
$this->assertEquals($expectedXml, $responseXml);
353353
}
354354
public function testStartStream() {
355+
$streamParam1 = new BandwidthLib\Voice\Bxml\StreamParam();
356+
$streamParam1->name("name1");
357+
$streamParam1->value("value1");
358+
$streamParam2 = new BandwidthLib\Voice\Bxml\StreamParam();
359+
$streamParam2->name("name2");
360+
$streamParam2->value("value2");
355361
$startStream = new BandwidthLib\Voice\Bxml\StartStream();
356362
$startStream->name("test");
357363
$startStream->tracks("inbound");
@@ -360,11 +366,13 @@ public function testStartStream() {
360366
$startStream->username("user");
361367
$startStream->password("pass");
362368
$startStream->streamEventUrl("https://url.com");
369+
$startStream->streamParams(array($streamParam1, $streamParam2));
370+
363371

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

367-
$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>';
375+
$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>';
368376
$responseXml = $response->toBxml();
369377
$this->assertEquals($expectedXml, $responseXml);
370378
}

0 commit comments

Comments
 (0)