Skip to content

Commit 2b9177c

Browse files
authored
Merge branch 'dev' into feature/audio-only-broadcast
2 parents 163e0fc + 9fefacd commit 2b9177c

File tree

4 files changed

+171
-2
lines changed

4 files changed

+171
-2
lines changed

src/OpenTok/Archive.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,17 @@ class Archive
105105
private $client;
106106
/** @internal */
107107
private $multiArchiveTag;
108-
108+
/**
109+
* @var mixed|null
110+
*/
111+
private const PERMITTED_AUTO_RESOLUTIONS = [
112+
'480x640',
113+
"640x480",
114+
"720x1280",
115+
"1280x720",
116+
"1080x1920",
117+
"1920x1080"
118+
];
109119

110120
/** @internal */
111121
public function __construct($archiveData, $options = array())
@@ -141,6 +151,11 @@ public function __construct($archiveData, $options = array())
141151
}
142152
}
143153

154+
public static function getPermittedResolutions()
155+
{
156+
return self::PERMITTED_AUTO_RESOLUTIONS;
157+
}
158+
144159
/** @internal */
145160
public function __get($name)
146161
{

src/OpenTok/OpenTok.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ public function generateToken($sessionId, $options = array())
173173
* <a href="https://tokbox.com/developer/guides/end-to-end-encryption">end-to-end encryption</a>
174174
* for a routed session.</li>
175175
*
176+
* <li><code>archiveName</code> (String) &mdash; Name of the archives in auto archived sessions</li>
177+
*
178+
* <li><code>archiveResolution</code> (Enum) &mdash; Resolution of the archives in
179+
* auto archived sessions. Can be one of "480x640", "640x480", "720x1280", "1280x720", "1080x1920", "1920x1080"</li>
180+
*
176181
* <li><code>'location'</code> (String) &mdash; An IP address that the OpenTok servers
177182
* will use to situate the session in its global network. If you do not set a location hint,
178183
* the OpenTok servers will be based on the first client connecting to the session.</li>
@@ -250,14 +255,34 @@ public function createSession($options = array())
250255
'archiveMode' => ArchiveMode::MANUAL,
251256
'location' => null,
252257
'e2ee' => 'false',
258+
'archiveName' => null,
259+
'archiveResolution' => null
253260
);
254261

262+
// Have to hack this because the default system in these classes needs total refactor
263+
$resolvedArchiveMode = array_merge($defaults, array_intersect_key($options, $defaults));
264+
265+
if ($resolvedArchiveMode['archiveMode'] === ArchiveMode::ALWAYS) {
266+
$defaults['archiveResolution'] = '640x480';
267+
}
268+
255269
$options = array_merge($defaults, array_intersect_key($options, $defaults));
270+
271+
// Have to hack this because the default system in these classes needs total refactor
272+
if ($options['archiveName'] === null) {
273+
unset($options['archiveName']);
274+
}
275+
276+
if ($options['archiveResolution'] === null) {
277+
unset($options['archiveResolution']);
278+
}
279+
256280
list($mediaMode, $archiveMode, $location, $e2ee) = array_values($options);
257281

258282
// validate arguments
259283
Validators::validateMediaMode($mediaMode);
260284
Validators::validateArchiveMode($archiveMode);
285+
Validators::validateAutoArchiveMode($archiveMode, $options);
261286
Validators::validateLocation($location);
262287

263288
// make API call
@@ -1012,7 +1037,7 @@ public function getStream($sessionId, $streamId)
10121037
}
10131038

