|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * StartStream.php |
| 4 | + * |
| 5 | + * Implementation of the BXML StartStream verb |
| 6 | + * |
| 7 | + * @copyright Bandwidth INC |
| 8 | + */ |
| 9 | + |
| 10 | +namespace BandwidthLib\Voice\Bxml; |
| 11 | + |
| 12 | +require_once "Verb.php"; |
| 13 | + |
| 14 | +class StartStream extends Verb { |
| 15 | + |
| 16 | + /** |
| 17 | + * Sets the destination attribute for StartStream |
| 18 | + * |
| 19 | + * @param string $destination A websocket URI to send the stream to. The audio from the specified tracks will be sent via websocket to this URL encoded as base64 encoded PCMU/G711 audio. See below for more details on the websocket packet format. |
| 20 | + */ |
| 21 | + public function destination($destination) { |
| 22 | + $this->destination = $destination; |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Sets the name attribute for StartStream |
| 27 | + * |
| 28 | + * @param string $name A name to refer to this stream by. Used when sending [`<StopStream>`][1]. If not provided, a random name will be generated and sent in the [`Media Stream Started`][2] webook |
| 29 | + */ |
| 30 | + public function name($name) { |
| 31 | + $this->name = $name; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Sets the tracks attribute for StartStream |
| 36 | + * |
| 37 | + * @param string $tracks The part of the call to send a stream from. `inbound`, `outbound` or `both`. Default is `inbound`. |
| 38 | + * |
| 39 | + */ |
| 40 | + public function tracks($tracks) { |
| 41 | + $this->tracks = $tracks; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Sets the username attribute for StartStream |
| 46 | + * |
| 47 | + * @param string $username The username to send in the HTTP request to `streamEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`). |
| 48 | + */ |
| 49 | + public function username($username) { |
| 50 | + $this->username = $username; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Sets the password attribute for StartStream |
| 55 | + * |
| 56 | + * @param string $password The password to send in the HTTP request to `streamEventUrl`. If specified, the URLs must be TLS-encrypted (i.e., `https`). |
| 57 | + */ |
| 58 | + public function password($password) { |
| 59 | + $this->password = $password; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Sets the streamEventUrl attribute for StartStream |
| 64 | + * |
| 65 | + * @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. |
| 66 | + */ |
| 67 | + public function streamEventUrl($streamEventUrl) { |
| 68 | + $this->streamEventUrl = $streamEventUrl; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Sets the streamEventMethod attribute for StartStream |
| 73 | + * |
| 74 | + * @param bool $streamEventMethod The HTTP method to use for the request to `streamEventUrl`. GET or POST. Default value is POST. |
| 75 | + */ |
| 76 | + public function streamEventMethod($streamEventMethod) { |
| 77 | + $this->streamEventMethod = $streamEventMethod; |
| 78 | + } |
| 79 | + |
| 80 | + public function toBxml($doc) { |
| 81 | + $element = $doc->createElement("StartStream"); |
| 82 | + |
| 83 | + if(isset($this->destination)) { |
| 84 | + $element->setattribute("destination", $this->destination); |
| 85 | + } |
| 86 | + |
| 87 | + if(isset($this->name)) { |
| 88 | + $element->setattribute("name", $this->name); |
| 89 | + } |
| 90 | + |
| 91 | + if(isset($this->tracks)) { |
| 92 | + $element->setattribute("tracks", $this->tracks); |
| 93 | + } |
| 94 | + |
| 95 | + if(isset($this->username)) { |
| 96 | + $element->setattribute("username", $this->username); |
| 97 | + } |
| 98 | + |
| 99 | + if(isset($this->password)) { |
| 100 | + $element->setattribute("password", $this->password); |
| 101 | + } |
| 102 | + |
| 103 | + if(isset($this->streamEventUrl)) { |
| 104 | + $element->setattribute("streamEventUrl", $this->streamEventUrl); |
| 105 | + } |
| 106 | + |
| 107 | + if(isset($this->streamEventMethod)) { |
| 108 | + $element->setattribute("streamEventMethod", $this->streamEventMethod); |
| 109 | + } |
| 110 | + |
| 111 | + return $element; |
| 112 | + } |
| 113 | +} |
0 commit comments