Skip to content

Commit addebc3

Browse files
committed
Merge branch 'master' of https://github.com/littleredbutton/bigbluebutton-api-php into remove-configToken
2 parents 3d76cc4 + b55171b commit addebc3

13 files changed

Lines changed: 280 additions & 62 deletions

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"ext-curl": "*",
6363
"ext-simplexml": "*",
6464
"ext-mbstring": "*",
65-
"ext-json": "*"
65+
"ext-json": "*",
66+
"marc-mabe/php-enum": "^4.7"
6667
},
6768
"suggest": {
6869
"psr/http-client-implementation": "To use the PsrHttpClientTransport.",
@@ -124,12 +125,12 @@
124125
"brainmaestro/composer-git-hooks": "^2.8",
125126
"extensions": {
126127
"phpunit/phpunit": {
127-
"fakerphp/faker": "^1.14"
128+
"fakerphp/faker": "1.20.*"
128129
}
129130
},
130131
"friendsofphp/php-cs-fixer": "^3.3",
131132
"php-coveralls/php-coveralls": "^2.4",
132-
"phpunit/phpunit": "^8",
133+
"phpunit/phpunit": "^9",
133134
"vimeo/psalm": "^4.22"
134135
}
135136
}

phpunit.xml.dist

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
4-
<phpunit backupGlobals="false"
5-
backupStaticAttributes="false"
6-
bootstrap="./tests/bootstrap.php"
7-
colors="true"
8-
convertDeprecationsToExceptions="false"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
12-
processIsolation="false"
13-
stopOnFailure="false">
14-
15-
<filter>
16-
<whitelist processUncoveredFilesFromWhitelist="true">
17-
<directory suffix=".php">./src/</directory>
18-
</whitelist>
19-
</filter>
20-
21-
<testsuites>
22-
<testsuite name="BigBlueButton unit test suite">
23-
<directory>./tests/unit/</directory>
24-
</testsuite>
25-
<testsuite name="BigBlueButton integration test suite">
26-
<directory>./tests/integration/</directory>
27-
</testsuite>
28-
<testsuite name="BigBlueButton functional test suite">
29-
<directory>./tests/functional/</directory>
30-
</testsuite>
31-
</testsuites>
32-
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="./tests/bootstrap.php" colors="true" convertDeprecationsToExceptions="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">./src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="BigBlueButton unit test suite">
10+
<directory>./tests/unit/</directory>
11+
</testsuite>
12+
<testsuite name="BigBlueButton integration test suite">
13+
<directory>./tests/integration/</directory>
14+
</testsuite>
15+
<testsuite name="BigBlueButton functional test suite">
16+
<directory>./tests/functional/</directory>
17+
</testsuite>
18+
</testsuites>
3319
</phpunit>

src/BigBlueButton.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace BigBlueButton;
2121

2222
use BigBlueButton\Core\ApiMethod;
23+
use BigBlueButton\Enum\HashingAlgorithm;
2324
use BigBlueButton\Exceptions\ConfigException;
2425
use BigBlueButton\Exceptions\NetworkException;
2526
use BigBlueButton\Exceptions\ParsingException;
@@ -80,6 +81,11 @@ class BigBlueButton
8081
*/
8182
protected $bbbServerBaseUrl;
8283

84+
/**
85+
* @var string
86+
*/
87+
protected $hashingAlgorithm;
88+
8389
/**
8490
* @var UrlBuilder
8591
*/
@@ -107,17 +113,19 @@ class BigBlueButton
107113
*
108114
* @throws ConfigException
109115
*/
110-
public function __construct(string $baseUrl = null, string $secret = null, TransportInterface $transport = null)
116+
public function __construct(string $baseUrl = null, string $secret = null, TransportInterface $transport = null, string $hashingAlgorithm = HashingAlgorithm::SHA_1)
111117
{
112118
// Keeping backward compatibility with older deployed versions
113119
$this->securitySecret = $secret ?: getenv('BBB_SECURITY_SALT') ?: getenv('BBB_SECRET');
114120
$this->bbbServerBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL');
115121

122+
$this->hashingAlgorithm = $hashingAlgorithm;
123+
116124
if (empty($this->bbbServerBaseUrl)) {
117125
throw new ConfigException('Base url required');
118126
}
119127

120-
$this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl);
128+
$this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl, $this->hashingAlgorithm);
121129
$this->transport = $transport ?? CurlTransport::createWithDefaultOptions();
122130
}
123131

src/Core/Meeting.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ class Meeting
6161
private $dialNumber;
6262

6363
/**
64-
* @var string
64+
* @var string|null
6565
*/
6666
private $attendeePassword;
6767

6868
/**
69-
* @var string
69+
* @var string|null
7070
*/
7171
private $moderatorPassword;
7272

src/Enum/HashingAlgorithm.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5+
*
6+
* Copyright (c) 2016-2023 BigBlueButton Inc. and by respective authors (see below).
7+
*
8+
* This program is free software; you can redistribute it and/or modify it under the
9+
* terms of the GNU Lesser General Public License as published by the Free Software
10+
* Foundation; either version 3.0 of the License, or (at your option) any later
11+
* version.
12+
*
13+
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License along
18+
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
namespace BigBlueButton\Enum;
22+
23+
use MabeEnum\Enum;
24+
25+
class HashingAlgorithm extends Enum
26+
{
27+
public const SHA_1 = 'sha1';
28+
public const SHA_256 = 'sha256';
29+
public const SHA_512 = 'sha512';
30+
public const SHA_384 = 'sha384';
31+
}

src/Parameters/CreateMeetingParameters.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ class CreateMeetingParameters extends MetaParameters
378378
*/
379379
protected $userCameraCap;
380380

