Skip to content

Commit

Permalink
Merge pull request #109 from littleredbutton/fix-playback-format
Browse files Browse the repository at this point in the history
Expose all formats of a recording
  • Loading branch information
FelixJacobi committed Mar 16, 2022
2 parents bc3cba2 + 80f01d5 commit 2023fe0
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 2 deletions.
64 changes: 64 additions & 0 deletions src/Core/ImagePreview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

/**
* This file is part of littleredbutton/bigbluebutton-api-php.
*
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Core;

class ImagePreview
{
/** @var int */
private $width;

/** @var int */
private $height;

/** @var string */
private $alt;

/** @var string */
private $url;

public function __construct(int $width, int $height, string $alt, string $url)
{
$this->width = $width;
$this->height = $height;
$this->alt = $alt;
$this->url = $url;
}

public function getWidth(): int
{
return $this->width;
}

public function getHeight(): int
{
return $this->height;
}

public function getAlt(): string
{
return $this->alt;
}

public function getUrl(): string
{
return $this->url;
}
}
105 changes: 105 additions & 0 deletions src/Core/PlaybackFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

/**
* This file is part of littleredbutton/bigbluebutton-api-php.
*
* littleredbutton/bigbluebutton-api-php is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* littleredbutton/bigbluebutton-api-php is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with littleredbutton/bigbluebutton-api-php. If not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton\Core;

class PlaybackFormat
{

/** @var string */
private $type;

/** @var string */
private $url;

/** @var int */
private $processingTime;

/** @var int */
private $length;

/** @var ImagePreview[] */
private $imagePreviews;

/** @var \SimpleXMLElement */
private $imagePreviewsRaw;

public function __construct(\SimpleXMLElement $xml)
{
$this->type = $xml->type->__toString();
$this->url = $xml->url->__toString();
$this->processingTime = (int) $xml->processingTime->__toString();
$this->length = (int) $xml->length->__toString();

$this->imagePreviewsRaw = $xml->preview->images;
}

public function getType(): string
{
return $this->type;
}

public function getUrl(): string
{
return $this->url;
}

public function getProcessingTime(): int
{
return $this->processingTime;
}

public function getLength(): int
{
return $this->length;
}

public function hasImagePreviews(): bool
{
return !!$this->imagePreviewsRaw;
}

/**
*
* @return ImagePreview[]
*/
public function getImagePreviews(): array
{
if ($this->imagePreviews !== null) {
return $this->imagePreviews;
}

$this->imagePreviews = [];
if ($this->imagePreviewsRaw) {
foreach ($this->imagePreviewsRaw->children() as $image) {
$attributes = $image->attributes();

$this->imagePreviews[] = new ImagePreview(
(int) $attributes->width->__toString(),
(int) $attributes->height->__toString(),
$attributes->alt->__toString(),
$image->__toString()
);
}
}

return $this->imagePreviews;
}
}
20 changes: 19 additions & 1 deletion src/Core/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class Record
private $playbackType;
private $playbackUrl;
private $playbackLength;
private $metas;
private $metas = [];

/** @var PlaybackFormat[] */
private $playbackFormats = [];

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

foreach ($xml->playback->children() as $format) {
$this->playbackFormats[] = new PlaybackFormat($format);
}

foreach ($xml->metadata->children() as $meta) {
$this->metas[$meta->getName()] = $meta->__toString();
}
Expand Down Expand Up @@ -121,6 +128,7 @@ public function getParticipantCount()
}

/**
* @deprecated since 4.2. Use getPlaybackFormats() instead.
* @return string
*/
public function getPlaybackType()
Expand All @@ -129,6 +137,7 @@ public function getPlaybackType()
}

/**
* @deprecated since 4.2. Use getPlaybackFormats() instead.
* @return string
*/
public function getPlaybackUrl()
Expand All @@ -137,6 +146,7 @@ public function getPlaybackUrl()
}

/**
* @deprecated since 4.2. Use getPlaybackFormats() instead.
* @return string
*/
public function getPlaybackLength()
Expand All @@ -151,4 +161,12 @@ public function getMetas()
{
return $this->metas;
}

