Skip to content

Commit c09e813

Browse files
committed
Add new max bitrate
1 parent eb070bb commit c09e813

File tree

9 files changed

+60
-15
lines changed

9 files changed

+60
-15
lines changed

src/OpenTok/Broadcast.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class Broadcast
9191
private $hasVideo;
9292
/** @ignore */
9393
private $status;
94+
/** @ignore */
95+
private $maxBitRate;
9496

9597
public function __construct($broadcastData, $options = array())
9698
{
@@ -123,6 +125,10 @@ public function __construct($broadcastData, $options = array())
123125
$this->multiBroadcastTag = $this->data['multiBroadcastTag'];
124126
}
125127

128+
if (isset($this->data['maxBitRate'])) {
129+
$this->maxBitRate = $this->data['maxBitRate'];
130+
}
131+
126132
if (isset($this->data['status'])) {
127133
$this->status = $this->data['status'];
128134
}
@@ -179,6 +185,8 @@ public function __get($name)
179185
return $this->hasVideo;
180186
case 'status':
181187
return $this->status;
188+
case 'maxBitRate':
189+
return $this->maxBitRate;
182190
default:
183191
return null;
184192
}

src/OpenTok/OpenTok.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,10 @@ public function startBroadcast(string $sessionId, array $options = []): Broadcas
864864
// not preferred to depend on that in the SDK because its then harder to garauntee backwards
865865
// compatibility
866866

867+
if (isset($options['maxBitRate'])) {
868+
Validators::validateBroadcastBitrate($options['maxBitRate']);
869+
}
870+
867871
if (isset($options['resolution'])) {
868872
Validators::validateResolution($options['resolution']);
869873
}
@@ -882,6 +886,7 @@ public function startBroadcast(string $sessionId, array $options = []): Broadcas
882886
'hasVideo' => true,
883887
'streamMode' => 'auto',
884888
'resolution' => '640x480',
889+
'maxBitRate' => 2000000,
885890
'outputs' => [
886891
'hls' => [
887892
'dvr' => false,
@@ -892,25 +897,21 @@ public function startBroadcast(string $sessionId, array $options = []): Broadcas
892897

893898
$options = array_merge($defaults, $options);
894899

895-
list($layout, $hasAudio, $hasVideo, $streamMode) = array_values($options);
896-
897-
// validate arguments
898900
Validators::validateSessionId($sessionId);
899-
Validators::validateLayout($layout);
900-
Validators::validateHasStreamMode($streamMode);
901+
Validators::validateLayout($options['layout']);
902+
Validators::validateHasStreamMode($options['streamMode']);
901903

902-
// make API call
903904
$broadcastData = $this->client->startBroadcast($sessionId, $options);
904905

905-
return new Broadcast($broadcastData, array('client' => $this->client));
906+
return new Broadcast($broadcastData, ['client' => $this->client]);
906907
}
907908

908909
/**
909910
* Stops a broadcast.
910911
*
911912
* @param String $broadcastId The ID of the broadcast.
912913
*/
913-
public function stopBroadcast($broadcastId)
914+
public function stopBroadcast($broadcastId): Broadcast
914915
{
915916
// validate arguments
916917
Validators::validateBroadcastId($broadcastId);
@@ -930,7 +931,7 @@ public function stopBroadcast($broadcastId)
930931
*
931932
* @return Broadcast An object with properties defining the broadcast.
932933
*/
933-
public function getBroadcast($broadcastId)
934+
public function getBroadcast($broadcastId): Broadcast
934935
{
935936
Validators::validateBroadcastId($broadcastId);
936937

src/OpenTok/Util/Validators.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,15 @@ protected static function decodeSessionId($sessionId)
486486
}
487487
return $data;
488488
}
489+
490+
public static function validateBroadcastBitrate($maxBitRate): void
491+
{
492+
if (!is_int($maxBitRate)) {
493+
throw new \InvalidArgumentException('Max Bitrate must be a number');
494+
}
495+
496+
if ($maxBitRate < 400000 && $maxBitRate > 2000000) {
497+
throw new \OutOfBoundsException('Max Bitrate must be between 400000 and 2000000');
498+
}
499+
}
489500
}

tests/OpenTokTest/OpenTokTest.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,6 @@ public function testCannotStartBroadcastWithBothHlsAndDvrEnabled(): void
17251725

