• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

littleredbutton / bigbluebutton-api-php / 7969683768

20 Feb 2024 07:06AM UTC coverage: 94.533% (-0.3%) from 94.875%
7969683768

Pull #172

github

SamuelWei
Remove passwords in CreateMeetingResponse
Pull Request #172: Remove deprecations

1 of 1 new or added line in 1 file covered. (100.0%)

6 existing lines in 3 files now uncovered.

709 of 750 relevant lines covered (94.53%)

36.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.53
/src/BigBlueButton.php
1
<?php
2
/**
3
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
4
 *
5
 * Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
6
 *
7
 * This program is free software; you can redistribute it and/or modify it under the
8
 * terms of the GNU Lesser General Public License as published by the Free Software
9
 * Foundation; either version 3.0 of the License, or (at your option) any later
10
 * version.
11
 *
12
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License along
17
 * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
namespace BigBlueButton;
21

22
use BigBlueButton\Core\ApiMethod;
23
use BigBlueButton\Enum\HashingAlgorithm;
24
use BigBlueButton\Exceptions\ConfigException;
25
use BigBlueButton\Exceptions\NetworkException;
26
use BigBlueButton\Exceptions\ParsingException;
27
use BigBlueButton\Exceptions\RuntimeException;
28
use BigBlueButton\Http\Transport\CurlTransport;
29
use BigBlueButton\Http\Transport\TransportInterface;
30
use BigBlueButton\Http\Transport\TransportRequest;
31
use BigBlueButton\Parameters\CreateMeetingParameters;
32
use BigBlueButton\Parameters\DeleteRecordingsParameters;
33
use BigBlueButton\Parameters\EndMeetingParameters;
34
use BigBlueButton\Parameters\GetMeetingInfoParameters;
35
use BigBlueButton\Parameters\GetRecordingsParameters;
36
use BigBlueButton\Parameters\GetRecordingTextTracksParameters;
37
use BigBlueButton\Parameters\HooksCreateParameters;
38
use BigBlueButton\Parameters\HooksDestroyParameters;
39
use BigBlueButton\Parameters\InsertDocumentParameters;
40
use BigBlueButton\Parameters\IsMeetingRunningParameters;
41
use BigBlueButton\Parameters\JoinMeetingParameters;
42
use BigBlueButton\Parameters\PublishRecordingsParameters;
43
use BigBlueButton\Parameters\PutRecordingTextTrackParameters;
44
use BigBlueButton\Parameters\UpdateRecordingsParameters;
45
use BigBlueButton\Responses\ApiVersionResponse;
46
use BigBlueButton\Responses\CreateMeetingResponse;
47
use BigBlueButton\Responses\DeleteRecordingsResponse;
48
use BigBlueButton\Responses\EndMeetingResponse;
49
use BigBlueButton\Responses\GetMeetingInfoResponse;
50
use BigBlueButton\Responses\GetMeetingsResponse;
51
use BigBlueButton\Responses\GetRecordingsResponse;
52
use BigBlueButton\Responses\GetRecordingTextTracksResponse;
53
use BigBlueButton\Responses\HooksCreateResponse;
54
use BigBlueButton\Responses\HooksDestroyResponse;
55
use BigBlueButton\Responses\HooksListResponse;
56
use BigBlueButton\Responses\InsertDocumentResponse;
57
use BigBlueButton\Responses\IsMeetingRunningResponse;
58
use BigBlueButton\Responses\JoinMeetingResponse;
59
use BigBlueButton\Responses\PublishRecordingsResponse;
60
use BigBlueButton\Responses\PutRecordingTextTrackResponse;
61
use BigBlueButton\Responses\UpdateRecordingsResponse;
62
use BigBlueButton\Util\UrlBuilder;
63

64
/**
65
 * Class BigBlueButton.
66
 *
67
 * @final since 4.0.
68
 */
