Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/OpenTok/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function __construct($archiveData, $options = array())
Validators::validateHasStreamMode($streamMode);

$this->data = $archiveData;

if (isset($this->data['multiArchiveTag'])) {
$this->multiArchiveTag = $this->data['multiArchiveTag'];
}
Expand All @@ -162,6 +163,7 @@ public function __get($name)
if ($this->isDeleted) {
// TODO: throw an logic error about not being able to stop an archive thats deleted
}

switch ($name) {
case 'createdAt':
case 'duration':
Expand All @@ -178,6 +180,7 @@ public function __get($name)
case 'outputMode':
case 'resolution':
case 'streamMode':
case 'maxBitrate':
return $this->data[$name];
case 'multiArchiveTag':
return $this->multiArchiveTag;
Expand Down
10 changes: 10 additions & 0 deletions src/OpenTok/OpenTok.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,19 @@ public function startArchive(string $sessionId, $options = []): Archive
'resolution' => null,
'streamMode' => StreamMode::AUTO,
);

// Horrible hack to workaround the defaults behaviour
if (isset($options['maxBitrate'])) {
$maxBitrate = $options['maxBitrate'];
}

$options = array_merge($defaults, array_intersect_key($options, $defaults));
list($name, $hasVideo, $hasAudio, $outputMode, $resolution, $streamMode) = array_values($options);

if (isset($maxBitrate)) {
$options['maxBitrate'] = $maxBitrate;
}

Validators::validateSessionId($sessionId);
Validators::validateArchiveName($name);

Expand Down
36 changes: 34 additions & 2 deletions tests/OpenTokTest/OpenTokTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ public function testStartsArchive(): void
$sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-';

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

// Assert
$this->assertCount(1, $this->historyContainer);
Expand All @@ -779,6 +779,7 @@ public function testStartsArchive(): void
$this->assertEquals('', $archive->reason);
$this->assertEquals('started', $archive->status);
$this->assertEquals(OutputMode::COMPOSED, $archive->outputMode);
$this->assertEquals(2000000, $archive->maxBitrate);
$this->assertNull($archive->name);
$this->assertNull($archive->url);
$this->assertTrue($archive->hasVideo);
Expand Down Expand Up @@ -1246,7 +1247,38 @@ public function testGetsArchive(): void
$this->assertEquals(true, TestHelpers::validateOpenTokAuthHeader($this->API_KEY, $this->API_SECRET, $authString));

$this->assertInstanceOf('OpenTok\Archive', $archive);
// TODO: test the properties of the actual archive object
}

public function testGetsArchiveWithMaxBitrate(): void
{
// Arrange
$this->setupOTWithMocks([[
'code' => 200,
'headers' => [
'Content-Type' => 'application/json'
],
'path' => 'v2/project/APIKEY/archive/ARCHIVEID/get'
]]);

$archiveId = '063e72a4-64b4-43c8-9da5-eca071daab89';

// Act
$archive = $this->opentok->getArchive($archiveId);

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

$request = $this->historyContainer[0]['request'];
$this->assertEquals('GET', strtoupper($request->getMethod()));
$this->assertEquals('/v2/project/'.$this->API_KEY.'/archive/'.$archiveId, $request->getUri()->getPath());
$this->assertEquals('api.opentok.com', $request->getUri()->getHost());
$this->assertEquals('https', $request->getUri()->getScheme());

$authString = $request->getHeaderLine('X-OPENTOK-AUTH');
$this->assertEquals(true, TestHelpers::validateOpenTokAuthHeader($this->API_KEY, $this->API_SECRET, $authString));

$this->assertInstanceOf('OpenTok\Archive', $archive);
$this->assertEquals(2000000, $archive->maxBitrate);
}

public function testDeletesArchive(): void
Expand Down
1 change: 1 addition & 0 deletions tests/mock/v2/project/APIKEY/archive/ARCHIVEID/get
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"duration" : 199,
"id" : "063e72a4-64b4-43c8-9da5-eca071daab89",
"name" : "showtime",
"maxBitrate": 2000000,
"partnerId" : 854511,
"reason" : "",
"sessionId" : "2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-",
Expand Down
1 change: 1 addition & 0 deletions tests/mock/v2/project/APIKEY/archive/session
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"duration" : 0,
"id" : "832641bf-5dbf-41a1-ad94-fea213e59a92",
"name" : null,
"maxBitrate": 2000000,
"partnerId" : 12345678,
"reason" : "",
"sessionId" : "2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-",
Expand Down
Loading