Skip to content

Commit a4dd757

Browse files
authored
Merge pull request #316 from opentok/dev
Release Candidate
2 parents 97028cc + 2490450 commit a4dd757

File tree

15 files changed

+692
-51
lines changed

15 files changed

+692
-51
lines changed

src/OpenTok/Archive.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@
4141
* the archive stopped (such as "maximum duration exceeded") or failed.
4242
*
4343
* @property string $resolution
44-
* The resolution of the archive.
44+
* The resolution of the archive, either "640x480" (SD landscape, the default), "1280x720" (HD landscape),
45+
* "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280" (HD portrait), or "1080x1920" (FHD portrait).
46+
* You may want to use a portrait aspect ratio for archives that include video streams from mobile devices (which often use the portrait aspect ratio).
4547
*
4648
* @property string $sessionId
4749
* The session ID of the OpenTok session associated with this archive.
4850
*
51+
* @property string $multiArchiveTag
52+
* Whether Multiple Archive is switched on, which will be a unique string for each simultaneous archive of an ongoing session.
53+
* See https://tokbox.com/developer/guides/archiving/#simultaneous-archives for more information.
54+
*
4955
* @property string $size
5056
* The size of the MP4 file. For archives that have not been generated, this value is set to 0.
5157
*
@@ -97,6 +103,9 @@ class Archive
97103
private $isDeleted;
98104
/** @internal */
99105
private $client;
106+
/** @internal */
107+
private $multiArchiveTag;
108+
100109

101110
/** @internal */
102111
public function __construct($archiveData, $options = array())
@@ -118,6 +127,9 @@ public function __construct($archiveData, $options = array())
118127
Validators::validateHasStreamMode($streamMode);
119128

120129
$this->data = $archiveData;
130+
if (isset($this->data['multiArchiveTag'])) {
131+
$this->multiArchiveTag = $this->data['multiArchiveTag'];
132+
}
121133

122134
$this->client = isset($client) ? $client : new Client();
123135
if (!$this->client->isConfigured()) {
@@ -152,6 +164,8 @@ public function __get($name)
152164
case 'resolution':
153165
case 'streamMode':
154166
return $this->data[$name];
167+
case 'multiArchiveTag':
168+
return $this->multiArchiveTag;
155169
default:
156170
return null;
157171
}

src/OpenTok/Broadcast.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
* @property boolean $isStopped
3636
* Whether the broadcast is stopped (true) or in progress (false).
3737
*
38+
* @property string $multiBroadcastTag
39+
* Whether Multiple Broadcast is switched on, which will be a unique string for each simultaneous broadcast of an ongoing session.
40+
* See https://tokbox.com/developer/guides/archiving/#simultaneous-archives for more information.
41+
*
3842
* @property boolean $isHls
3943
* Whether the broadcast supports HLS.
4044
*
@@ -44,6 +48,11 @@
4448
* @property boolean $isLowLatency
4549
* Whether the broadcast supports low-latency mode for the HLS stream.
4650
*
51+
* @property string $resolution
52+
* The resolution of the archive, either "640x480" (SD landscape, the default), "1280x720" (HD landscape),
53+
* "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280" (HD portrait), or "1080x1920" (FHD portrait).
54+
* You may want to use a portrait aspect ratio for archives that include video streams from mobile devices (which often use the portrait aspect ratio).
55+
*
4756
* @property string $streamMode
4857
* Whether streams included in the broadcast are selected automatically (<code>StreamMode.AUTO</code>)
4958
* or manually (<code>StreamMode.MANUAL</code>). When streams are selected automatically (<code>StreamMode.AUTO</code>),
@@ -69,8 +78,11 @@ class Broadcast
6978
private $isLowLatency;
7079
/** @ignore */
7180
private $isDvr;
72-
7381
/** @ignore */
82+
private $multiBroadcastTag;
83+
/** @ignore */
84+
private $resolution;
85+
7486
public function __construct($broadcastData, $options = array())
7587
{
7688
// unpack optional arguments (merging with default values) into named variables
@@ -85,7 +97,7 @@ public function __construct($broadcastData, $options = array())
8597
'streamMode' => StreamMode::AUTO,
8698
'isHls' => true,
8799
'isLowLatency' => false,
88-
'isDvr' => false
100+
'isDvr' => false,
89101
);
90102
$options = array_merge($defaults, array_intersect_key($options, $defaults));
91103
list($apiKey, $apiSecret, $apiUrl, $client, $isStopped, $streamMode) = array_values($options);
@@ -97,7 +109,12 @@ public function __construct($broadcastData, $options = array())
97109

