Skip to content

Commit c249956

Browse files
committed
Added max bitrate and tests
1 parent ef2e91c commit c249956

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

src/OpenTok/Archive.php

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public function __construct($archiveData, $options = array())
137137
Validators::validateHasStreamMode($streamMode);
138138

139139
$this->data = $archiveData;
140+
140141
if (isset($this->data['multiArchiveTag'])) {
141142
$this->multiArchiveTag = $this->data['multiArchiveTag'];
142143
}
@@ -162,6 +163,7 @@ public function __get($name)
162163
if ($this->isDeleted) {
163164
// TODO: throw an logic error about not being able to stop an archive thats deleted
164165
}
166+
165167
switch ($name) {
166168
case 'createdAt':
167169
case 'duration':
@@ -178,6 +180,7 @@ public function __get($name)
178180
case 'outputMode':
179181
case 'resolution':
180182
case 'streamMode':
183+
case 'maxBitrate':
181184
return $this->data[$name];
182185
case 'multiArchiveTag':
183186
return $this->multiArchiveTag;

src/OpenTok/OpenTok.php

+10
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,19 @@ public function startArchive(string $sessionId, $options = []): Archive
502502
'resolution' => null,
503503
'streamMode' => StreamMode::AUTO,
504504
);
505+
506+
// Horrible hack to workaround the defaults behaviour
507+
if (isset($options['maxBitrate'])) {
508+
$maxBitrate = $options['maxBitrate'];
509+
}
510+
505511
$options = array_merge($defaults, array_intersect_key($options, $defaults));
506512
list($name, $hasVideo, $hasAudio, $outputMode, $resolution, $streamMode) = array_values($options);
507513

514+
if (isset($maxBitrate)) {
515+
$options['maxBitrate'] = $maxBitrate;
516+
}
517+
508518
Validators::validateSessionId($sessionId);
509519
Validators::validateArchiveName($name);
510520

tests/OpenTokTest/OpenTokTest.php

+34-2
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ public function testStartsArchive(): void
756756
$sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-';
757757

758758
// Act
759-
$archive = $this->opentok->startArchive($sessionId);
759+
$archive = $this->opentok->startArchive($sessionId, ['maxBitrate' => 2000000]);
760760

761761
// Assert
762762
$this->assertCount(1, $this->historyContainer);
@@ -779,6 +779,7 @@ public function testStartsArchive(): void
779779
$this->assertEquals('', $archive->reason);
780780
$this->assertEquals('started', $archive->status);
781781
$this->assertEquals(OutputMode::COMPOSED, $archive->outputMode);
782+
$this->assertEquals(2000000, $archive->maxBitrate);
782783
$this->assertNull($archive->name);
783784
$this->assertNull($archive->url);
784785
$this->assertTrue($archive->hasVideo);
@@ -1246,7 +1247,38 @@ public function testGetsArchive(): void
12461247
$this->assertEquals(true, TestHelpers::validateOpenTokAuthHeader($this->API_KEY, $this->API_SECRET, $authString));
12471248

12481249
$this->assertInstanceOf('OpenTok\Archive', $archive);
1249-
// TODO: test the properties of the actual archive object
1250+
}
1251+
1252+
public function testGetsArchiveWithMaxBitrate(): void
1253+
{
1254+
// Arrange
1255+
$this->setupOTWithMocks([[
1256+
'code' => 200,
1257+
'headers' => [
1258+
'Content-Type' => 'application/json'
1259+
],
1260+
'path' => 'v2/project/APIKEY/archive/ARCHIVEID/get'
1261+
]]);
1262+
1263+
$archiveId = '063e72a4-64b4-43c8-9da5-eca071daab89';
1264+
1265+
// Act
1266+
$archive = $this->opentok->getArchive($archiveId);
1267+
1268+
// Assert
1269+
$this->assertCount(1, $this->historyContainer);
1270+
1271+
$request = $this->historyContainer[0]['request'];
1272+
$this->assertEquals('GET', strtoupper($request->getMethod()));
1273+
$this->assertEquals('/v2/project/'.$this->API_KEY.'/archive/'.$archiveId, $request->getUri()->getPath());
1274+
$this->assertEquals('api.opentok.com', $request->getUri()->getHost());
1275+
$this->assertEquals('https', $request->getUri()->getScheme());
1276+
1277+
$authString = $request->getHeaderLine('X-OPENTOK-AUTH');
1278+
$this->assertEquals(true, TestHelpers::validateOpenTokAuthHeader($this->API_KEY, $this->API_SECRET, $authString));
1279+
1280+
$this->assertInstanceOf('OpenTok\Archive', $archive);
1281+
$this->assertEquals(2000000, $archive->maxBitrate);
12501282
}
12511283

12521284
public function testDeletesArchive(): void

tests/mock/v2/project/APIKEY/archive/ARCHIVEID/get

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"duration" : 199,
44
"id" : "063e72a4-64b4-43c8-9da5-eca071daab89",
55
"name" : "showtime",
6+
"maxBitrate": 2000000,
67
"partnerId" : 854511,
78
"reason" : "",
89
"sessionId" : "2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-",

tests/mock/v2/project/APIKEY/archive/session

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"duration" : 0,
44
"id" : "832641bf-5dbf-41a1-ad94-fea213e59a92",
55
"name" : null,
6+
"maxBitrate": 2000000,
67
"partnerId" : 12345678,
78
"reason" : "",
89
"sessionId" : "2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-",

0 commit comments

Comments
 (0)