Skip to content

Commit 94f5542

Browse files
authored
Merge pull request #314 from opentok/feature/multiple-archive-support
Feature/multiple archive support
2 parents c8873cd + 809a840 commit 94f5542

File tree

5 files changed

+119
-3
lines changed

5 files changed

+119
-3
lines changed

src/OpenTok/Archive.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
* @property string $sessionId
4949
* The session ID of the OpenTok session associated with this archive.
5050
*
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+
*
5155
* @property string $size
5256
* The size of the MP4 file. For archives that have not been generated, this value is set to 0.
5357
*
@@ -99,6 +103,9 @@ class Archive
99103
private $isDeleted;
100104
/** @internal */
101105
private $client;
106+
/** @internal */
107+
private $multiArchiveTag;
108+
102109

103110
/** @internal */
104111
public function __construct($archiveData, $options = array())
@@ -120,6 +127,9 @@ public function __construct($archiveData, $options = array())
120127
Validators::validateHasStreamMode($streamMode);
121128

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

124134
$this->client = isset($client) ? $client : new Client();
125135
if (!$this->client->isConfigured()) {
@@ -154,6 +164,8 @@ public function __get($name)
154164
case 'resolution':
155165
case 'streamMode':
156166
return $this->data[$name];
167+
case 'multiArchiveTag':
168+
return $this->multiArchiveTag;
157169
default:
158170
return null;
159171
}

src/OpenTok/Broadcast.php

Lines changed: 13 additions & 2 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
*
@@ -75,9 +79,10 @@ class Broadcast
7579
/** @ignore */
7680
private $isDvr;
7781
/** @ignore */
78-
private $resolution;
79-
82+
private $multiBroadcastTag;
8083
/** @ignore */
84+
private $resolution;
85+
8186
public function __construct($broadcastData, $options = array())
8287
{
8388
// unpack optional arguments (merging with default values) into named variables
@@ -104,6 +109,10 @@ public function __construct($broadcastData, $options = array())
104109

105110
$this->data = $broadcastData;
106111

112+
if (isset($this->data['multiBroadcastTag'])) {
113+
$this->multiBroadcastTag = $this->data['multiBroadcastTag'];
114+
}
115+
107116
$this->isStopped = $isStopped;
108117
$this->resolution = $this->data['resolution'];
109118
$this->isHls = isset($this->data['settings']['hls']);
@@ -146,6 +155,8 @@ public function __get($name)
146155
return $this->isLowLatency;
147156
case 'isDvr':
148157
return $this->isDvr;
158+
case 'multiBroadcastTag':
159+
return $this->multiBroadcastTag;
149160
default:
150161
return null;
151162
}

src/OpenTok/OpenTok.php

100755100644
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ public function getRender($renderId): Render
410410
* <code>hasVideo</code> to false, the call to the <code>startArchive()</code> method results
411411
* in an error.</li>
412412
*
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+
*
413423
* <li><code>'outputMode'</code> (OutputMode) &mdash; Whether all streams in the
414424
* archive are recorded to a single file (<code>OutputMode::COMPOSED</code>, the default)
415425
* or to individual files (<code>OutputMode::INDIVIDUAL</code>).</li>
@@ -754,6 +764,13 @@ public function disableForceMute(string $sessionId, array $options): bool
754764
* <a href="https://tokbox.com/developer/guides/archive-broadcast-layout/#stream-prioritization-rules">stream
755765
* prioritization rules</a>.</li>
756766
*
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+
*
757774
* <li><code>resolution</code> &mdash; The resolution of the broadcast: either "640x480" (SD landscape, the default), "1280x720" (HD landscape),
758775
* "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280" (HD portrait), or "1080x1920"
759776
* (FHD portrait).</li>

tests/OpenTokTest/ArchiveTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function testCannotAddStreamToArchiveInAutoMode(): void
188188
);
189189
}
190190