98110
$this->data = $broadcastData;
99111

112+
if (isset($this->data['multiBroadcastTag'])) {
113+
$this->multiBroadcastTag = $this->data['multiBroadcastTag'];
114+
}
115+
100116
$this->isStopped = $isStopped;
117+
$this->resolution = $this->data['resolution'];
101118
$this->isHls = isset($this->data['settings']['hls']);
102119
$this->isLowLatency = $this->data['settings']['hls']['lowLatency'] ?? false;
103120
$this->isDvr = $this->data['settings']['hls']['dvr'] ?? false;
@@ -124,9 +141,10 @@ public function __get($name)
124141
case 'broadcastUrls':
125142
case 'status':
126143
case 'maxDuration':
127-
case 'resolution':
128144
case 'streamMode':
129145
return $this->data[$name];
146+
case 'resolution':
147+
return $this->resolution;
130148
case 'hlsUrl':
131149
return $this->data['broadcastUrls']['hls'];
132150
case 'isStopped':
@@ -137,6 +155,8 @@ public function __get($name)
137155
return $this->isLowLatency;
138156
case 'isDvr':
139157
return $this->isDvr;
158+
case 'multiBroadcastTag':
159+
return $this->multiBroadcastTag;
140160
default:
141161
return null;
142162
}

src/OpenTok/OpenTok.php

100755100644
Lines changed: 148 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,114 @@ public function createSession($options = array())
255255
));
256256
}
257257

