Skip to content

Commit 1738a57

Browse files
author
Manik Sachdeva
authored
Merge pull request #204 from opentok/dev
adding resolution parameter for startArchive
2 parents 80cdff3 + 50698aa commit 1738a57

File tree

9 files changed

+164
-28
lines changed

9 files changed

+164
-28
lines changed

DEVELOPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ In order to create a release, the following should be completed in order.
3838
"-alpha.1" in each file except samples and documentation. Then make another commit with the
3939
message "Begin development on next version".
4040
1. Push the changes to the source repository: `git push origin master; git push --tags origin`s
41-
1. Generate a phar archive for distribution using [Box](http://box-project.org/): `box build`. Be sure that the
41+
1. Generate a phar archive for distribution using [Box](https://github.com/box-project/box2): `box build`. Be sure that the
4242
dependencies in the `/vendor` directory are current before building. Upload it to the GitHub Release. Add
4343
release notes with a description of changes and fixes.
4444

src/OpenTok/Archive.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
* For archives with the status "stopped" or "failed", this string describes the reason
4242
* the archive stopped (such as "maximum duration exceeded") or failed.
4343
*
44+
* @property string $resolution
45+
* The resolution of the archive.
46+
*
4447
* @property string $sessionId
4548
* The session ID of the OpenTok session associated with this archive.
4649
*
@@ -133,6 +136,7 @@ public function __get($name)
133136
case 'hasVideo':
134137
case 'hasAudio':
135138
case 'outputMode':
139+
case 'resolution':
136140
return $this->data[$name];
137141
break;
138142
default:

src/OpenTok/OpenTok.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,19 @@ public function startArchive($sessionId, $options=array())
292292
'name' => null,
293293
'hasVideo' => true,
294294
'hasAudio' => true,
295-
'outputMode' => OutputMode::COMPOSED
295+
'outputMode' => OutputMode::COMPOSED,
296+
'resolution' => '640x480'
296297
);
297298
$options = array_merge($defaults, array_intersect_key($options, $defaults));
298-
list($name, $hasVideo, $hasAudio, $outputMode) = array_values($options);
299+
list($name, $hasVideo, $hasAudio, $outputMode, $resolution) = array_values($options);
299300

300301
// validate arguments
301302
Validators::validateSessionId($sessionId);
302303
Validators::validateArchiveName($name);
303304
Validators::validateArchiveHasVideo($hasVideo);
304305
Validators::validateArchiveHasAudio($hasAudio);
305306
Validators::validateArchiveOutputMode($outputMode);
307+
Validators::validateArchiveResolution($resolution);
306308

307309
// make API call
308310
$archiveData = $this->client->startArchive($sessionId, $options);

src/OpenTok/Util/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
// TODO: build this dynamically
3030
/** @internal */
31-
define('OPENTOK_SDK_VERSION', '4.0.0');
31+
define('OPENTOK_SDK_VERSION', '4.0.1-alpha.1');
3232
/** @internal */
3333
define('OPENTOK_SDK_USER_AGENT', 'OpenTok-PHP-SDK/' . OPENTOK_SDK_VERSION);
3434

src/OpenTok/Util/Validators.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ public static function validateArchiveOutputMode($outputMode)
145145
throw new InvalidArgumentException('Unknown output mode: '.print_r($outputMode, true));
146146
}
147147
}
148+
public static function validateArchiveResolution($resolution)
149+
{
150+
if (!(is_string($resolution))) {
151+
throw new InvalidArgumentException('The resolution must be a string: '.print_r($resolution, true));
152+
}
153+
}
148154
public static function validateArchiveId($archiveId)
149155
{
150156
if ( !is_string($archiveId) || preg_match(self::$guidRegEx, $archiveId) ) {

tests/OpenTok/ArchiveTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public function setupArchives()
4343
'url' => null,
4444
'hasVideo' => false,
4545
'hasAudio' => true,
46-
'outputMode' => 'composed'
46+
'outputMode' => 'composed',
47+
'resolution' => '640x480'
4748
);
4849

4950
$this->archive = new Archive($this->archiveData, array(
@@ -118,6 +119,7 @@ public function testReadsProperties()
118119
$this->assertEquals($this->archiveData['hasVideo'], $this->archive->hasVideo);
119120
$this->assertEquals($this->archiveData['hasAudio'], $this->archive->hasAudio);
120121
$this->assertEquals($this->archiveData['outputMode'], $this->archive->outputMode);
122+
$this->assertEquals($this->archiveData['resolution'], $this->archive->resolution);
121123
}
122124

123125
public function testStopsArchive()
@@ -154,7 +156,7 @@ public function testStopsArchive()
154156
// TODO: test the dynamically built User Agent string
155157
$userAgent = $request->getHeaderLine('User-Agent');
156158
$this->assertNotEmpty($userAgent);
157-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
159+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
158160

159161
// TODO: test the properties of the actual archive object
160162
$this->assertEquals('stopped', $this->archive->status);
@@ -193,7 +195,7 @@ public function testDeletesArchive()
193195
// TODO: test the dynamically built User Agent string
194196
$userAgent = $request->getHeaderLine('User-Agent');
195197
$this->assertNotEmpty($userAgent);
196-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
198+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
197199

198200
$this->assertTrue($success);
199201
// TODO: assert that all properties of the archive object were cleared

tests/OpenTok/OpenTokTest.php

Lines changed: 117 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function testCreatesDefaultSession()
124124
// TODO: test the dynamically built User Agent string
125125
$userAgent = $request->getHeaderLine('User-Agent');
126126
$this->assertNotEmpty($userAgent);
127-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
127+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
128128

129129
$p2p_preference = $this->getPostField($request, 'p2p.preference');
130130
$this->assertEquals('enabled', $p2p_preference);
@@ -184,7 +184,7 @@ public function testCreatesMediaRoutedAndLocationSession()
184184
// TODO: test the dynamically built User Agent string
185185
$userAgent = $request->getHeaderLine('User-Agent');
186186
$this->assertNotEmpty($userAgent);
187-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
187+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
188188

189189
$location = $this->getPostField($request, 'location');
190190
$this->assertEquals('12.34.56.78', $location);
@@ -232,7 +232,7 @@ public function testCreatesMediaRelayedSession()
232232
// TODO: test the dynamically built User Agent string
233233
$userAgent = $request->getHeaderLine('User-Agent');
234234
$this->assertNotEmpty($userAgent);
235-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
235+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
236236

237237
$p2p_preference = $this->getPostField($request, 'p2p.preference');
238238
$this->assertEquals('enabled', $p2p_preference);
@@ -277,7 +277,7 @@ public function testCreatesAutoArchivedSession()
277277
// TODO: test the dynamically built User Agent string
278278
$userAgent = $request->getHeaderLine('User-Agent');
279279
$this->assertNotEmpty($userAgent);
280-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
280+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
281281

282282
$archiveMode = $this->getPostField($request, 'archiveMode');
283283
$this->assertEquals('always', $archiveMode);
@@ -483,7 +483,7 @@ public function testStartsArchive()
483483
// TODO: test the dynamically built User Agent string
484484
$userAgent = $request->getHeaderLine('User-Agent');
485485
$this->assertNotEmpty($userAgent);
486-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
486+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
487487

488488
$this->assertInstanceOf('OpenTok\Archive', $archive);
489489
$this->assertEquals(0, $archive->duration);
@@ -533,7 +533,7 @@ public function testStartsArchiveNamed()
533533
// TODO: test the dynamically built User Agent string
534534
$userAgent = $request->getHeaderLine('User-Agent');
535535
$this->assertNotEmpty($userAgent);
536-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
536+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
537537

538538
$body = json_decode($request->getBody());
539539
$this->assertEquals($sessionId, $body->sessionId);
@@ -581,7 +581,7 @@ public function testStartsArchiveNamedDeprecated()
581581
// TODO: test the dynamically built User Agent string
582582
$userAgent = $request->getHeaderLine('User-Agent');
583583
$this->assertNotEmpty($userAgent);
584-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
584+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
585585

586586
$body = json_decode($request->getBody());
587587
$this->assertEquals($sessionId, $body->sessionId);
@@ -628,7 +628,7 @@ public function testStartsArchiveAudioOnly()
628628
// TODO: test the dynamically built User Agent string
629629
$userAgent = $request->getHeaderLine('User-Agent');
630630
$this->assertNotEmpty($userAgent);
631-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
631+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
632632

633633
$body = json_decode($request->getBody());
634634
$this->assertEquals($sessionId, $body->sessionId);
@@ -678,7 +678,7 @@ public function testStartsArchiveIndividualOutput()
678678
// TODO: test the dynamically built User Agent string
679679
$userAgent = $request->getHeaderLine('User-Agent');
680680
$this->assertNotEmpty($userAgent);
681-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
681+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
682682

683683
$body = json_decode($request->getBody());
684684
$this->assertEquals($sessionId, $body->sessionId);
@@ -688,6 +688,102 @@ public function testStartsArchiveIndividualOutput()
688688
$this->assertEquals(OutputMode::INDIVIDUAL, $archive->outputMode);
689689
}
690690

691+
public function testStartsArchiveResolutionSD()
692+
{
693+
// Arrange
694+
$this->setupOTWithMocks([[
695+
'code' => 200,
696+
'headers' => [
697+
'Content-Type' => 'application/json'
698+
],
699+
'path' => 'v2/project/APIKEY/archive/session_resolution-sd'
700+
]]);
701+
702+
// This sessionId was generated using a different apiKey, but this method doesn't do any
703+
// decoding to check, so its fine.
704+
$sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-';
705+
706+
// Act
707+
$archive = $this->opentok->startArchive($sessionId, array(
708+
'resolution' => '640x480'
709+
));
710+
711+
// Assert
712+
$this->assertCount(1, $this->historyContainer);
713+
714+
$request = $this->historyContainer[0]['request'];
715+
$this->assertEquals('POST', strtoupper($request->getMethod()));
716+
$this->assertEquals('/v2/project/'.$this->API_KEY.'/archive', $request->getUri()->getPath());
717+
$this->assertEquals('api.opentok.com', $request->getUri()->getHost());
718+
$this->assertEquals('https', $request->getUri()->getScheme());
719+
720+
$contentType = $request->getHeaderLine('Content-Type');
721+
$this->assertNotEmpty($contentType);
722+
$this->assertEquals('application/json', $contentType);
723+
724+
$authString = $request->getHeaderLine('X-OPENTOK-AUTH');
725+
$this->assertEquals(true, TestHelpers::validateOpenTokAuthHeader($this->API_KEY, $this->API_SECRET, $authString));
726+
727+
// TODO: test the dynamically built User Agent string
728+
$userAgent = $request->getHeaderLine('User-Agent');
729+
$this->assertNotEmpty($userAgent);
730+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
731+
732+
$body = json_decode($request->getBody());
733+
$this->assertEquals($sessionId, $body->sessionId);
734+
$this->assertEquals('640x480', $body->resolution);
735+
736+
$this->assertInstanceOf('OpenTok\Archive', $archive);
737+
}
738+
739+
public function testStartsArchiveResolutionHD()
740+
{
741+
// Arrange
742+
$this->setupOTWithMocks([[
743+
'code' => 200,
744+
'headers' => [
745+
'Content-Type' => 'application/json'
746+
],
747+
'path' => 'v2/project/APIKEY/archive/session_resolution-hd'
748+
]]);
749+
750+
// This sessionId was generated using a different apiKey, but this method doesn't do any
751+
// decoding to check, so its fine.
752+
$sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-';
753+
754+
// Act
755+
$archive = $this->opentok->startArchive($sessionId, array(
756+
'resolution' => '1280x720'
757+
));
758+
759+
// Assert
760+
$this->assertCount(1, $this->historyContainer);
761+
762+
$request = $this->historyContainer[0]['request'];
763+
$this->assertEquals('POST', strtoupper($request->getMethod()));
764+
$this->assertEquals('/v2/project/'.$this->API_KEY.'/archive', $request->getUri()->getPath());
765+
$this->assertEquals('api.opentok.com', $request->getUri()->getHost());
766+
$this->assertEquals('https', $request->getUri()->getScheme());
767+
768+
$contentType = $request->getHeaderLine('Content-Type');
769+
$this->assertNotEmpty($contentType);
770+
$this->assertEquals('application/json', $contentType);
771+
772+
$authString = $request->getHeaderLine('X-OPENTOK-AUTH');
773+
$this->assertEquals(true, TestHelpers::validateOpenTokAuthHeader($this->API_KEY, $this->API_SECRET, $authString));
774+
775+
// TODO: test the dynamically built User Agent string
776+
$userAgent = $request->getHeaderLine('User-Agent');
777+
$this->assertNotEmpty($userAgent);
778+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
779+
780+
$body = json_decode($request->getBody());
781+
$this->assertEquals($sessionId, $body->sessionId);
782+
$this->assertEquals('1280x720', $body->resolution);
783+
784+
$this->assertInstanceOf('OpenTok\Archive', $archive);
785+
}
786+
691787
public function testStopsArchive()
692788
{
693789
// Arrange
@@ -723,7 +819,7 @@ public function testStopsArchive()
723819
// TODO: test the dynamically built User Agent string
724820
$userAgent = $request->getHeaderLine('User-Agent');
725821
$this->assertNotEmpty($userAgent);
726-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
822+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
727823

728824
$this->assertInstanceOf('OpenTok\Archive', $archive);
729825
// TODO: test the properties of the actual archive object
@@ -762,7 +858,7 @@ public function testGetsArchive()
762858
// TODO: test the dynamically built User Agent string
763859
$userAgent = $request->getHeaderLine('User-Agent');
764860
$this->assertNotEmpty($userAgent);
765-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
861+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
766862

767863
$this->assertInstanceOf('OpenTok\Archive', $archive);
768864
// TODO: test the properties of the actual archive object
@@ -799,7 +895,7 @@ public function testDeletesArchive()
799895
// TODO: test the dynamically built User Agent string
800896
$userAgent = $request->getHeaderLine('User-Agent');
801897
$this->assertNotEmpty($userAgent);
802-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
898+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
803899

804900
$this->assertTrue($success);
805901
// TODO: test the properties of the actual archive object
@@ -834,7 +930,7 @@ public function testListsArchives()
834930
// TODO: test the dynamically built User Agent string
835931
$userAgent = $request->getHeaderLine('User-Agent');
836932
$this->assertNotEmpty($userAgent);
837-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
933+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
838934

839935
$this->assertInstanceOf('OpenTok\ArchiveList', $archiveList);
840936
// TODO: test the properties of the actual archiveList object and its contained archive
@@ -870,7 +966,7 @@ public function testListsArchivesWithOffsetAndCount()
870966
// TODO: test the dynamically built User Agent string
871967
$userAgent = $request->getHeaderLine('User-Agent');
872968
$this->assertNotEmpty($userAgent);
873-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
969+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
874970

875971
$this->assertInstanceOf('OpenTok\ArchiveList', $archiveList);
876972
$this->assertEquals(1, $archiveList->totalCount());
@@ -955,7 +1051,7 @@ public function testForceDisconnect()
9551051
// TODO: test the dynamically built User Agent string
9561052
$userAgent = $request->getHeaderLine('User-Agent');
9571053
$this->assertNotEmpty($userAgent);
958-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
1054+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
9591055

9601056
$this->assertTrue($success);
9611057
}
@@ -997,7 +1093,7 @@ public function testStartsBroadcast()
9971093
// TODO: test the dynamically built User Agent string
9981094
$userAgent = $request->getHeaderLine('User-Agent');
9991095
$this->assertNotEmpty($userAgent);
1000-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
1096+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
10011097

10021098
$this->assertInstanceOf('OpenTok\Broadcast', $broadcast);
10031099
$this->assertInternalType('string', $broadcast->id);
@@ -1042,7 +1138,7 @@ public function testStopsBroadcast()
10421138
// TODO: test the dynamically built User Agent string
10431139
$userAgent = $request->getHeaderLine('User-Agent');
10441140
$this->assertNotEmpty($userAgent);
1045-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
1141+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
10461142

10471143
$this->assertInstanceOf('OpenTok\Broadcast', $broadcast);
10481144
$this->assertTrue($broadcast->isStopped);
@@ -1079,7 +1175,7 @@ public function testGetsBroadcast()
10791175
// TODO: test the dynamically built User Agent string
10801176
$userAgent = $request->getHeaderLine('User-Agent');
10811177
$this->assertNotEmpty($userAgent);
1082-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
1178+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
10831179

10841180
$this->assertInstanceOf('OpenTok\Broadcast', $broadcast);
10851181
}
@@ -1123,7 +1219,7 @@ public function testUpdatesBroadcastLayoutWithPredefined()
11231219
// TODO: test the dynamically built User Agent string
11241220
$userAgent = $request->getHeaderLine('User-Agent');
11251221
$this->assertNotEmpty($userAgent);
1126-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
1222+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
11271223
}
11281224

11291225
public function testUpdatesBroadcastLayoutWithCustom()
@@ -1169,7 +1265,7 @@ public function testUpdatesBroadcastLayoutWithCustom()
11691265
// TODO: test the dynamically built User Agent string
11701266
$userAgent = $request->getHeaderLine('User-Agent');
11711267
$this->assertNotEmpty($userAgent);
1172-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
1268+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
11731269
}
11741270

11751271
public function testUpdatesStreamLayoutClassList()
@@ -1214,7 +1310,7 @@ public function testUpdatesStreamLayoutClassList()
12141310
// TODO: test the dynamically built User Agent string
12151311
$userAgent = $request->getHeaderLine('User-Agent');
12161312
$this->assertNotEmpty($userAgent);
1217-
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.0', $userAgent);
1313+
$this->assertStringStartsWith('OpenTok-PHP-SDK/4.0.1-alpha.1', $userAgent);
12181314
}
12191315

12201316

0 commit comments

Comments
 (0)