10141039
/**
1015-
* Returns a StreamList Object for the given session ID.
1040+
* Returns a StreamList Object for the given session ID.
10161041
*
10171042
* @param String $sessionId The session ID.
10181043
*

src/OpenTok/Util/Validators.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenTok\Util;
44

5+
use OpenTok\Archive;
56
use OpenTok\Util\Client;
67
use OpenTok\Layout;
78
use OpenTok\Role;
@@ -266,6 +267,7 @@ public static function validateMediaMode($mediaMode)
266267
);
267268
}
268269
}
270+
269271
public static function validateArchiveMode($archiveMode)
270272
{
271273
if (!ArchiveMode::isValidValue($archiveMode)) {
@@ -274,6 +276,22 @@ public static function validateArchiveMode($archiveMode)
274276
);
275277
}
276278
}
279+
280+
public static function validateAutoArchiveMode($archiveMode, $options)
281+
{
282+
if ($archiveMode === ArchiveMode::MANUAL) {
283+
foreach (['archiveName', 'archiveResolution'] as $key) {
284+
if (array_key_exists($key, $options)) {
285+
throw new InvalidArgumentException('Cannot set ' . $key . ' when Archive mode is Manual');
286+
}
287+
}
288+
}
289+
290+
if (array_key_exists('archiveResolution', $options)) {
291+
self::validateAutoArchiveResolution($options['archiveResolution']);
292+
}
293+
}
294+
277295
public static function validateLocation($location)
278296
{
279297
if ($location != null && !filter_var($location, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
@@ -394,6 +412,13 @@ public static function validateWebsocketOptions(array $websocketOptions)
394412
}
395413
}
396414

415+
public static function validateAutoArchiveResolution($archiveResolution)
416+
{
417+
if (! in_array($archiveResolution, Archive::getPermittedResolutions(), true)) {
418+
throw new InvalidArgumentException($archiveResolution . ' is not a valid resolution');
419+
}
420+
}
421+
397422
public static function validateLayoutClassListItem($layoutClassList)
398423
{
399424
if (!is_string($layoutClassList['id'])) {

tests/OpenTokTest/OpenTokTest.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,110 @@ public function testCreatesDefaultSession(): void
232232
);
233233
}
234234

235+
public function testCanStartAutoSessionWithArchiveNameAndResolution(): void
236+
{
237+
// Arrange
238+
$this->setupOTWithMocks([[
239+
'code' => 200,
240+
'headers' => [
241+
'Content-Type' => 'text/xml'
242+
],
243+
'path' => 'session/create/alwaysarchived'
244+
]]);
245+
246+
$options = [
247+
'archiveMode' => ArchiveMode::ALWAYS,
248+
'archiveName' => 'testAutoArchives',
249+
'archiveResolution' => '640x480'
250+
];
251+
252+
// Act
253+
$session = $this->opentok->createSession($options);
254+
255+
// Assert
256+
$this->assertCount(1, $this->historyContainer);
257+
258+
$request = $this->historyContainer[0]['request'];
259+
$this->assertEquals('POST', strtoupper($request->getMethod()));
260+
$this->assertEquals('/session/create', $request->getUri()->getPath());
261+
$this->assertEquals('api.opentok.com', $request->getUri()->getHost());
262+
$this->assertEquals('https', $request->getUri()->getScheme());
263+
264+
$e2ee = $this->getPostField($request, 'e2ee');
265+
$this->assertEquals('false', $e2ee);
266+
267+
$this->assertEquals('always', $this->getPostField($request, 'archiveMode'));
268+
$this->assertEquals('testAutoArchives', $this->getPostField($request, 'archiveName'));
269+
$this->assertEquals('640x480', $this->getPostField($request, 'archiveResolution'));
270+
271+
272+
$this->assertInstanceOf('OpenTok\Session', $session);
273+
}
274+
275+
public function testCannotStartSessionWithArchiveNameInManualMode(): void
276+
{
277+
$this->expectException(InvalidArgumentException::class);
278+
279+
// Arrange
280+
$this->setupOTWithMocks([[
281+
'code' => 200,
282+
'headers' => [
283+
'Content-Type' => 'text/xml'
284+
],
285+
'path' => 'session/create/relayed'
286+
]]);
287+
288+
$options = [
289+
'archiveName' => 'testAutoArchives',
290+
];
291+
292+
// Act
293+
$session = $this->opentok->createSession($options);
294+
}
295+
296+
public function testCannotStartSessionWithArchiveResolutionInManualMode(): void
297+
{
298+
$this->expectException(InvalidArgumentException::class);
299+
300+
// Arrange
301+
$this->setupOTWithMocks([[
302+
'code' => 200,
303+
'headers' => [
304+
'Content-Type' => 'text/xml'
305+
],
306+
'path' => 'session/create/relayed'
307+
]]);
308+
309+
$options = [
310+
'archiveResolution' => '640x480'
311+
];
312+
313+
// Act
314+
$session = $this->opentok->createSession($options);
315+
}
316+
317+
public function testCannotStartSessionWithInvalidResolutionInAutoArchive(): void
318+
{
319+
$this->expectException(InvalidArgumentException::class);
320+
321+
// Arrange
322+
$this->setupOTWithMocks([[
323+
'code' => 200,
324+
'headers' => [
325+
'Content-Type' => 'text/xml'
326+
],
327+
'path' => 'session/create/relayed'
328+
]]);
329+
330+
$options = [
331+
'archiveMode' => ArchiveMode::ALWAYS,
332+
'archiveResolution' => '680x440',
333+
];
334+
335+
// Act
336+
$session = $this->opentok->createSession($options);
337+
}
338+
235339
public function testCreatesE2EESession(): void
236340
{
237341
// Arrange

0 commit comments

Comments
 (0)