Skip to content

Add BBB 3.0 client settings override #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"ext-curl": "*",
"ext-simplexml": "*",
"ext-mbstring": "*",
"ext-json": "*"
"ext-json": "*",
"ext-dom": "*"
},
"suggest": {
"psr/http-client-implementation": "To use the PsrHttpClientTransport.",
Expand Down
2 changes: 1 addition & 1 deletion src/BigBlueButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function getCreateMeetingUrl(CreateMeetingParameters $createMeetingParams
*/
public function createMeeting(CreateMeetingParameters $createMeetingParams): CreateMeetingResponse
{
$xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML());
$xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getModules());

return new CreateMeetingResponse($xml);
}
Expand Down
32 changes: 25 additions & 7 deletions src/Parameters/CreateMeetingParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use BigBlueButton\Enum\Feature;
use BigBlueButton\Enum\GuestPolicy;
use BigBlueButton\Enum\MeetingLayout;
use BigBlueButton\Util\SimpleXMLElementExtended;

/**
* @method string getName()
Expand Down Expand Up @@ -157,6 +158,10 @@
* @method $this setPluginManifestsFetchUrl(string $pluginManifestsFetchUrl)
* @method bool|null isPresentationConversionCacheEnabled()
* @method $this setPresentationConversionCacheEnabled(bool $presentationConversionCacheEnabled)
* @method bool|null isAllowOverrideClientSettingsOnCreateCall()
* @method $this setAllowOverrideClientSettingsOnCreateCall(bool $allowOverrideClientSettingsOnCreateCall)
* @method string getClientSettingsOverride()
* @method $this setClientSettingsOverride(string $clientSettingsOverride)
*/
class CreateMeetingParameters extends MetaParameters
{
Expand Down Expand Up @@ -239,6 +244,8 @@ class CreateMeetingParameters extends MetaParameters
protected ?string $pluginManifests = null;
protected ?string $pluginManifestsFetchUrl = null;
protected ?bool $presentationConversionCacheEnabled = null;
protected ?bool $allowOverrideClientSettingsOnCreateCall = null;
protected ?string $clientSettingsOverride = null;

/**
* @var array<string,string>
Expand All @@ -249,7 +256,7 @@ public function __construct(protected string $meetingID, protected string $name)
{
$this->guestPolicy = GuestPolicy::ALWAYS_ACCEPT;

$this->ignoreProperties = ['disabledFeatures', 'disabledFeaturesExclude'];
$this->ignoreProperties = ['disabledFeatures', 'disabledFeaturesExclude', 'clientSettingsOverride'];
}

public function setEndCallbackUrl(string $endCallbackUrl): self
Expand Down Expand Up @@ -381,12 +388,26 @@ public function getPresentations(): array
return $this->presentations;
}

public function getPresentationsAsXML(): string|false
public function getModules(): string
{
$result = '';
$xml = new SimpleXMLElementExtended('<?xml version="1.0" encoding="UTF-8"?><modules/>');
$this->addPresentationsModule($xml);
$this->addClientSettingsOverrideModule($xml);

return $xml->asXML();
}

public function addClientSettingsOverrideModule(SimpleXMLElementExtended $xml): void
{
if (!empty($this->clientSettingsOverride)) {
$module = $xml->addChildWithCData('module', $this->clientSettingsOverride);
$module->addAttribute('name', 'clientSettingsOverride');
}
}

public function addPresentationsModule(SimpleXMLElementExtended $xml): void
{
if (!empty($this->presentations)) {
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>');
$module = $xml->addChild('module');
$module->addAttribute('name', 'presentation');

Expand All @@ -404,10 +425,7 @@ public function getPresentationsAsXML(): string|false
$document[0] = $content;
}
}
$result = $xml->asXML();
}

return $result;
}

public function getHTTPQuery(): string
Expand Down
24 changes: 24 additions & 0 deletions src/Util/SimpleXMLElementExtended.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace BigBlueButton\Util;

final class SimpleXMLElementExtended extends \SimpleXMLElement
{
/**
* Adds a child with $value inside CDATA.
*
* @param string $name the name of the child element
* @param string $value the value to be wrapped in CDATA
*/
public function addChildWithCData(string $name, string $value): self
{
$child = parent::addChild($name);
$element = dom_import_simplexml($child);
$docOwner = $element->ownerDocument;
$element->appendChild($docOwner->createCDATASection($value));

return $child;
}
}
6 changes: 6 additions & 0 deletions tests/fixtures/client_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<modules>
<module name="clientSettingsOverride">
<![CDATA[{ "public": { "app": { "appName": "Test" } } }]]>
</module>
</modules>
16 changes: 13 additions & 3 deletions tests/unit/Parameters/CreateMeetingParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,23 @@ public function testGetPresentationsAsXMLWithUrl(): void
$params = $this->generateCreateParams();
$createMeetingParams = $this->getCreateMock($params);
$createMeetingParams->addPresentation('http://test-install.blindsidenetworks.com/default.pdf');
$this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_url.xml', $createMeetingParams->getPresentationsAsXML());
$this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_url.xml', $createMeetingParams->getModules());
}

