From c24995630a2b1dc730249700b33626b36076832b Mon Sep 17 00:00:00 2001 From: Jim Seconde Date: Thu, 21 Nov 2024 12:12:15 +0000 Subject: [PATCH] Added max bitrate and tests --- src/OpenTok/Archive.php | 3 ++ src/OpenTok/OpenTok.php | 10 ++++++ tests/OpenTokTest/OpenTokTest.php | 36 +++++++++++++++++-- .../v2/project/APIKEY/archive/ARCHIVEID/get | 1 + tests/mock/v2/project/APIKEY/archive/session | 1 + 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/OpenTok/Archive.php b/src/OpenTok/Archive.php index 3759f721..14cb0c68 100644 --- a/src/OpenTok/Archive.php +++ b/src/OpenTok/Archive.php @@ -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']; } @@ -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': @@ -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; diff --git a/src/OpenTok/OpenTok.php b/src/OpenTok/OpenTok.php index b21ebc87..bdc8967c 100644 --- a/src/OpenTok/OpenTok.php +++ b/src/OpenTok/OpenTok.php @@ -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); diff --git a/tests/OpenTokTest/OpenTokTest.php b/tests/OpenTokTest/OpenTokTest.php index 00bb6225..a014cdbf 100644 --- a/tests/OpenTokTest/OpenTokTest.php +++ b/tests/OpenTokTest/OpenTokTest.php @@ -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); @@ -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); @@ -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 diff --git a/tests/mock/v2/project/APIKEY/archive/ARCHIVEID/get b/tests/mock/v2/project/APIKEY/archive/ARCHIVEID/get index 70f6190b..d32ca376 100644 --- a/tests/mock/v2/project/APIKEY/archive/ARCHIVEID/get +++ b/tests/mock/v2/project/APIKEY/archive/ARCHIVEID/get @@ -3,6 +3,7 @@ "duration" : 199, "id" : "063e72a4-64b4-43c8-9da5-eca071daab89", "name" : "showtime", + "maxBitrate": 2000000, "partnerId" : 854511, "reason" : "", "sessionId" : "2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-", diff --git a/tests/mock/v2/project/APIKEY/archive/session b/tests/mock/v2/project/APIKEY/archive/session index 46ae4b13..ddc5572a 100644 --- a/tests/mock/v2/project/APIKEY/archive/session +++ b/tests/mock/v2/project/APIKEY/archive/session @@ -3,6 +3,7 @@ "duration" : 0, "id" : "832641bf-5dbf-41a1-ad94-fea213e59a92", "name" : null, + "maxBitrate": 2000000, "partnerId" : 12345678, "reason" : "", "sessionId" : "2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-",