Skip to content

Commit 2023fe0

Browse files
authored
Merge pull request #109 from littleredbutton/fix-playback-format
Expose all formats of a recording
2 parents bc3cba2 + 80f01d5 commit 2023fe0

File tree

5 files changed

+263
-2
lines changed

5 files changed

+263
-2
lines changed

src/Core/ImagePreview.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of littleredbutton/bigbluebutton-api-php.
7+
*
8+
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
namespace BigBlueButton\Core;
22+
23+
class ImagePreview
24+
{
25+
/** @var int */
26+
private $width;
27+
28+
/** @var int */
29+
private $height;
30+
31+
/** @var string */
32+
private $alt;
33+
34+
/** @var string */
35+
private $url;
36+
37+
public function __construct(int $width, int $height, string $alt, string $url)
38+
{
39+
$this->width = $width;
40+
$this->height = $height;
41+
$this->alt = $alt;
42+
$this->url = $url;
43+
}
44+
45+
public function getWidth(): int
46+
{
47+
return $this->width;
48+
}
49+
50+
public function getHeight(): int
51+
{
52+
return $this->height;
53+
}
54+
55+
public function getAlt(): string
56+
{
57+
return $this->alt;
58+
}
59+
60+
public function getUrl(): string
61+
{
62+
return $this->url;
63+
}
64+
}

src/Core/PlaybackFormat.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of littleredbutton/bigbluebutton-api-php.
7+
*
8+
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
namespace BigBlueButton\Core;
22+
23+
class PlaybackFormat
24+
{
25+
26+
/** @var string */
27+
private $type;
28+
29+
/** @var string */
30+
private $url;
31+
32+
/** @var int */
33+
private $processingTime;
34+
35+
/** @var int */
36+
private $length;
37+
38+
/** @var ImagePreview[] */
39+
private $imagePreviews;
40+
41+
/** @var \SimpleXMLElement */
42+
private $imagePreviewsRaw;
43+
44+
public function __construct(\SimpleXMLElement $xml)
45+
{
46+
$this->type = $xml->type->__toString();
47+
$this->url = $xml->url->__toString();
48+
$this->processingTime = (int) $xml->processingTime->__toString();
49+
$this->length = (int) $xml->length->__toString();
50+
51+
$this->imagePreviewsRaw = $xml->preview->images;
52+
}
53+
54+
public function getType(): string
55+
{
56+
return $this->type;
57+
}
58+
59+
public function getUrl(): string
60+
{
61+
return $this->url;
62+
}
63+
64+
public function getProcessingTime(): int
65+
{
66+
return $this->processingTime;
67+
}
68+
69+
public function getLength(): int
70+
{
71+
return $this->length;
72+
}
73+
74+
public function hasImagePreviews(): bool
75+
{
76+
return !!$this->imagePreviewsRaw;
77+
}
78+
79+
/**
80+
*
81+
* @return ImagePreview[]
82+
*/
83+
public function getImagePreviews(): array
84+
{
85+
if ($this->imagePreviews !== null) {
86+
return $this->imagePreviews;
87+
}
88+
89+
$this->imagePreviews = [];
90+
if ($this->imagePreviewsRaw) {
91+
foreach ($this->imagePreviewsRaw->children() as $image) {
92+
$attributes = $image->attributes();
93+
94+
$this->imagePreviews[] = new ImagePreview(
95+
(int) $attributes->width->__toString(),
96+
(int) $attributes->height->__toString(),
97+
$attributes->alt->__toString(),
98+
$image->__toString()
99+
);
100+
}
101+
}
102+
103+
return $this->imagePreviews;
104+
}
105+
}

src/Core/Record.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class Record
3535
private $playbackType;
3636
private $playbackUrl;
3737
private $playbackLength;
38-
private $metas;
38+
private $metas = [];
39+
40+
/** @var PlaybackFormat[] */
41+
private $playbackFormats = [];
3942

4043
public function __construct(\SimpleXMLElement $xml)
4144
{
@@ -51,6 +54,10 @@ public function __construct(\SimpleXMLElement $xml)
5154
$this->playbackUrl = $xml->playback->format->url->__toString();
5255
$this->playbackLength = (int) $xml->playback->format->length->__toString();
5356

57+
foreach ($xml->playback->children() as $format) {
58+
$this->playbackFormats[] = new PlaybackFormat($format);
59+
}
60+
5461
foreach ($xml->metadata->children() as $meta) {
5562
$this->metas[$meta->getName()] = $meta->__toString();
5663
}
@@ -121,6 +128,7 @@ public function getParticipantCount()
121128
}
122129

123130
/**
131+
* @deprecated since 4.2. Use getPlaybackFormats() instead.
124132
* @return string
125133
*/
126134
public function getPlaybackType()
@@ -129,6 +137,7 @@ public function getPlaybackType()
129137
}
130138

131139
/**
140+
* @deprecated since 4.2. Use getPlaybackFormats() instead.
132141
* @return string
133142
*/
134143
public function getPlaybackUrl()
@@ -137,6 +146,7 @@ public function getPlaybackUrl()
137146
}
138147

139148
/**
149+
* @deprecated since 4.2. Use getPlaybackFormats() instead.
140150
* @return string
141151
*/
142152
public function getPlaybackLength()
@@ -151,4 +161,12 @@ public function getMetas()
151161
{
152162
return $this->metas;
153163
}
164+
165+
/**
166+
* @return PlaybackFormat[]
167+
*/
168+
public function getPlaybackFormats(): array
169+
{
170+
return $this->playbackFormats;
171+
}
154172
}