191-
public function testCannotAddStreamToArchiveWithNoAudioAndVideoe(): void
191+
public function testCannotAddStreamToArchiveWithNoAudioAndVideo(): void
192192
{
193193
$this->expectException(InvalidArgumentException::class);
194194
$this->setupOTWithMocks([[

tests/OpenTokTest/OpenTokTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,41 @@ public function testStartsArchive()
625625
$this->assertEquals('auto', $archive->streamMode);
626626
}
627627

628+
public function testStartsArchiveInMultiTagMode()
629+
{
630+
$this->setupOTWithMocks([[
631+
'code' => 200,
632+
'headers' => [
633+
'Content-Type' => 'application/json'
634+
],
635+
'path' => 'v2/project/APIKEY/archive/session'
636+
]]);
637+
638+
$sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-';
639+
640+
$archive = $this->opentok->startArchive($sessionId, ['multiArchiveTag' => 'my-key']);
641+
642+
// Assert
643+
$this->assertCount(1, $this->historyContainer);
644+
645+
$request = $this->historyContainer[0]['request'];
646+
$this->assertEquals('POST', strtoupper($request->getMethod()));
647+
$this->assertEquals('/v2/project/'.$this->API_KEY.'/archive', $request->getUri()->getPath());
648+
$this->assertEquals('api.opentok.com', $request->getUri()->getHost());
649+
$this->assertEquals('https', $request->getUri()->getScheme());
650+
651+
$this->assertInstanceOf('OpenTok\Archive', $archive);
652+
$this->assertEquals(0, $archive->duration);
653+
$this->assertEquals('', $archive->reason);
654+
$this->assertEquals('started', $archive->status);
655+
$this->assertEquals(OutputMode::COMPOSED, $archive->outputMode);
656+
$this->assertNull($archive->name);
657+
$this->assertNull($archive->url);
658+
$this->assertTrue($archive->hasVideo);
659+
$this->assertTrue($archive->hasAudio);
660+
$this->assertEquals('auto', $archive->streamMode);
661+
}
662+
628663
public function testStartsArchiveInManualMode(): void
629664
{
630665
// Arrange
@@ -1559,6 +1594,47 @@ public function testStartsBroadcast()
15591594
$this->assertEquals('auto', $broadcast->streamMode);
15601595
}
15611596

1597+
public function testStartsBroadcastWithMultiBroadcastTag()
1598+
{
1599+
// Arrange
1600+
$this->setupOTWithMocks([[
1601+
'code' => 200,
1602+
'headers' => [
1603+
'Content-Type' => 'application/json'
1604+
],
1605+
'path' => '/v2/project/APIKEY/broadcast/session_layout-bestfit'
1606+
]]);
1607+
1608+
$sessionId = '2_MX44NTQ1MTF-fjE0NzI0MzU2MDUyMjN-eVgwNFJhZmR6MjdockFHanpxNzBXaEFXfn4';
1609+
1610+
$broadcast = $this->opentok->startBroadcast($sessionId, ['multiBroadcastTag' => 'my-broadcast-tag']);
1611+
1612+
$this->assertCount(1, $this->historyContainer);
1613+
1614+
$request = $this->historyContainer[0]['request'];
1615+
$this->assertEquals('POST', strtoupper($request->getMethod()));
1616+
$this->assertEquals('/v2/project/'.$this->API_KEY.'/broadcast', $request->getUri()->getPath());
1617+
$this->assertEquals('api.opentok.com', $request->getUri()->getHost());
1618+
$this->assertEquals('https', $request->getUri()->getScheme());
1619+
1620+
$contentType = $request->getHeaderLine('Content-Type');
1621+
$this->assertNotEmpty($contentType);
1622+
$this->assertEquals('application/json', $contentType);
1623+
1624+
$authString = $request->getHeaderLine('X-OPENTOK-AUTH');
1625+
$this->assertEquals(true, TestHelpers::validateOpenTokAuthHeader($this->API_KEY, $this->API_SECRET, $authString));
1626+
1627+
$this->assertInstanceOf('OpenTok\Broadcast', $broadcast);
1628+
$this->assertIsString($broadcast->id);
1629+
$this->assertEquals($sessionId, $broadcast->sessionId);
1630+
$this->assertIsArray($broadcast->broadcastUrls);
1631+
$this->assertArrayHasKey('hls', $broadcast->broadcastUrls);
1632+
$this->assertIsString($broadcast->broadcastUrls['hls']);
1633+
$this->assertIsString($broadcast->hlsUrl);
1634+
$this->assertFalse($broadcast->isStopped);
1635+
$this->assertEquals('auto', $broadcast->streamMode);
1636+
}
1637+
15621638
public function testCannotStartBroadcastWithInvalidStreamMode()
15631639
{
15641640
$this->expectException(InvalidArgumentException::class);

0 commit comments

Comments
 (0)