Skip to content

Commit 0c2ed6f

Browse files
author
Manik Sachdeva
authored
v4.1.1 (#207)
* fixes start archive for individual stream
1 parent cb67eaa commit 0c2ed6f

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ You can only archive sessions that use the OpenTok Media Router
120120
You can start the recording of an OpenTok Session using the `startArchive($sessionId, $name)` method
121121
of the `OpenTok\OpenTok` class. This will return an `OpenTok\Archive` instance. The parameter
122122
`$archiveOptions` is an optional array and is used to assign a name, whether to record audio and/or
123-
video, and the desired output mode for the Archive. Note that you can only start an
123+
video, the desired output mode for the Archive, and the desired resolution if applicable. Note that you can only start an
124124
Archive on a Session that has clients connected.
125125

126126
```php
@@ -130,18 +130,19 @@ $archive = $opentok->startArchive($sessionId);
130130

131131
// Create an archive using custom options
132132
$archiveOptions = array(
133-
'name' => 'Important Presentation', // default: null
134-
'hasAudio' => true, // default: true
135-
'hasVideo' => true, // default: true
136-
'outputMode' => OutputMode::INDIVIDUAL // default: OutputMode::COMPOSED
133+
'name' => 'Important Presentation', // default: null
134+
'hasAudio' => true, // default: true
135+
'hasVideo' => true, // default: true
136+
'outputMode' => OutputMode::COMPOSED, // default: OutputMode::COMPOSED
137+
'resolution' => '1280x720' // default: '640x480'
137138
);
138139
$archive = $opentok->startArchive($sessionId, $archiveOptions);
139140

140141
// Store this archiveId in the database for later use
141142
$archiveId = $archive->id;
142143
```
143144

144-
Setting the output mode to `OutputMode::INDIVIDUAL` setting causes each stream in the archive to be recorded to its own individual file. The `OutputMode::COMPOSED` setting (the default) causes all streams in the archive to be recorded to a single (composed) file.
145+
If you set the `outputMode` option to `OutputMode::INDIVIDUAL`, it causes each stream in the archive to be recorded to its own individual file. Please note that you cannot specify the resolution when you set the `outputMode` option to `OutputMode::INDIVIDUAL`. The `OutputMode::COMPOSED` setting (the default) causes all streams in the archive to be recorded to a single (composed) file.
145146

146147
You can stop the recording of a started Archive using the `stopArchive($archiveId)` method of the
147148
`OpenTok\OpenTok` object. You can also do this using the `stop()` method of the

src/OpenTok/OpenTok.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,26 +286,36 @@ public function startArchive($sessionId, $options=array())
286286
if (!is_array($options)) {
287287
$options = array('name' => $options);
288288
}
289-
289+
290290
// unpack optional arguments (merging with default values) into named variables
291291
$defaults = array(
292292
'name' => null,
293293
'hasVideo' => true,
294294
'hasAudio' => true,
295295
'outputMode' => OutputMode::COMPOSED,
296-
'resolution' => '640x480'
296+
'resolution' => null,
297297
);
298298
$options = array_merge($defaults, array_intersect_key($options, $defaults));
299299
list($name, $hasVideo, $hasAudio, $outputMode, $resolution) = array_values($options);
300-
301300
// validate arguments
302301
Validators::validateSessionId($sessionId);
303302
Validators::validateArchiveName($name);
304303
Validators::validateArchiveHasVideo($hasVideo);
305304
Validators::validateArchiveHasAudio($hasAudio);
306305
Validators::validateArchiveOutputMode($outputMode);
307-
Validators::validateArchiveResolution($resolution);
308306

307+
if ((is_null($resolution) || empty($resolution)) && $outputMode === OutputMode::COMPOSED) {
308+
$options['resolution'] = "640x480";
309+
} else if((is_null($resolution) || empty($resolution)) && $outputMode === OutputMode::INDIVIDUAL) {
310+
unset($options['resolution']);
311+
} else if(!empty($resolution) && $outputMode === OutputMode::INDIVIDUAL) {
312+
$errorMessage = "Resolution can't be specified for Individual Archives";
313+
throw new UnexpectedValueException($errorMessage);
314+
} else if(!empty($resolution) && $outputMode === OutputMode::COMPOSED && !is_string($resolution)) {
315+
$errorMessage = "Resolution must be a valid string";
316+
throw new UnexpectedValueException($errorMessage);
317+
}
318+
// we don't validate the actual resolution so if we add resolutions, we don't artificially block functionality
309319
// make API call
310320
$archiveData = $this->client->startArchive($sessionId, $options);
311321

src/OpenTok/Util/Validators.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ 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-
}
154148
public static function validateArchiveId($archiveId)
155149
{
156150
if ( !is_string($archiveId) || preg_match(self::$guidRegEx, $archiveId) ) {

0 commit comments

Comments
 (0)