public function testGetPresentationsAsXMLWithUrlAndFilename(): void
{
$params = $this->generateCreateParams();
$createMeetingParams = $this->getCreateMock($params);
$createMeetingParams->addPresentation('http://test-install.blindsidenetworks.com/default.pdf', null, 'presentation.pdf');
$this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_filename.xml', $createMeetingParams->getPresentationsAsXML());
$this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_filename.xml', $createMeetingParams->getModules());
}

public function testGetPresentationsAsXMLWithFile(): void
{
$params = $this->generateCreateParams();
$createMeetingParams = $this->getCreateMock($params);
$createMeetingParams->addPresentation('bbb_logo.png', file_get_contents(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'bbb_logo.png'));
$this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_embedded_file.xml', $createMeetingParams->getPresentationsAsXML());
$this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'presentation_with_embedded_file.xml', $createMeetingParams->getModules());
}

public function testUserCameraCap(): void
Expand Down Expand Up @@ -272,4 +272,14 @@ public function testGuestPolicyAskModerator(): void
$this->assertSame(GuestPolicy::ASK_MODERATOR, $createMeetingParams->getGuestPolicy());
$this->assertTrue($createMeetingParams->isGuestPolicyAskModerator());
}

public function testClientSettingsOverride(): void
{
$params = $this->generateCreateParams();
$createMeetingParams = $this->getCreateMock($params);

$createMeetingParams->setClientSettingsOverride('{ "public": { "app": { "appName": "Test" } } }');

$this->assertXmlStringEqualsXmlFile(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'client_settings.xml', $createMeetingParams->getModules());
}
}
46 changes: 46 additions & 0 deletions tests/unit/Util/SimpleXMLElementExtendedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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\Tests\Unit\Util;

use BigBlueButton\Tests\Common\TestCase;
use BigBlueButton\Util\SimpleXMLElementExtended;

/**
* @covers \BigBlueButton\Util\SimpleXMLElementExtended
*/
final class SimpleXMLElementExtendedTest extends TestCase
{
/**
* Test adding a child element with CDATA content.
*/
public function testAddChildWithCData(): void
{
$xml = new SimpleXMLElementExtended('<?xml version="1.0" encoding="UTF-8"?><modules/>');
$module = $xml->addChildWithCData('module', '{"foo": {"foo": "baa"}}');
$module->addAttribute('name', 'clientSettingsOverride');

$expected = '<?xml version="1.0" encoding="UTF-8"?>
<modules><module name="clientSettingsOverride"><![CDATA[{"foo": {"foo": "baa"}}]]></module></modules>';

$this->assertXmlStringEqualsXmlString($expected, $xml->asXML());
}
}