/**
* @return PlaybackFormat[]
*/
public function getPlaybackFormats(): array
{
return $this->playbackFormats;
}
}
39 changes: 39 additions & 0 deletions tests/fixtures/get_recordings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,44 @@
</format>
</playback>
</recording>
<recording>
<recordID>ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124</recordID>
<meetingID>c637ba21adcd0191f48f5c4bf23fab0f96ed5c18</meetingID>
<internalMeetingID>ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124</internalMeetingID>
<name>Fred's Room</name>
<isBreakout>false</isBreakout>
<published>true</published>
<state>published</state>
<startTime>1530718721124</startTime>
<endTime>1530718810456</endTime>
<participants>3</participants>
<metadata>
<isBreakout>false</isBreakout>
<meetingName>Fred's Room</meetingName>
<gl-listed>false</gl-listed>
<meetingId>c637ba21adcd0191f48f5c4bf23fab0f96ed5c18</meetingId>
</metadata>
<playback>
<format>
<type>podcast</type>
<url>https://demo.bigbluebutton.org/podcast/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/audio.ogg</url>
<processingTime>0</processingTime>
<length>0</length>
</format>
<format>
<type>presentation</type>
<url>https://demo.bigbluebutton.org/playback/presentation/2.0/playback.html?meetingId=ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124</url>
<processingTime>7177</processingTime>
<length>0</length>
<preview>
<images>
<image alt="Welcome to" height="136" width="176">https://demo.bigbluebutton.org/presentation/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1530718721134/thumbnails/thumb-1.png</image>
<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>
<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>
</images>
</preview>
</format>
</playback>
</recording>
</recordings>
</response>
37 changes: 36 additions & 1 deletion tests/unit/Responses/GetRecordingsResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testGetRecordingResponseContent()
{
$this->assertEquals('SUCCESS', $this->records->getReturnCode());

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

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

Expand All @@ -56,6 +56,8 @@ public function testGetRecordingResponseContent()
$this->assertEquals('http://test-install.blindsidenetworks.com/playback/presentation/0.9.0/playback.html?meetingId=f71d810b6e90a4a34ae02b8c7143e8733178578e-1462980100026', $aRecord->getPlaybackUrl());
$this->assertEquals(86, $aRecord->getPlaybackLength());
$this->assertEquals(9, sizeof($aRecord->getMetas()));

$this->assertEquals($aRecord->getPlaybackUrl(), $aRecord->getPlaybackFormats()[0]->getUrl(), 'The default plackback is the first playback child');
}

public function testRecordMetadataContent()
Expand All @@ -80,4 +82,37 @@ public function testGetRecordingResponseTypes()

$this->assertEachGetterValueIsDouble($aRecord, ['getStartTime', 'getEndTime']);
}

public function testMultiplePlaybackFormats(): void
{
$record = $this->records->getRecords()[6];
$formats = $record->getPlaybackFormats();

$this->assertCount(2, $formats);

$this->assertEquals('podcast', $formats[0]->getType());
$this->assertEquals('https://demo.bigbluebutton.org/podcast/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/audio.ogg', $formats[0]->getUrl());
$this->assertEquals(0, $formats[0]->getProcessingTime());
$this->assertEquals(0, $formats[0]->getLength());

$this->assertEquals('presentation', $formats[1]->getType());
$this->assertEquals('https://demo.bigbluebutton.org/playback/presentation/2.0/playback.html?meetingId=ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124', $formats[1]->getUrl());
$this->assertEquals(7177, $formats[1]->getProcessingTime());
$this->assertEquals(0, $formats[1]->getLength());
}

public function testImagePreviews(): void
{
$record = $this->records->getRecords()[6];
$formats = $record->getPlaybackFormats();

$this->assertTrue($formats[1]->hasImagePreviews());

$previews = $formats[1]->getImagePreviews();

$this->assertCount(3, $previews);

$this->assertEquals('Welcome to', $previews[0]->getAlt());
$this->assertEquals('https://demo.bigbluebutton.org/presentation/ffbfc4cc24428694e8b53a4e144f414052431693-1530718721124/presentation/d2d9a672040fbde2a47a10bf6c37b6a4b5ae187f-1530718721134/thumbnails/thumb-1.png', $previews[0]->getUrl());
}
}

0 comments on commit 2023fe0

Please sign in to comment.