Skip to content

Commit 8dc24c3

Browse files
committed
Implement eventID for webhook APIs
1 parent 6e46353 commit 8dc24c3

5 files changed

Lines changed: 132 additions & 10 deletions

File tree

src/Core/Hook.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ class Hook
3737

3838
private bool $rawData;
3939

40+
/**
41+
* @var array<string>
42+
*/
43+
private array $eventID;
44+
4045
public function __construct(\SimpleXMLElement $xml)
4146
{
4247
$this->rawXml = $xml;
4348
$this->hookId = (int) $xml->hookID->__toString();
4449
$this->callbackUrl = $xml->callbackURL->__toString();
4550
$this->meetingId = $xml->meetingID->__toString();
51+
$this->eventID = explode(',', $xml->eventID->__toString());
4652
$this->permanentHook = 'true' === $xml->permanentHook->__toString();
4753
$this->rawData = 'true' === $xml->rawData->__toString();
4854
}
@@ -62,6 +68,14 @@ public function getCallbackUrl(): string
6268
return $this->callbackUrl;
6369
}
6470

71+
/**
72+
* @return array<string>
73+
*/
74+
public function getEventID(): array
75+
{
76+
return $this->eventID;
77+
}
78+
6579
public function isPermanentHook(): ?bool
6680
{
6781
return $this->permanentHook;

src/Enum/WebHookEvent.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/*
4+
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5+
*
6+
* Copyright (c) 2016-2025 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 <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
namespace BigBlueButton\Enum;
22+
23+
/**
24+
* @ref : https://github.com/bigbluebutton/bbb-webhooks/blob/main/src/process/event.js#L7
25+
*/
26+
enum WebHookEvent: string
27+
{
28+
case MEETING_CREATED = 'meeting-created';
29+
case MEETING_ENDED = 'meeting-ended';
30+
case MEETING_RECORDING_STARTED = 'meeting-recording-started';
31+
case MEETING_RECORDING_STOPPED = 'meeting-recording-stopped';
32+
case MEETING_RECORDING_UNHANDLED = 'meeting-recording-unhandled';
33+
case MEETING_SCREENSHARE_STARTED = 'meeting-screenshare-started';
34+
case MEETING_SCREENSHARE_STOPPED = 'meeting-screenshare-stopped';
35+
case MEETING_PRESENTATION_CHANGED = 'meeting-presentation-changed';
36+
case USER_JOINED = 'user-joined';
37+
case USER_LEFT = 'user-left';
38+
case USER_AUDIO_VOICE_ENABLED = 'user-audio-voice-enabled';
39+
case USER_AUDIO_VOICE_DISABLED = 'user-audio-voice-disabled';
40+
case USER_AUDIO_MUTED = 'user-audio-muted';
41+
case USER_AUDIO_UNMUTED = 'user-audio-unmuted';
42+
case USER_AUDIO_UNHANDLED = 'user-audio-unhandled';
43+
case USER_CAM_BROADCAST_START = 'user-cam-broadcast-start';
44+
case USER_CAM_BROADCAST_END = 'user-cam-broadcast-end';
45+
case USER_PRESENTER_ASSIGNED = 'user-presenter-assigned';
46+
case USER_PRESENTER_UNASSIGNED = 'user-presenter-unassigned';
47+
case USER_EMOJI_CHANGED = 'user-emoji-changed';
48+
case USER_RAISE_HAND_CHANGED = 'user-raise-hand-changed';
49+
case CHAT_GROUP_MESSAGE_SENT = 'chat-group-message-sent';
50+
case RAP_PUBLISHED = 'rap-published';
51+
case RAP_UNPUBLISHED = 'rap-unpublished';
52+
case RAP_DELETED = 'rap-deleted';
53+
case PAD_CONTENT = 'pad-content';
54+
case RAP_ARCHIVE_STARTED = 'rap-archive-started';
55+
case RAP_ARCHIVE_ENDED = 'rap-archive-ended';
56+
case RAP_SANITY_STARTED = 'rap-sanity-started';
57+
case RAP_SANITY_ENDED = 'rap-sanity-ended';
58+
case RAP_POST_ARCHIVE_STARTED = 'rap-post-archive-started';
59+
case RAP_POST_ARCHIVE_ENDED = 'rap-post-archive-ended';
60+
case RAP_PROCESS_STARTED = 'rap-process-started';
61+
case RAP_PROCESS_ENDED = 'rap-process-ended';
62+
case RAP_POST_PROCESS_STARTED = 'rap-post-process-started';
63+
case RAP_POST_PROCESS_ENDED = 'rap-post-process-ended';
64+
case RAP_PUBLISH_STARTED = 'rap-publish-started';
65+
case RAP_PUBLISH_ENDED = 'rap-publish-ended';
66+
case RAP_POST_PUBLISH_STARTED = 'rap-post-publish-started';
67+
case RAP_POST_PUBLISH_ENDED = 'rap-post-publish-ended';
68+
case POLL_STARTED = 'poll-started';
69+
case POLL_RESPONDED = 'poll-responded';
70+
}

src/Parameters/HooksCreateParameters.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@
2121
namespace BigBlueButton\Parameters;
2222

2323
use BigBlueButton\Attribute\ApiParameterMapper;
24+
use BigBlueButton\Enum\WebHookEvent;
2425

2526
class HooksCreateParameters extends BaseParameters
2627
{
2728
private string $callbackUrl;
2829

2930
private ?string $meetingId = null;
3031

31-
private ?string $eventId = null;
32+
/**
33+
* @var WebHookEvent[]
34+
*/
35+
private array $eventId = [];
3236

3337
private ?bool $getRaw = null;
3438

@@ -63,12 +67,21 @@ public function setMeetingId(string $meetingId): self
6367
return $this;
6468
}
6569

66-
public function getEventId(): ?string
70+
/**
71+
* @return WebHookEvent[]
72+
*/
73+
#[ApiParameterMapper(attributeName: 'eventID')]
74+
public function getEventId(): array
6775
{
6876
return $this->eventId;
6977
}
7078

71-
public function setEventId(string $eventId): self
79+
/**
80+
* @param WebHookEvent[] $eventId
81+
*
82+
* @since 2.5
83+
*/
84+
public function setEventId(array $eventId): self
7285
{
7386
$this->eventId = $eventId;
7487

tests/Parameters/HooksCreateParametersTest.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,52 @@
2020

2121
namespace BigBlueButton\Parameters;
2222

23+
use BigBlueButton\Enum\WebHookEvent;
24+
use BigBlueButton\TestServices\Fixtures;
25+
2326
/**
2427
* @internal
2528
*/
2629
class HooksCreateParametersTest extends ParameterTestCase
2730
{
2831
public function testHooksCreateParameters(): void
2932
{
30-
// create string of eventIds
33+
$hooksCreateParameters = new HooksCreateParameters($callBackUrl = $this->faker->url);
34+
35+
// Get raw values from fixtures and ensure we have an array
36+
$rawEvents = (array) Fixtures::randomEnumValues($this->faker, WebHookEvent::class, null, 'array');
37+
38+
// Convert to WebHookEvent instances with proper type handling
3139
$eventIds = [];
32-
for ($i = 0; $i < $this->faker->numberBetween(1, 5); ++$i) {
33-
$eventIds[] = $this->faker->uuid;
34-
}
35-
$eventIds = implode(',', $eventIds);
40+
foreach ($rawEvents as $event) {
41+
if ($event instanceof WebHookEvent) {
42+
$eventIds[] = $event;
3643

37-
$hooksCreateParameters = new HooksCreateParameters($callBackUrl = $this->faker->url);
44+
continue;
45+
}
46+
47+
if (is_string($event)) {
48+
$eventIds[] = WebHookEvent::from($event);
49+
50+
continue;
51+
}
52+
53+
if (is_object($event) && method_exists($event, '__toString')) {
54+
$eventIds[] = WebHookEvent::from((string) $event);
55+
56+
continue;
57+
}
58+
59+
throw new \InvalidArgumentException('Invalid event type provided');
60+
}
3861

3962
$this->assertEquals($callBackUrl, $hooksCreateParameters->getCallbackUrl());
4063

41-
// Test setters that are ignored by the constructor
64+
// Test setters
4265
$hooksCreateParameters->setMeetingId($meetingId = $this->faker->uuid);
4366
$hooksCreateParameters->setGetRaw($getRaw = $this->faker->boolean);
4467
$hooksCreateParameters->setEventId($eventIds);
68+
4569
$this->assertEquals($meetingId, $hooksCreateParameters->getMeetingId());
4670
$this->assertEquals($getRaw, $hooksCreateParameters->getRaw());
4771
$this->assertEquals($eventIds, $hooksCreateParameters->getEventId());

tests/fixtures/responses/hooks_list.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<callbackURL><![CDATA[http://postcatcher.in/catchers/abcdefghijk]]></callbackURL>
77
<meetingID><![CDATA[my-meeting]]></meetingID>
88
<permanentHook>false</permanentHook>
9+
<eventID/>
910
<rawData>false</rawData>
1011
</hook>
1112
<hook>

0 commit comments

Comments
 (0)