Skip to content

Commit e231d4b

Browse files
Implement breakout rooms groups in create API (#155)
* Implement breakout rooms groups in create API * Code cleanup, add comments, type hints * Fix cs * Fixed missing type hints * Fixed CS --------- Co-authored-by: Felix Jacobi <felix@jacobi-hamburg.net>
1 parent eaafe11 commit e231d4b

5 files changed

Lines changed: 69 additions & 8 deletions

File tree

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/Parameters/CreateMeetingParameters.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ class CreateMeetingParameters extends MetaParameters
373373
*/
374374
protected $userCameraCap;
375375

376+
/**
377+
* @var array<array{id: string, name: string|null, roster: array}>
378+
*/
379+
private $breakoutRoomsGroups = [];
380+
376381
/**
377382
* @var array
378383
*/
@@ -487,6 +492,24 @@ public function addPresentation(string $nameOrUrl, string $content = null, strin
487492
return $this;
488493
}
489494

495+
/**
496+
* @return array<array{id: string, name: string|null, roster: array}>
497+
*/
498+
public function getBreakoutRoomsGroups(): array
499+
{
500+
return $this->breakoutRoomsGroups;
501+
}
502+
503+
/**
504+
* @return $this
505+
*/
506+
public function addBreakoutRoomsGroup(string $id, ?string $name, array $roster): self
507+
{
508+
$this->breakoutRoomsGroups[] = ['id' => $id, 'name' => $name, 'roster' => $roster];
509+
510+
return $this;
511+
}
512+
490513
public function getPresentations(): array
491514
{
492515
return $this->presentations;
@@ -524,6 +547,13 @@ public function getHTTPQuery(): string
524547
{
525548
$queries = $this->getHTTPQueryArray();
526549

550+
// Pre-defined groups to automatically assign the students to a given breakout room
551+
if (!empty($this->breakoutRoomsGroups)) {
552+
$queries = array_merge($queries, [
553+
'groups' => json_encode($this->breakoutRoomsGroups),
554+
]);
555+
}
556+
527557
if ($this->isBreakout()) {
528558
if ($this->parentMeetingID === null || $this->sequence === null) {
529559
throw new \RuntimeException('Breakout rooms require a parentMeetingID and sequence number.');

tests/TestCase.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/unit/BigBlueButtonTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,8 @@ public function testCreateMeetingUrl()
163163
{
164164
$params = $this->generateCreateParams();
165165
$url = $this->bbb->getCreateMeetingUrl($this->getCreateMock($params));
166-
foreach ($params as $key => $value) {
167-
if (\is_bool($value)) {
168-
$value = $value ? 'true' : 'false';
169-
}
170-
$this->assertStringContainsString(rawurlencode($key).'='.rawurlencode($value), $url);
171-
}
166+
167+
$this->assertUrlContainsAllRequestParameters($url, $params);
172168
}
173169

174170
/* Join Meeting */

tests/unit/Parameters/CreateMeetingParametersTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function testCreateMeetingParameters()
8989
$this->assertEquals($params['breakoutRoomsRecord'], $createMeetingParams->isBreakoutRoomsRecord());
9090
$this->assertEquals($params['allowRequestsWithoutSession'], $createMeetingParams->isAllowRequestsWithoutSession());
9191
$this->assertEquals($params['virtualBackgroundsDisabled'], $createMeetingParams->isVirtualBackgroundsDisabled());
92+
$this->assertEquals(json_encode($params['groups']), json_encode($createMeetingParams->getBreakoutRoomsGroups()));
9293

9394
// Check values are empty of this is not a breakout room
9495
$this->assertNull($createMeetingParams->isBreakout());

0 commit comments

Comments
 (0)