17261726
public function testStartsBroadcast(): void
17271727
{
1728-
// Arrange
17291728
$this->setupOTWithMocks([[
17301729
'code' => 200,
17311730
'headers' => [
@@ -1734,14 +1733,10 @@ public function testStartsBroadcast(): void
17341733
'path' => '/v2/project/APIKEY/broadcast/session_layout-bestfit'
17351734
]]);
17361735

1737-
// This sessionId was generated using a different apiKey, but this method doesn't do any
1738-
// decoding to check, so it's fine.
17391736
$sessionId = '2_MX44NTQ1MTF-fjE0NzI0MzU2MDUyMjN-eVgwNFJhZmR6MjdockFHanpxNzBXaEFXfn4';
17401737

1741-
// Act
17421738
$broadcast = $this->opentok->startBroadcast($sessionId);
17431739

1744-
// Assert
17451740
$this->assertCount(1, $this->historyContainer);
17461741

17471742
$request = $this->historyContainer[0]['request'];
@@ -1767,9 +1762,34 @@ public function testStartsBroadcast(): void
17671762
$this->assertEquals('auto', $broadcast->streamMode);
17681763
}
17691764

1765+
public function testStartsBroadcastWithMaxBitrate(): void
1766+
{
1767+
$this->setupOTWithMocks([[
1768+
'code' => 200,
1769+
'headers' => [
1770+
'Content-Type' => 'application/json'
1771+
],
1772+
'path' => '/v2/project/APIKEY/broadcast/session_layout-bestfit'
1773+
]]);
1774+
1775+
$sessionId = '2_MX44NTQ1MTF-fjE0NzI0MzU2MDUyMjN-eVgwNFJhZmR6MjdockFHanpxNzBXaEFXfn4';
1776+
1777+
$broadcast = $this->opentok->startBroadcast($sessionId, [
1778+
'maxBitRate' => 2000000
1779+
]);
1780+
1781+
$this->assertIsString($broadcast->id);
1782+
$this->assertEquals($sessionId, $broadcast->sessionId);
1783+
$this->assertIsArray($broadcast->broadcastUrls);
1784+
$this->assertArrayHasKey('hls', $broadcast->broadcastUrls);
1785+
$this->assertIsString($broadcast->broadcastUrls['hls']);
1786+
$this->assertIsString($broadcast->hlsUrl);
1787+
$this->assertFalse($broadcast->isStopped);
1788+
$this->assertEquals(2000000, $broadcast->maxBitRate);
1789+
}
1790+
17701791
public function testStartsBroadcastWithMultiBroadcastTag(): void
17711792
{
1772-
// Arrange
17731793
$this->setupOTWithMocks([[
17741794
'code' => 200,
17751795
'headers' => [

tests/mock/v2/project/APIKEY/broadcast/BROADCASTID/start_default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"status":"started",
2525
"partnerId":854511,
2626
"maxDuration":5400,
27+
"maxBitRate": 2000000,
2728
"resolution": "1280x720",
2829
"streamMode": "auto",
2930
"hasAudio": true,

tests/mock/v2/project/APIKEY/broadcast/BROADCASTID/start_dvr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"status":"started",
2222
"partnerId":854511,
2323
"maxDuration":5400,
24+
"maxBitRate": 2000000,
2425
"resolution": "1280x720",
2526
"streamMode": "auto",
2627
"hasAudio": true,

tests/mock/v2/project/APIKEY/broadcast/BROADCASTID/start_ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"status":"started",
2525
"partnerId":854511,
2626
"maxDuration":5400,
27+
"maxBitRate": 2000000,
2728
"resolution": "1280x720",
2829
"streamMode": "auto",
2930
"hasAudio": true,

tests/mock/v2/project/APIKEY/broadcast/session_layout-bestfit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"status":"started",
2121
"partnerId":854511,
2222
"maxDuration":5400,
23+
"maxBitRate": 2000000,
2324
"resolution": "1280x720",
2425
"streamMode": "auto"
2526
}

tests/mock/v2/project/APIKEY/broadcast/session_manual_stream

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"status":"started",
2121
"partnerId":854511,
2222
"maxDuration":5400,
23+
"maxBitRate": 2000000,
2324
"resolution": "1280x720",
2425
"streamMode": "manual"
2526
}

0 commit comments

Comments
 (0)