69
class BigBlueButton
70
{
71
    public const CONNECTION_ERROR_BASEURL = 1;
72
    public const CONNECTION_ERROR_SECRET = 2;
73

74
    /**
75
     * @var string
76
     */
77
    protected $securitySecret;
78

79
    /**
80
     * @var string
81
     */
82
    protected $bbbServerBaseUrl;
83

84
    /**
85
     * @var string
86
     */
87
    protected $hashingAlgorithm;
88

89
    /**
90
     * @var UrlBuilder
91
     */
92
    protected $urlBuilder;
93

94
    /**
95
     * @var string|null
96
     */
97
    protected $jSessionId;
98

99
    /**
100
     * @var int|null
101
     */
102
    protected $connectionError;
103

104
    /**
105
     * @var TransportInterface
106
     */
107
    protected $transport;
108

109
    /**
110
     * @param string|null             $baseUrl   (optional) If not given, it will be retrieved from the environment
111
     * @param string|null             $secret    (optional) If not given, it will be retrieved from the environment
112
     * @param TransportInterface|null $transport (optional) Use a custom transport for all HTTP requests. Will fallback to default CurlTransport.
113
     *
114
     * @throws ConfigException
115
     */
116
    public function __construct(?string $baseUrl = null, ?string $secret = null, ?TransportInterface $transport = null, string $hashingAlgorithm = HashingAlgorithm::SHA_1)
117
    {
118
        // Keeping backward compatibility with older deployed versions
119
        $this->securitySecret = $secret ?: getenv('BBB_SECURITY_SALT') ?: getenv('BBB_SECRET');
21✔
120
        $this->bbbServerBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL');
21✔
121

122
        $this->hashingAlgorithm = $hashingAlgorithm;
21✔
123

124
        if (empty($this->bbbServerBaseUrl)) {
21✔
125
            throw new ConfigException('Base url required');
1✔
126
        }
127

128
        $this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl, $this->hashingAlgorithm);
21✔
129
        $this->transport = $transport ?? CurlTransport::createWithDefaultOptions();
21✔
130
    }
131

132
    /**
133
     * @throws NetworkException
134
     * @throws ParsingException
135
     * @throws RuntimeException
136
     */
137
    public function getApiVersion(): ApiVersionResponse
138
    {
139
        $xml = $this->processXmlResponse($this->urlBuilder->buildUrl());
1✔
140

141
        return new ApiVersionResponse($xml);
1✔
142
    }
143

144
    /**
145
     * Check if connection to api can be established with the baseurl and secret.
146
     *
147
     * @return bool connection successful
148
     */
149
    public function isConnectionWorking(): bool
150
    {
151
        // Reset connection error
152
        $this->connectionError = null;
1✔
153

154
        try {
155
            $response = $this->isMeetingRunning(
1✔
156
                new IsMeetingRunningParameters('connection_check')
1✔
157
            );
1✔
158

159
            // url and secret working
160
            if ($response->success()) {
1✔
161
                return true;
1✔
162
            }
163

164
            // Checksum error - invalid secret
165
            if ($response->hasChecksumError()) {
1✔
166
                $this->connectionError = self::CONNECTION_ERROR_SECRET;
1✔
167

168
                return false;
1✔
169
            }
170

171
            // HTTP exception or XML parse
172
        } catch (\Exception $e) {
1✔
173
        }
174

175
        $this->connectionError = self::CONNECTION_ERROR_BASEURL;
1✔
176

177
        return false;
1✔
178
    }
179

180
    /**
181
     * Return connection error type.
182
     *
183
     * @return int|null Connection error (const CONNECTION_ERROR_BASEURL or CONNECTION_ERROR_SECRET)
184
     */
185
    public function getConnectionError(): ?int
186
    {
187
        return $this->connectionError;
1✔
188
    }
189

190
    /* __________________ BBB ADMINISTRATION METHODS _________________ */
191
    /* The methods in the following section support the following categories of the BBB API:
192
    -- create
193
    -- join
194
    -- end
195
    */
