From 66d24e29e221ddf4a65af179f6ce5f208be7c378 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 1 Aug 2022 17:09:22 -0400 Subject: [PATCH 1/7] DX-2704 --- src/Voice/Bxml/StartStream.php | 113 +++++++++++++++++++++++++++++++++ src/Voice/Bxml/StopStream.php | 34 ++++++++++ tests/BxmlTest.php | 29 +++++++++ 3 files changed, 176 insertions(+) create mode 100644 src/Voice/Bxml/StartStream.php create mode 100644 src/Voice/Bxml/StopStream.php diff --git a/src/Voice/Bxml/StartStream.php b/src/Voice/Bxml/StartStream.php new file mode 100644 index 0000000..d794e25 --- /dev/null +++ b/src/Voice/Bxml/StartStream.php @@ -0,0 +1,113 @@ +destination = $destination; + } + + /** + * Sets the name attribute for StartStream + * + * @param string $name A name to refer to this stream by. Used when sending [``][1]. If not provided, a random name will be generated and sent in the [`Media Stream Started`][2] webook + */ + public function name($name) { + $this->name = $name; + } + + /** + * Sets the tracks attribute for StartStream + * + * @param string $tracks The part of the call to send a stream from. `inbound`, `outbound` or `both`. Default is `inbound`. + * as ("GET" or "POST") + */ + public function tracks($tracks) { + $this->tracks = $tracks; + } + + /** + * Sets the username attribute for StartStream + * + * @param string $username The username to send in the HTTP request to `streamEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`). + */ + public function username($username) { + $this->username = $username; + } + + /** + * Sets the password attribute for StartStream + * + * @param string $password The password to send in the HTTP request to `streamEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`). + */ + public function password($password) { + $this->password = $password; + } + + /** + * Sets the streamEventUrl attribute for StartStream + * + * @param string $streamEventUrl URL to send the associated Webhook events to during this stream's lifetime. Does not accept BXML. May be a relative URL. + */ + public function streamEventUrl($streamEventUrl) { + $this->streamEventUrl = $streamEventUrl; + } + + /** + * Sets the streamEventMethod attribute for StartStream + * + * @param bool $streamEventMethod The HTTP method to use for the request to `streamEventUrl`. GET or POST. Default value is POST. + */ + public function streamEventMethod($streamEventMethod) { + $this->streamEventMethod = $streamEventMethod; + } + + public function toBxml($doc) { + $element = $doc->createElement("StartStream"); + + if(isset($this->destination)) { + $element->setattribute("destination", $this->destination); + } + + if(isset($this->name)) { + $element->setattribute("name", $this->name); + } + + if(isset($this->tracks)) { + $element->setattribute("tracks", $this->tracks); + } + + if(isset($this->username)) { + $element->setattribute("username", $this->username); + } + + if(isset($this->password)) { + $element->setattribute("password", $this->password); + } + + if(isset($this->streamEventUrl)) { + $element->setattribute("streamEventUrl", $this->streamEventUrl); + } + + if(isset($this->streamEventMethod)) { + $element->setattribute("streamEventMethod", $this->streamEventMethod); + } + + return $element; + } +} diff --git a/src/Voice/Bxml/StopStream.php b/src/Voice/Bxml/StopStream.php new file mode 100644 index 0000000..c6f1466 --- /dev/null +++ b/src/Voice/Bxml/StopStream.php @@ -0,0 +1,34 @@ +`][1] verb, or the system generated name returned in the [Media Stream Started][2] webhook if `` was sent with no `name` attribute. + */ + public function name($name) { + $this->name = $name; + } + + public function toBxml($doc) { + $element = $doc->createElement("StopStream"); + + if(isset($this->name)) { + $element->setAttribute("name", $this->name); + } + + return $element; + } +} diff --git a/tests/BxmlTest.php b/tests/BxmlTest.php index 109cbc3..513c9d0 100644 --- a/tests/BxmlTest.php +++ b/tests/BxmlTest.php @@ -351,6 +351,35 @@ public function testStopRecording() { $responseXml = $response->toBxml(); $this->assertEquals($expectedXml, $responseXml); } + public function testStartStream() { + $startStream = new BandwidthLib\Voice\Bxml\StartStream(); + $startStream->name("test"); + $startStream->destination("https://url.com"); + $startStream->streamEventMethod("POST"); + $startStream->username("user"); + $startStream->password("pass"); + $startStream->streamEventUrl("https://url.com"); + + + $response = new BandwidthLib\Voice\Bxml\Response(); + $response->addVerb($startStream); + + $expectedXml = ''; + $responseXml = $response->toBxml(); + $this->assertEquals($expectedXml, $responseXml); + } + + public function testStopStream() { + $stopStream = new BandwidthLib\Voice\Bxml\StopStream(); + $stopStream->name("test"); + + $response = new BandwidthLib\Voice\Bxml\Response(); + $response->addVerb($stopStream); + + $expectedXml = 'tracks = $tracks; @@ -107,7 +107,7 @@ public function toBxml($doc) { if(isset($this->streamEventMethod)) { $element->setattribute("streamEventMethod", $this->streamEventMethod); } - + return $element; } } From e1174ab81788c39a4fdc90d83c0cae527d439940 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 4 Aug 2022 10:23:31 -0400 Subject: [PATCH 3/7] Update BxmlTest.php --- tests/BxmlTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BxmlTest.php b/tests/BxmlTest.php index 513c9d0..b09beaa 100644 --- a/tests/BxmlTest.php +++ b/tests/BxmlTest.php @@ -376,7 +376,7 @@ public function testStopStream() { $response = new BandwidthLib\Voice\Bxml\Response(); $response->addVerb($stopStream); - $expectedXml = ''; $responseXml = $response->toBxml(); $this->assertEquals($expectedXml, $responseXml); } From 0a5a63ecfba225b9539994e84198686ae3882425 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 4 Aug 2022 11:55:56 -0400 Subject: [PATCH 4/7] Update BxmlTest.php --- tests/BxmlTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BxmlTest.php b/tests/BxmlTest.php index b09beaa..8b9b430 100644 --- a/tests/BxmlTest.php +++ b/tests/BxmlTest.php @@ -364,7 +364,7 @@ public function testStartStream() { $response = new BandwidthLib\Voice\Bxml\Response(); $response->addVerb($startStream); - $expectedXml = ''; + $expectedXml = ''; $responseXml = $response->toBxml(); $this->assertEquals($expectedXml, $responseXml); } From fb27d401f3fcea50af6dd10682c3ff7dabd8afe8 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 4 Aug 2022 13:38:42 -0400 Subject: [PATCH 5/7] Update BxmlTest.php --- tests/BxmlTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/BxmlTest.php b/tests/BxmlTest.php index 8b9b430..60caf0f 100644 --- a/tests/BxmlTest.php +++ b/tests/BxmlTest.php @@ -354,17 +354,17 @@ public function testStopRecording() { public function testStartStream() { $startStream = new BandwidthLib\Voice\Bxml\StartStream(); $startStream->name("test"); + $startStream->tracks("inbound"); $startStream->destination("https://url.com"); $startStream->streamEventMethod("POST"); $startStream->username("user"); $startStream->password("pass"); $startStream->streamEventUrl("https://url.com"); - $response = new BandwidthLib\Voice\Bxml\Response(); $response->addVerb($startStream); - $expectedXml = ''; + $expectedXml = ''; $responseXml = $response->toBxml(); $this->assertEquals($expectedXml, $responseXml); } From 74c87d9bd28fc54781d810081ce7b4ed1a8a5c53 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 5 Aug 2022 16:46:15 -0400 Subject: [PATCH 6/7] Update BxmlTest.php --- tests/BxmlTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BxmlTest.php b/tests/BxmlTest.php index 60caf0f..78516dc 100644 --- a/tests/BxmlTest.php +++ b/tests/BxmlTest.php @@ -364,7 +364,7 @@ public function testStartStream() { $response = new BandwidthLib\Voice\Bxml\Response(); $response->addVerb($startStream); - $expectedXml = ''; + $expectedXml = ''; $responseXml = $response->toBxml(); $this->assertEquals($expectedXml, $responseXml); } From 3a90b0e3f5c19de59d4c59c4340ff4fd133ef5a8 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 5 Aug 2022 16:50:10 -0400 Subject: [PATCH 7/7] DX-2704 --- tests/BxmlTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BxmlTest.php b/tests/BxmlTest.php index 78516dc..a81417e 100644 --- a/tests/BxmlTest.php +++ b/tests/BxmlTest.php @@ -364,7 +364,7 @@ public function testStartStream() { $response = new BandwidthLib\Voice\Bxml\Response(); $response->addVerb($startStream); - $expectedXml = ''; + $expectedXml = ''; $responseXml = $response->toBxml(); $this->assertEquals($expectedXml, $responseXml); }