258+
/**
259+
* Starts an Experience Composer renderer for an OpenTok session.
260+
* For more information, see the
261+
* <a href="https://tokbox.com/developer/guides/experience-composer">Experience Composer
262+
* developer guide</a>.
263+
*
264+
* @param $sessionId (string) The session ID of the OpenTok session that will include the Experience Composer stream.
265+
*
266+
* @param $token (string) A valid OpenTok token with a Publisher role and (optionally) connection data to be associated with the output stream.
267+
*
268+
* @param $url (string) A publicly reachable URL controlled by the customer and capable of generating the content to be rendered without user intervention.
269+
* The minimum length of the URL is 15 characters and the maximum length is 2048 characters.
270+
*
271+
* @param $maxDuration (int) (optional) The maximum time allowed for the Experience Composer, in seconds. After this time, it is stopped
272+
* automatically, if it is still running. The maximum value is 36000 (10 hours), the minimum value is 60 (1 minute), and the default value is 7200 (2 hours).
273+
* When the Experience Composer ends, its stream is unpublished and an event is posted to the callback URL, if configured in the Account Portal.
274+
*
275+
* @param $resolution (string) (optional) The resolution of the Experience Composer, either "640x480" (SD landscape), "480x640" (SD portrait), "1280x720" (HD landscape),
276+
* "720x1280" (HD portrait), "1920x1080" (FHD landscape), or "1080x1920" (FHD portrait). By default, this resolution is "1280x720" (HD landscape, the default).
277+
*
278+
* @param $properties (array) (optional) The initial configuration of Publisher properties for the composed output stream.
279+
* <ul>
280+
* <li><code>name</code> (String) (optional) &mdash; Serves as the name of the composed output stream which is published to the session. The name must have a minimum length of 1 and
281+
* a maximum length of 200.
282+
* </li>
283+
* </ul>
284+
*
285+
* @return \OpenTok\Render The render object, which includes properties defining the render, including the render ID.
286+
*/
287+
public function startRender(
288+
$sessionId,
289+
$token,
290+
$url,
291+
$maxDuration,
292+
$resolution,
293+
$properties
294+
): Render {
295+
$arguments = [
296+
'sessionId' => $sessionId,
297+
'token' => $token,
298+
'url' => $url,
299+
'maxDuration' => $maxDuration,
300+
'resolution' => $resolution,
301+
'properties' => $properties
302+
];
303+
304+
$defaults = [
305+
'maxDuration' => 1800,
306+
'resolution' => '1280x720',
307+
];
308+
309+
$payload = array_merge($defaults, $arguments);
310+
Validators::validateSessionId($payload['sessionId']);
311+
312+
$render = $this->client->startRender($payload);
313+
314+
return new Render($render);
315+
}
316+
317+
/**
318+
* Returns a list of Experience Composer renderers for an OpenTok project.
319+
*
320+
* @param int $offset
321+
* @param int $count
322+
*
323+
* @return mixed
324+
*/
325+
public function listRenders(int $offset = 0, int $count = 50)
326+
{
327+
$queryPayload = [
328+
'offset' => $offset,
329+
'count' => $count
330+
];
331+
return $this->client->listRenders($queryPayload);
332+
}
333+
334+
/**
335+
* Stops an existing render.
336+
*
337+
* @param $renderId
338+
*
339+
* @return mixed
340+
*/
341+
public function stopRender($renderId)
342+
{
343+
return $this->client->stopRender($renderId);
344+
}
345+
346+
/**
347+
* Fetch an existing render to view status. Status can be one of:
348+
* <ul>
349+
* <li><code>starting</code> &mdash; The Vonage Video API platform is in the process of connecting to the remote application at the URL provided. This is the initial state.</li>
350+
* <li><code>started</code> &mdash; The Vonage Video API platform has succesfully connected to the remote application server, and is republishing that media into the Vonage Video API platform.</li>
351+
* <li><code>stopped</code> &mdash; The Render has stopped.</li>
352+
* <li><code>failed</code> &mdash; An error occurred and the Render could not proceed. It may occur at startup if the opentok server cannot connect to the remote application server or republish the stream. It may also occur at point during the rendering process due to some error in the Vonage Video API platform.</li>
353+
* </ul>
354+
*
355+
* @param $renderId
356+
*
357+
* @return Render
358+
*/
359+
public function getRender($renderId): Render
360+
{
361+
$renderPayload = $this->client->getRender($renderId);
362+
363+
return new Render($renderPayload);
364+
}
365+
258366
/**
259367
* Starts archiving an OpenTok session.
260368
* <p>
@@ -302,10 +410,25 @@ public function createSession($options = array())
302410
* <code>hasVideo</code> to false, the call to the <code>startArchive()</code> method results
303411
* in an error.</li>
304412
*
413+
* <li><code>'multiArchiveTag'</code> (String) (Optional) &mdash; Set this to support recording multiple archives
414+
* for the same session simultaneously. Set this to a unique string for each simultaneous archive of an ongoing
415+
* session. You must also set this option when manually starting an archive
416+
* that is {https://tokbox.com/developer/guides/archiving/#automatic automatically archived}.
417+
* Note that the `multiArchiveTag` value is not included in the response for the methods to
418+
* {https://tokbox.com/developer/rest/#listing_archives list archives} and
419+
* {https://tokbox.com/developer/rest/#retrieve_archive_info retrieve archive information}.
420+
* If you do not specify a unique `multiArchiveTag`, you can only record one archive at a time for a given session.
421+
* {https://tokbox.com/developer/guides/archiving/#simultaneous-archives See Simultaneous archives}.</li>
422+
*
305423
* <li><code>'outputMode'</code> (OutputMode) &mdash; Whether all streams in the
306424
* archive are recorded to a single file (<code>OutputMode::COMPOSED</code>, the default)
307425
* or to individual files (<code>OutputMode::INDIVIDUAL</code>).</li>
308426
*
427+
* <li><code>'resolution'</code> (String) &mdash; The resolution of the archive, either "640x480" (SD landscape,
428+
* the default), "1280x720" (HD landscape), "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280"
429+
* (HD portrait), or "1080x1920" (FHD portrait). This property only applies to composed archives. If you set
430+
* this property and set the outputMode property to "individual", a call to the method
431+
* results in an error.</li>
309432
* </ul>
310433
*
311434
* @return Archive The Archive object, which includes properties defining the archive, including
@@ -329,13 +452,18 @@ public function startArchive(string $sessionId, $options = []): Archive
329452
'hasAudio' => true,
330453
'outputMode' => OutputMode::COMPOSED,
331454
'resolution' => null,
332-
'streamMode' => StreamMode::AUTO
455+
'streamMode' => StreamMode::AUTO,
333456
);
334457
$options = array_merge($defaults, array_intersect_key($options, $defaults));
335458
list($name, $hasVideo, $hasAudio, $outputMode, $resolution, $streamMode) = array_values($options);
336-
// validate arguments
459+
337460
Validators::validateSessionId($sessionId);
338461
Validators::validateArchiveName($name);
462+
463+
if ($resolution) {
464+
Validators::validateResolution($resolution);
465+
}
466+
339467
Validators::validateArchiveHasVideo($hasVideo);
340468
Validators::validateArchiveHasAudio($hasAudio);
341469
Validators::validateArchiveOutputMode($outputMode);
@@ -352,8 +480,7 @@ public function startArchive(string $sessionId, $options = []): Archive
352480
$errorMessage = "Resolution must be a valid string";
353481
throw new UnexpectedValueException($errorMessage);
354482
}
355-
// we don't validate the actual resolution so if we add resolutions, we don't artificially block functionality
356-
// make API call
483+
357484
$archiveData = $this->client->startArchive($sessionId, $options);
358485

359486
return new Archive($archiveData, array( 'client' => $this->client ));
@@ -637,6 +764,17 @@ public function disableForceMute(string $sessionId, array $options): bool
637764
* <a href="https://tokbox.com/developer/guides/archive-broadcast-layout/#stream-prioritization-rules">stream
638765
* prioritization rules</a>.</li>
639766
*
767+
* <li><code>multiBroadcastTag</code> (String) (Optional) &mdash; Set this to support multiple broadcasts for
768+
* the same session simultaneously. Set this to a unique string for each simultaneous broadcast of an ongoing session.
769+
* Note that the `multiBroadcastTag` value is *not* included in the response for the methods to
770+
* {https://tokbox.com/developer/rest/#list_broadcasts list live streaming broadcasts} and
771+
* {https://tokbox.com/developer/rest/#get_info_broadcast get information about a live streaming broadcast}.
772+
* {https://tokbox.com/developer/guides/broadcast/live-streaming#simultaneous-broadcasts See Simultaneous broadcasts}.</li>
773+
*
774+
* <li><code>resolution</code> &mdash; The resolution of the broadcast: either "640x480" (SD landscape, the default), "1280x720" (HD landscape),
775+
* "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280" (HD portrait), or "1080x1920"
776+
* (FHD portrait).</li>
777+
*
640778
* <li><code>outputs</code> (Array) &mdash;
641779
* Defines the HLS broadcast and RTMP streams. You can provide the following keys:
642780
* <ul>
@@ -678,6 +816,10 @@ public function startBroadcast(string $sessionId, array $options = []): Broadcas
678816
// not preferred to depend on that in the SDK because its then harder to garauntee backwards
679817
// compatibility
680818

819+
if (isset($options['resolution'])) {
820+
Validators::validateResolution($options['resolution']);
821+
}
822+
681823
if (isset($options['output']['hls'])) {
682824
Validators::validateBroadcastOutputOptions($options['output']['hls']);
683825
}
@@ -689,6 +831,7 @@ public function startBroadcast(string $sessionId, array $options = []): Broadcas
689831
$defaults = [
690832
'layout' => Layout::getBestFit(),
691833
'streamMode' => 'auto',
834+
'resolution' => '640x480',
692835
'output' => [
693836
'hls' => [
694837
'dvr' => false,
@@ -709,7 +852,7 @@ public function startBroadcast(string $sessionId, array $options = []): Broadcas
709852
// make API call
710853
$broadcastData = $this->client->startBroadcast($sessionId, $options);
711854

712-
return new Broadcast($broadcastData, array( 'client' => $this->client ));
855+
return new Broadcast($broadcastData, array('client' => $this->client));
713856
}
714857

715858
/**

0 commit comments

Comments
 (0)