196

197
    public function getCreateMeetingUrl(CreateMeetingParameters $createMeetingParams): string
198
    {
199
        return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
4✔
200
    }
201

202
    /**
203
     * @throws NetworkException
204
     * @throws ParsingException
205
     * @throws RuntimeException
206
     */
207
    public function createMeeting(CreateMeetingParameters $createMeetingParams): CreateMeetingResponse
208
    {
209
        $xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML());
3✔
210

211
        return new CreateMeetingResponse($xml);
1✔
212
    }
213

214
    public function getJoinMeetingURL(JoinMeetingParameters $joinMeetingParams): string
215
    {
216
        return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
2✔
217
    }
218

219
    /**
220
     * @throws NetworkException
221
     * @throws ParsingException
222
     * @throws RuntimeException
223
     */
224
    public function joinMeeting(JoinMeetingParameters $joinMeetingParams): JoinMeetingResponse
225
    {
226
        $xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams));
1✔
227

228
        return new JoinMeetingResponse($xml);
1✔
229
    }
230

231
    public function getEndMeetingURL(EndMeetingParameters $endParams): string
232
    {
233
        return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
2✔
234
    }
235

236
    /**
237
     * @throws NetworkException
238
     * @throws ParsingException
239
     * @throws RuntimeException
240
     */
241
    public function endMeeting(EndMeetingParameters $endParams): EndMeetingResponse
242
    {
243
        $xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
1✔
244

245
        return new EndMeetingResponse($xml);
1✔
246
    }
247

248
    public function getIsMeetingRunningUrl(IsMeetingRunningParameters $meetingParams): string
249
    {
250
        return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
1✔
251
    }
252

253
    /**
254
     * @throws NetworkException
255
     * @throws ParsingException
256
     * @throws RuntimeException
257
     */
258
    public function isMeetingRunning(IsMeetingRunningParameters $meetingParams): IsMeetingRunningResponse
259
    {
260
        $xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
1✔
261

262
        return new IsMeetingRunningResponse($xml);
1✔
263
    }
264

265
    public function getMeetingsUrl(): string
266
    {
267
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
2✔
268
    }
269

270
    /**
271
     * @throws NetworkException
272
     * @throws ParsingException
273
     * @throws RuntimeException
274
     */
275
    public function getMeetings(): GetMeetingsResponse
276
    {
277
        $xml = $this->processXmlResponse($this->getMeetingsUrl());
1✔
278

279
        return new GetMeetingsResponse($xml);
1✔
280
    }
281

282
    public function getMeetingInfoUrl(GetMeetingInfoParameters $meetingParams): string
283
    {
284
        return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
×
285
    }
286

287
    /**
288
     * @throws NetworkException
289
     * @throws ParsingException
290
     * @throws RuntimeException
291
     */
292
    public function getMeetingInfo(GetMeetingInfoParameters $meetingParams): GetMeetingInfoResponse
293
    {
294
        $xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
×
295

296
        return new GetMeetingInfoResponse($xml);
×
297
    }
298

299
    public function getRecordingsUrl(GetRecordingsParameters $recordingsParams): string
300
    {
301
        return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
1✔
302
    }
303

304
    /**
305
     * @throws NetworkException
306
     * @throws ParsingException
307
     * @throws RuntimeException
308
     */
309
    public function getRecordings(GetRecordingsParameters $recordingParams): GetRecordingsResponse
310
    {
311
        $xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
×
312

313
        return new GetRecordingsResponse($xml);
×
314
    }
315

316
    public function getPublishRecordingsUrl(PublishRecordingsParameters $recordingParams): string
317
    {
318
        return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
1✔
319
    }
320

321
    /**
322
     * @throws NetworkException
323
     * @throws ParsingException
324
     * @throws RuntimeException
325
     */
326
    public function publishRecordings(PublishRecordingsParameters $recordingParams): PublishRecordingsResponse