381+
/**
382+
* @var array<array{id: string, name: string|null, roster: array}>
383+
*/
384+
private $breakoutRoomsGroups = [];
385+
381386
/**
382387
* @var array
383388
*/
@@ -512,6 +517,24 @@ public function addPresentation(string $nameOrUrl, string $content = null, strin
512517
return $this;
513518
}
514519

520+
/**
521+
* @return array<array{id: string, name: string|null, roster: array}>
522+
*/
523+
public function getBreakoutRoomsGroups(): array
524+
{
525+
return $this->breakoutRoomsGroups;
526+
}
527+
528+
/**
529+
* @return $this
530+
*/
531+
public function addBreakoutRoomsGroup(string $id, ?string $name, array $roster): self
532+
{
533+
$this->breakoutRoomsGroups[] = ['id' => $id, 'name' => $name, 'roster' => $roster];
534+
535+
return $this;
536+
}
537+
515538
public function getPresentations(): array
516539
{
517540
return $this->presentations;
@@ -549,9 +572,16 @@ public function getHTTPQuery(): string
549572
{
550573
$queries = $this->getHTTPQueryArray();
551574

575+
// Pre-defined groups to automatically assign the students to a given breakout room
576+
if (!empty($this->breakoutRoomsGroups)) {
577+
$queries = array_merge($queries, [
578+
'groups' => json_encode($this->breakoutRoomsGroups),
579+
]);
580+
}
581+
552582
if ($this->isBreakout()) {
553583
if ($this->parentMeetingID === null || $this->sequence === null) {
554-
trigger_error('Breakout rooms require a parentMeetingID and sequence number.', \E_USER_WARNING);
584+
throw new \RuntimeException('Breakout rooms require a parentMeetingID and sequence number.');
555585
}
556586
} else {
557587
$queries = $this->filterBreakoutRelatedQueries($queries);

src/Util/UrlBuilder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ final class UrlBuilder
3535
*/
3636
private $bbbServerBaseUrl;
3737

38-
public function __construct(string $secret, string $serverBaseUrl)
38+
/**
39+
* @var string
40+
*/
41+
private $hashingAlgorithm;
42+
43+
public function __construct(string $secret, string $serverBaseUrl, string $hashingAlgorithm)
3944
{
4045
$this->securitySalt = $secret;
4146
$this->bbbServerBaseUrl = $serverBaseUrl;
47+
$this->hashingAlgorithm = $hashingAlgorithm;
4248
}
4349

4450
/**
@@ -61,6 +67,6 @@ public function buildQs(string $method = '', string $params = ''): string
6167
$checksumParam = 'checksum=';
6268
}
6369

64-
return $params.$checksumParam.sha1($method.$params.$this->securitySalt);
70+
return $params.$checksumParam.hash($this->hashingAlgorithm, $method.$params.$this->securitySalt);
6571
}
6672
}

tests/TestCase.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function generateCreateParams()
7272
'moderatorPW' => $this->faker->password,
7373
'autoStartRecording' => $this->faker->boolean(50),
7474
'dialNumber' => $this->faker->phoneNumber,
75-
'voiceBridge' => $this->faker->randomNumber(5),
75+
'voiceBridge' => $this->faker->randomNumber(5, true),
7676
'webVoice' => $this->faker->word,
7777
'logoutURL' => $this->faker->url,
7878
'maxParticipants' => $this->faker->numberBetween(2, 100),
@@ -120,9 +120,24 @@ protected function generateCreateParams()
120120
'allowRequestsWithoutSession' => $this->faker->boolean(50),
121121
'virtualBackgroundsDisabled' => $this->faker->boolean(50),
122122
'userCameraCap' => $this->faker->numberBetween(1, 5),
123+
'groups' => $this->generateBreakoutRoomsGroups(),
123124
];
124125
}
125126

127+
/**
128+
* @return array<array{id: string, name: string, roster: array}>
129+
*/
130+
protected function generateBreakoutRoomsGroups(): array
131+
{
132+
$br = $this->faker->numberBetween(0, 8);
133+
$groups = [];
134+
for ($i = 0; $i <= $br; ++$i) {
135+
$groups[] = ['id' => $this->faker->uuid, 'name' => $this->faker->name, 'roster' => $this->faker->randomElements];
136+
}
137+
138+
return $groups;
139+
}
140+
126141
/**
127142
* @return array
128143
*/
@@ -145,6 +160,10 @@ protected function getCreateMock($params)
145160
{
146161
$createMeetingParams = new CreateMeetingParameters($params['meetingID'], $params['name']);
147162

163+
foreach ($params['groups'] as $group) {
164+
$createMeetingParams->addBreakoutRoomsGroup($group['id'], $group['name'], $group['roster']);
165+
}
166+
148167
return $createMeetingParams->setAttendeePW($params['attendeePW'])
149168
->setModeratorPW($params['moderatorPW'])
150169
->setDialNumber($params['dialNumber'])
@@ -339,4 +358,19 @@ public function assertEachGetterValueIsBoolean($obj, $getters)
339358
$this->assertIsBool($obj->$getterName(), 'Got a '.\gettype($obj->$getterName()).' instead of a boolean for property -> '.$getterName);
340359
}
341360
}
361+
362+
public function assertUrlContainsAllRequestParameters(string $url, array $parameters): void
363+
{
364+
foreach ($parameters as $parameter) {
365+
if (\is_bool($parameter)) {
366+
$parameter = $parameter ? 'true' : 'false';
367+
}
368+
369+
if (!\is_array($parameter)) {
370+
$this->assertStringContainsString($parameter, urldecode($url));
371+
} else {
372+
$this->assertUrlContainsAllRequestParameters($url, $parameter);
373+
}
374+
}
375+
}
342376
}

0 commit comments

Comments
 (0)