tests/fixtures/get_recordings.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,44 @@
163163
</format>
164164
</playback>
165165
</recording>
166+
<recording>
167+
<recordID>ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124</recordID>
168+
<meetingID>c637ba21adcd0191f48f5c4bf23fab0f96ed5c18</meetingID>
169+
<internalMeetingID>ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124</internalMeetingID>
170+
<name>Fred's Room</name>
171+
<isBreakout>false</isBreakout>
172+
<published>true</published>
173+
<state>published</state>
174+
<startTime>1530718721124</startTime>
175+
<endTime>1530718810456</endTime>
176+
<participants>3</participants>
177+
<metadata>
178+
<isBreakout>false</isBreakout>
179+
<meetingName>Fred's Room</meetingName>
180+
<gl-listed>false</gl-listed>
181+
<meetingId>c637ba21adcd0191f48f5c4bf23fab0f96ed5c18</meetingId>
182+
</metadata>
183+
<playback>
184+
<format>
185+
<type>podcast</type>
186+
<url>https://demo.bigbluebutton.org/podcast/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/audio.ogg</url>
187+
<processingTime>0</processingTime>
188+
<length>0</length>
189+
</format>
190+
<format>
191+
<type>presentation</type>
192+
<url>https://demo.bigbluebutton.org/playback/presentation/2.0/playback.html?meetingId=ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124</url>
193+
<processingTime>7177</processingTime>
194+
<length>0</length>
195+
<preview>
196+
<images>
197+
<image alt="Welcome to" height="136" width="176">https://demo.bigbluebutton.org/presentation/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1530718721134/thumbnails/thumb-1.png</image>
198+
<image alt="(this slide left blank for use as a whiteboard)" height="136" width="176">https://demo.bigbluebutton.org/presentation/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1530718721134/thumbnails/thumb-2.png</image>
199+
<image alt="(this slide left blank for use as a whiteboard)" height="136" width="176">https://demo.bigbluebutton.org/presentation/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1530718721134/thumbnails/thumb-3.png</image>
200+
</images>
201+
</preview>
202+
</format>
203+
</playback>
204+
</recording>
166205
</recordings>
167206
</response>

tests/unit/Responses/GetRecordingsResponseTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testGetRecordingResponseContent()
4141
{
4242
$this->assertEquals('SUCCESS', $this->records->getReturnCode());
4343

44-
$this->assertCount(6, $this->records->getRecords());
44+
$this->assertCount(7, $this->records->getRecords());
4545

4646
$aRecord = $this->records->getRecords()[4];
4747

@@ -56,6 +56,8 @@ public function testGetRecordingResponseContent()
5656
$this->assertEquals('http://test-install.blindsidenetworks.com/playback/presentation/0.9.0/playback.html?meetingId=f71d810b6e90a4a34ae02b8c7143e8733178578e-1462980100026', $aRecord->getPlaybackUrl());
5757
$this->assertEquals(86, $aRecord->getPlaybackLength());
5858
$this->assertEquals(9, sizeof($aRecord->getMetas()));
59+
60+
$this->assertEquals($aRecord->getPlaybackUrl(), $aRecord->getPlaybackFormats()[0]->getUrl(), 'The default plackback is the first playback child');
5961
}
6062

6163
public function testRecordMetadataContent()
@@ -80,4 +82,37 @@ public function testGetRecordingResponseTypes()
8082

8183
$this->assertEachGetterValueIsDouble($aRecord, ['getStartTime', 'getEndTime']);
8284
}
85+
86+
public function testMultiplePlaybackFormats(): void
87+
{
88+
$record = $this->records->getRecords()[6];
89+
$formats = $record->getPlaybackFormats();
90+
91+
$this->assertCount(2, $formats);
92+
93+
$this->assertEquals('podcast', $formats[0]->getType());
94+
$this->assertEquals('https://demo.bigbluebutton.org/podcast/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/audio.ogg', $formats[0]->getUrl());
95+
$this->assertEquals(0, $formats[0]->getProcessingTime());
96+
$this->assertEquals(0, $formats[0]->getLength());
97+
98+
$this->assertEquals('presentation', $formats[1]->getType());
99+
$this->assertEquals('https://demo.bigbluebutton.org/playback/presentation/2.0/playback.html?meetingId=ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124', $formats[1]->getUrl());
100+
$this->assertEquals(7177, $formats[1]->getProcessingTime());
101+
$this->assertEquals(0, $formats[1]->getLength());
102+
}
103+
104+
public function testImagePreviews(): void
105+
{
106+
$record = $this->records->getRecords()[6];
107+
$formats = $record->getPlaybackFormats();
108+
109+
$this->assertTrue($formats[1]->hasImagePreviews());
110+
111+
$previews = $formats[1]->getImagePreviews();
112+
113+
$this->assertCount(3, $previews);
114+
115+
$this->assertEquals('Welcome to', $previews[0]->getAlt());
116+
$this->assertEquals('https://demo.bigbluebutton.org/presentation/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1530718721134/thumbnails/thumb-1.png', $previews[0]->getUrl());
117+
}
83118
}

0 commit comments

Comments
 (0)