327
    {
328
        $xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
×
329

330
        return new PublishRecordingsResponse($xml);
×
331
    }
332

333
    public function getDeleteRecordingsUrl(DeleteRecordingsParameters $recordingParams): string
334
    {
335
        return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
1✔
336
    }
337

338
    /**
339
     * @throws NetworkException
340
     * @throws ParsingException
341
     * @throws RuntimeException
342
     */
343
    public function deleteRecordings(DeleteRecordingsParameters $recordingParams): DeleteRecordingsResponse
344
    {
345
        $xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams));
×
346

347
        return new DeleteRecordingsResponse($xml);
×
348
    }
349

350
    public function getUpdateRecordingsUrl(UpdateRecordingsParameters $recordingParams): string
351
    {
352
        return $this->urlBuilder->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
1✔
353
    }
354

355
    /**
356
     * @throws NetworkException
357
     * @throws ParsingException
358
     * @throws RuntimeException
359
     */
360
    public function updateRecordings(UpdateRecordingsParameters $recordingParams): UpdateRecordingsResponse
361
    {
362
        $xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams));
×
363

364
        return new UpdateRecordingsResponse($xml);
×
365
    }
366

367
    public function getRecordingTextTracksUrl(GetRecordingTextTracksParameters $getRecordingTextTracksParams): string
368
    {
369
        return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDING_TEXT_TRACKS, $getRecordingTextTracksParams->getHTTPQuery());
1✔
370
    }
371

372
    /**
373
     * @throws NetworkException
374
     * @throws RuntimeException
375
     */
376
    public function getRecordingTextTracks(GetRecordingTextTracksParameters $getRecordingTextTracksParams): GetRecordingTextTracksResponse
377
    {
378
        return new GetRecordingTextTracksResponse(
1✔
379
            $this->processJsonResponse($this->getRecordingTextTracksUrl($getRecordingTextTracksParams))
1✔
380
        );
1✔
381
    }
382

383
    public function getPutRecordingTextTrackUrl(PutRecordingTextTrackParameters $putRecordingTextTrackParams): string
384
    {
385
        return $this->urlBuilder->buildUrl(ApiMethod::PUT_RECORDING_TEXT_TRACK, $putRecordingTextTrackParams->getHTTPQuery());
1✔
386
    }
387

388
    /**
389
     * @throws NetworkException
390
     * @throws RuntimeException
391
     */
392
    public function putRecordingTextTrack(PutRecordingTextTrackParameters $putRecordingTextTrackParams): PutRecordingTextTrackResponse
393
    {
394
        $url = $this->getPutRecordingTextTrackUrl($putRecordingTextTrackParams);
1✔
395
        $file = $putRecordingTextTrackParams->getFile();
1✔
396

397
        return new PutRecordingTextTrackResponse(
1✔
398
            $file === null ?
1✔
399
                $this->processJsonResponse($url) :
1✔
400
                $this->processJsonResponse($url, $file, $putRecordingTextTrackParams->getContentType())
1✔
401
        );
1✔
402
    }
403

404
    public function getHooksCreateUrl(HooksCreateParameters $hookCreateParams): string
405
    {
406
        return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_CREATE, $hookCreateParams->getHTTPQuery());
×
407
    }
408

409
    /**
410
     * @throws NetworkException
411
     * @throws RuntimeException
412
     * @throws ParsingException
413
     */
414
    public function hooksCreate(HooksCreateParameters $hookCreateParams): HooksCreateResponse
415
    {
416
        $xml = $this->processXmlResponse($this->getHooksCreateUrl($hookCreateParams));
×
417

418
        return new HooksCreateResponse($xml);
×
419
    }
420

421
    public function getHooksListUrl(): string
422
    {
423
        return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_LIST);
×
424
    }
425

426
    public function hooksList(): HooksListResponse
427
    {
UNCOV
428
        $xml = $this->processXmlResponse($this->getHooksListUrl());
×
429

430
        return new HooksListResponse($xml);
×
431
    }
