forked from bigbluebutton/bigbluebutton-api-php
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBigBlueButton.php
More file actions
564 lines (471 loc) · 20 KB
/
Copy pathBigBlueButton.php
File metadata and controls
564 lines (471 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<?php
declare(strict_types=1);
/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program 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.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton 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 BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/
namespace BigBlueButton;
use BigBlueButton\Enum\ApiMethod;
use BigBlueButton\Enum\HashingAlgorithm;
use BigBlueButton\Exceptions\ConfigException;
use BigBlueButton\Exceptions\NetworkException;
use BigBlueButton\Exceptions\ParsingException;
use BigBlueButton\Exceptions\RuntimeException;
use BigBlueButton\Http\Transport\CurlTransport;
use BigBlueButton\Http\Transport\TransportInterface;
use BigBlueButton\Http\Transport\TransportRequest;
use BigBlueButton\Parameters\CreateMeetingParameters;
use BigBlueButton\Parameters\DeleteRecordingsParameters;
use BigBlueButton\Parameters\EndMeetingParameters;
use BigBlueButton\Parameters\GetMeetingInfoParameters;
use BigBlueButton\Parameters\GetRecordingsParameters;
use BigBlueButton\Parameters\GetRecordingTextTracksParameters;
use BigBlueButton\Parameters\HooksCreateParameters;
use BigBlueButton\Parameters\HooksDestroyParameters;
use BigBlueButton\Parameters\HooksListParameters;
use BigBlueButton\Parameters\InsertDocumentParameters;
use BigBlueButton\Parameters\IsMeetingRunningParameters;
use BigBlueButton\Parameters\JoinMeetingParameters;
use BigBlueButton\Parameters\PublishRecordingsParameters;
use BigBlueButton\Parameters\PutRecordingTextTrackParameters;
use BigBlueButton\Parameters\SendChatMessageParameters;
use BigBlueButton\Parameters\UpdateRecordingsParameters;
use BigBlueButton\Responses\ApiVersionResponse;
use BigBlueButton\Responses\CreateMeetingResponse;
use BigBlueButton\Responses\DeleteRecordingsResponse;
use BigBlueButton\Responses\EndMeetingResponse;
use BigBlueButton\Responses\GetMeetingInfoResponse;
use BigBlueButton\Responses\GetMeetingsResponse;
use BigBlueButton\Responses\GetRecordingsResponse;
use BigBlueButton\Responses\GetRecordingTextTracksResponse;
use BigBlueButton\Responses\HooksCreateResponse;
use BigBlueButton\Responses\HooksDestroyResponse;
use BigBlueButton\Responses\HooksListResponse;
use BigBlueButton\Responses\InsertDocumentResponse;
use BigBlueButton\Responses\IsMeetingRunningResponse;
use BigBlueButton\Responses\JoinMeetingResponse;
use BigBlueButton\Responses\PublishRecordingsResponse;
use BigBlueButton\Responses\PutRecordingTextTrackResponse;
use BigBlueButton\Responses\SendChatMessageResponse;
use BigBlueButton\Responses\UpdateRecordingsResponse;
use BigBlueButton\Util\UrlBuilder;
/**
* Class BigBlueButton.
*
* @final since 4.0.
*/
class BigBlueButton
{
public const CONNECTION_ERROR_BASEURL = 1;
public const CONNECTION_ERROR_SECRET = 2;
protected string $securitySecret;
protected string $bbbServerBaseUrl;
protected UrlBuilder $urlBuilder;
protected ?string $jSessionId = null;
protected ?int $connectionError = null;
protected TransportInterface $transport;
/**
* @param string|null $baseUrl (optional) If not given, it will be retrieved from the environment
* @param string|null $secret (optional) If not given, it will be retrieved from the environment
* @param TransportInterface|null $transport (optional) Use a custom transport for all HTTP requests. Will fallback to default CurlTransport.
*
* @throws ConfigException
*/
public function __construct(?string $baseUrl = null, ?string $secret = null, ?TransportInterface $transport = null, protected HashingAlgorithm $hashingAlgorithm = HashingAlgorithm::SHA_1)
{
if (null === $baseUrl) {
@trigger_error(\sprintf('Constructing "%s" without passing a server base URL is deprecated and will throw an exception 6.0.', self::class), \E_USER_DEPRECATED);
}
if (null === $secret) {
@trigger_error(\sprintf('Constructing "%s" without passing a secret is deprecated and will throw an exception 6.0.', self::class), \E_USER_DEPRECATED);
}
if (getenv('BBB_SECURITY_SALT') !== false || getenv('BBB_SECRET') !== false) {
@trigger_error('Using BBB_SECURITY_SALT or BBB_SECRET environment variables is deprecated for security reasons and will be removed in 6.0. Use the constructor parameters instead.', \E_USER_DEPRECATED);
}
if (getenv('BBB_SERVER_BASE_URL') !== false) {
@trigger_error('Using BBB_SERVER_BASE_URL environment variable is deprecated for security reasons and will be removed in 6.0. Use the constructor parameters instead.', \E_USER_DEPRECATED);
}
// Keeping backward compatibility with older deployed versions
$securitySecret = $secret ?: getenv('BBB_SECURITY_SALT') ?: getenv('BBB_SECRET');
if (false === $securitySecret) {
// @codeCoverageIgnoreStart
@trigger_error(\sprintf('Constructing "%s" without passing a secret is deprecated since 6.0 and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED);
$this->securitySecret = ''; // previous behaviour
// @codeCoverageIgnoreEnd
} else {
$this->securitySecret = $securitySecret;
}
$bbbServerBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL');
if (false === $bbbServerBaseUrl) {
// @codeCoverageIgnoreStart
@trigger_error(\sprintf('Constructing "%s" without passing a server base URL is deprecated since 6.0 and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED);
$this->bbbServerBaseUrl = ''; // previous behaviour
// @codeCoverageIgnoreEnd
} else {
$this->bbbServerBaseUrl = $bbbServerBaseUrl;
}
if (empty($this->bbbServerBaseUrl)) {
throw new ConfigException('Base url required');
}
$this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl, $this->hashingAlgorithm);
$this->transport = $transport ?? CurlTransport::createWithDefaultOptions();
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function getApiVersion(): ApiVersionResponse
{
$xml = $this->processXmlResponse($this->urlBuilder->buildUrl());
return new ApiVersionResponse($xml);
}
/**
* Check if connection to api can be established with the baseurl and secret.
*
* @return bool connection successful
*/
public function isConnectionWorking(): bool
{
// Reset connection error
$this->connectionError = null;
try {
$response = $this->isMeetingRunning(
new IsMeetingRunningParameters('connection_check')
);
// url and secret working
if ($response->success()) {
return true;
}
// Checksum error - invalid secret
if ($response->hasChecksumError()) {
$this->connectionError = self::CONNECTION_ERROR_SECRET;
return false;
}
// HTTP exception or XML parse
} catch (\Exception) {
}
$this->connectionError = self::CONNECTION_ERROR_BASEURL;
return false;
}
/**
* Return connection error type.
*
* @return int|null Connection error (const CONNECTION_ERROR_BASEURL or CONNECTION_ERROR_SECRET)
*/
public function getConnectionError(): ?int
{
return $this->connectionError;
}
/* __________________ BBB ADMINISTRATION METHODS _________________ */
/* The methods in the following section support the following categories of the BBB API:
-- create
-- join
-- end
*/
public function getCreateMeetingUrl(CreateMeetingParameters $createMeetingParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function createMeeting(CreateMeetingParameters $createMeetingParams): CreateMeetingResponse
{
$xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getModules());
return new CreateMeetingResponse($xml);
}
public function getJoinMeetingURL(JoinMeetingParameters $joinMeetingParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function joinMeeting(JoinMeetingParameters $joinMeetingParams): JoinMeetingResponse
{
$xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams));
return new JoinMeetingResponse($xml);
}
public function getEndMeetingURL(EndMeetingParameters $endParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function endMeeting(EndMeetingParameters $endParams): EndMeetingResponse
{
$xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
return new EndMeetingResponse($xml);
}
public function getIsMeetingRunningUrl(IsMeetingRunningParameters $meetingParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function isMeetingRunning(IsMeetingRunningParameters $meetingParams): IsMeetingRunningResponse
{
$xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
return new IsMeetingRunningResponse($xml);
}
public function getMeetingsUrl(): string
{
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function getMeetings(): GetMeetingsResponse
{
$xml = $this->processXmlResponse($this->getMeetingsUrl());
return new GetMeetingsResponse($xml);
}
public function getMeetingInfoUrl(GetMeetingInfoParameters $meetingParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function getMeetingInfo(GetMeetingInfoParameters $meetingParams): GetMeetingInfoResponse
{
$xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
return new GetMeetingInfoResponse($xml);
}
public function getRecordingsUrl(GetRecordingsParameters $recordingsParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function getRecordings(GetRecordingsParameters $recordingParams): GetRecordingsResponse
{
$xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
return new GetRecordingsResponse($xml);
}
public function getPublishRecordingsUrl(PublishRecordingsParameters $recordingParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function publishRecordings(PublishRecordingsParameters $recordingParams): PublishRecordingsResponse
{
$xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
return new PublishRecordingsResponse($xml);
}
public function getDeleteRecordingsUrl(DeleteRecordingsParameters $recordingParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function deleteRecordings(DeleteRecordingsParameters $recordingParams): DeleteRecordingsResponse
{
$xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams));
return new DeleteRecordingsResponse($xml);
}
public function getUpdateRecordingsUrl(UpdateRecordingsParameters $recordingParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function updateRecordings(UpdateRecordingsParameters $recordingParams): UpdateRecordingsResponse
{
$xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams));
return new UpdateRecordingsResponse($xml);
}
public function getRecordingTextTracksUrl(GetRecordingTextTracksParameters $getRecordingTextTracksParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDING_TEXT_TRACKS, $getRecordingTextTracksParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws RuntimeException
*/
public function getRecordingTextTracks(GetRecordingTextTracksParameters $getRecordingTextTracksParams): GetRecordingTextTracksResponse
{
return new GetRecordingTextTracksResponse(
$this->processJsonResponse($this->getRecordingTextTracksUrl($getRecordingTextTracksParams))
);
}
public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $putRecordingTextTrackParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::PUT_RECORDING_TEXT_TRACK, $putRecordingTextTrackParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws RuntimeException
*/
public function putRecordingTextTrack(PutRecordingTextTrackParameters $putRecordingTextTrackParams): PutRecordingTextTrackResponse
{
$url = $this->getPutRecordingTextTrackUrl($putRecordingTextTrackParams);
$file = $putRecordingTextTrackParams->getFile();
return new PutRecordingTextTrackResponse(
$file === null ?
$this->processJsonResponse($url) :
$this->processJsonResponse($url, $file, $putRecordingTextTrackParams->getContentType())
);
}
public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws RuntimeException
* @throws ParsingException
*/
public function hooksCreate(HooksCreateParameters $hookCreateParams): HooksCreateResponse
{
$xml = $this->processXmlResponse($this->getHooksCreateUrl($hookCreateParams));
return new HooksCreateResponse($xml);
}
public function getHooksListUrl(HooksListParameters $hooksListParameters): string
{
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_LIST, $hooksListParameters->getHTTPQuery());
}
public function hooksList(HooksListParameters $hooksListParameters): HooksListResponse
{
$xml = $this->processXmlResponse($this->getHooksListUrl($hooksListParameters));
return new HooksListResponse($xml);
}
public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws RuntimeException
* @throws ParsingException
*/
public function hooksDestroy(HooksDestroyParameters $hooksDestroyParams): HooksDestroyResponse
{
$xml = $this->processXmlResponse($this->getHooksDestroyUrl($hooksDestroyParams));
return new HooksDestroyResponse($xml);
}
public function getInsertDocumentUrl(InsertDocumentParameters $insertDocumentParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::INSERT_DOCUMENT, $insertDocumentParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function insertDocument(InsertDocumentParameters $insertDocumentParams): InsertDocumentResponse
{
$xml = $this->processXmlResponse($this->getInsertDocumentUrl($insertDocumentParams), $insertDocumentParams->getPresentationsAsXML());
return new InsertDocumentResponse($xml);
}
public function getSendChatMessageUrl(SendChatMessageParameters $sendChatMessageParams): string
{
return $this->urlBuilder->buildUrl(ApiMethod::SEND_CHAT_MESSAGE, $sendChatMessageParams->getHTTPQuery());
}
/**
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
public function getSendChatMessage(SendChatMessageParameters $sendChatMessageParams): SendChatMessageResponse
{
$xml = $this->processXmlResponse($this->getSendChatMessageUrl($sendChatMessageParams));
return new SendChatMessageResponse($xml);
}
/* ____________________ SPECIAL METHODS ___________________ */
public function getJSessionId(): ?string
{
return $this->jSessionId;
}
public function setJSessionId(string $jSessionId): void
{
$this->jSessionId = $jSessionId;
}
/* ____________________ INTERNAL CLASS METHODS ___________________ */
/**
* A private utility method used by other public methods to process XML responses.
*
* @throws NetworkException
* @throws ParsingException
* @throws RuntimeException
*/
private function processXmlResponse(string $url, string $payload = '', string $contentType = 'application/xml'): \SimpleXMLElement
{
try {
return new \SimpleXMLElement($this->requestUrl($url, $payload, $contentType));
} catch (NetworkException|RuntimeException $e) {
throw $e;
} catch (\Throwable $e) {
throw new ParsingException('Could not parse payload as XML', 0, $e);
}
}
/**
* A private utility method used by other public methods to process json responses.
*
* @throws RuntimeException|NetworkException
*/
private function processJsonResponse(string $url, string $payload = '', string $contentType = 'application/json'): string
{
return $this->requestUrl($url, $payload, $contentType);
}
/**
* A private utility method used by other public methods to request from the api.
*
* @return string Response body
*
* @throws RuntimeException|NetworkException
*/
private function requestUrl(string $url, string $payload = '', string $contentType = 'application/xml'): string
{
$response = $this->transport->request(new TransportRequest($url, $payload, $contentType));
if (null !== $sessionId = $response->getSessionId()) {
$this->setJSessionId($sessionId);
}
return $response->getBody();
}
public function buildUrl(string $method = '', string $params = '', bool $append = true): string
{
return $this->urlBuilder->buildUrl($method, $params, $append);
}
}