432

433
    public function getHooksDestroyUrl(HooksDestroyParameters $hooksDestroyParams): string
434
    {
435
        return $this->urlBuilder->buildUrl(ApiMethod::HOOKS_DESTROY, $hooksDestroyParams->getHTTPQuery());
×
436
    }
437

438
    /**
439
     * @throws NetworkException
440
     * @throws RuntimeException
441
     * @throws ParsingException
442
     */
443
    public function hooksDestroy(HooksDestroyParameters $hooksDestroyParams): HooksDestroyResponse
444
    {
UNCOV
445
        $xml = $this->processXmlResponse($this->getHooksDestroyUrl($hooksDestroyParams));
×
446

UNCOV
447
        return new HooksDestroyResponse($xml);
×
448
    }
449

450
    public function getInsertDocumentUrl(InsertDocumentParameters $insertDocumentParams): string
451
    {
452
        return $this->urlBuilder->buildUrl(ApiMethod::INSERT_DOCUMENT, $insertDocumentParams->getHTTPQuery());
1✔
453
    }
454

455
    /**
456
     * @throws NetworkException
457
     * @throws ParsingException
458
     * @throws RuntimeException
459
     */
460
    public function insertDocument(InsertDocumentParameters $insertDocumentParams): InsertDocumentResponse
461
    {
462
        $xml = $this->processXmlResponse($this->getInsertDocumentUrl($insertDocumentParams), $insertDocumentParams->getPresentationsAsXML());
1✔
463

464
        return new InsertDocumentResponse($xml);
1✔
465
    }
466

467
    /* ____________________ SPECIAL METHODS ___________________ */
468

469
    public function getJSessionId(): ?string
470
    {
471
        return $this->jSessionId;
1✔
472
    }
473

474
    public function setJSessionId(string $jSessionId): void
475
    {
476
        $this->jSessionId = $jSessionId;
1✔
477
    }
478

479
    /* ____________________ INTERNAL CLASS METHODS ___________________ */
480

481
    /**
482
     * A private utility method used by other public methods to process XML responses.
483
     *
484
     * @throws NetworkException
485
     * @throws ParsingException
486
     * @throws RuntimeException
487
     */
488
    private function processXmlResponse(string $url, string $payload = '', string $contentType = 'application/xml'): \SimpleXMLElement
489
    {
490
        try {
491
            return new \SimpleXMLElement($this->requestUrl($url, $payload, $contentType));
9✔
492
        } catch (NetworkException|RuntimeException $e) {
3✔
493
            throw $e;
1✔
494
        } catch (\Throwable $e) {
2✔
495
            throw new ParsingException('Could not parse payload as XML', 0, $e);
2✔
496
        }
497
    }
498

499
    /**
500
     * A private utility method used by other public methods to process json responses.
501
     *
502
     * @throws RuntimeException|NetworkException
503
     */
504
    private function processJsonResponse(string $url, string $payload = '', string $contentType = 'application/json'): string
505
    {
506
        return $this->requestUrl($url, $payload, $contentType);
2✔
507
    }
508

509
    /**
510
     * A private utility method used by other public methods to request from the api.
511
     *
512
     * @return string Response body
513
     *
514
     * @throws RuntimeException|NetworkException
515
     */
516
    private function requestUrl(string $url, string $payload = '', string $contentType = 'application/xml'): string
517
    {
518
        $response = $this->transport->request(new TransportRequest($url, $payload, $contentType));
11✔
519

520
        if (null !== $sessionId = $response->getSessionId()) {
10✔
521
            $this->setJSessionId($sessionId);
1✔
522
        }
523

524
        return $response->getBody();
10✔
525
    }
526

527
    public function buildUrl(string $method = '', string $params = '', bool $append = true): string
528
    {
529
        return $this->urlBuilder->buildUrl($method, $params, $append);
1✔
530
    }
531
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc