forked from bigbluebutton/bigbluebutton-api-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigBlueButton.php
More file actions
429 lines (376 loc) · 13.3 KB
/
BigBlueButton.php
File metadata and controls
429 lines (376 loc) · 13.3 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
<?php
/**
* 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\Core\ApiMethod;
use BigBlueButton\Parameters\CreateMeetingParameters;
use BigBlueButton\Parameters\DeleteRecordingsParameters;
use BigBlueButton\Parameters\EndMeetingParameters;
use BigBlueButton\Parameters\GetMeetingInfoParameters;
use BigBlueButton\Parameters\GetRecordingsParameters;
use BigBlueButton\Parameters\IsMeetingRunningParameters;
use BigBlueButton\Parameters\JoinMeetingParameters;
use BigBlueButton\Parameters\PublishRecordingsParameters;
use BigBlueButton\Parameters\UpdateRecordingsParameters;
use BigBlueButton\Responses\ApiVersionResponse;
use BigBlueButton\Responses\CreateMeetingResponse;
use BigBlueButton\Responses\DeleteRecordingsResponse;
use BigBlueButton\Responses\EndMeetingResponse;
use BigBlueButton\Responses\GetDefaultConfigXMLResponse;
use BigBlueButton\Responses\GetMeetingInfoResponse;
use BigBlueButton\Responses\GetMeetingsResponse;
use BigBlueButton\Responses\GetRecordingsResponse;
use BigBlueButton\Responses\IsMeetingRunningResponse;
use BigBlueButton\Responses\JoinMeetingResponse;
use BigBlueButton\Responses\PublishRecordingsResponse;
use BigBlueButton\Responses\SetConfigXMLResponse;
use BigBlueButton\Responses\UpdateRecordingsResponse;
use BigBlueButton\Util\UrlBuilder;
use SimpleXMLElement;
/**
* Class BigBlueButton
* @package BigBlueButton
*/
class BigBlueButton
{
protected $securitySecret;
protected $bbbServerBaseUrl;
protected $urlBuilder;
protected $jSessionId;
public function __construct()
{
// Keeping backward compatibility with older deployed versions
$this->securitySecret = (getenv('BBB_SECURITY_SALT') === false) ? getenv('BBB_SECRET') : $this->securitySecret = getenv('BBB_SECURITY_SALT');
$this->bbbServerBaseUrl = getenv('BBB_SERVER_BASE_URL');
$this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl);
}
/**
* @return ApiVersionResponse
*
* @throws \RuntimeException
*/
public function getApiVersion()
{
$xml = $this->processXmlResponse($this->urlBuilder->buildUrl());
return new ApiVersionResponse($xml);
}
/* __________________ BBB ADMINISTRATION METHODS _________________ */
/* The methods in the following section support the following categories of the BBB API:
-- create
-- getDefaultConfigXML
-- setConfigXML
-- join
-- end
*/
/**
* @param CreateMeetingParameters $createMeetingParams
* @return string
*/
public function getCreateMeetingUrl($createMeetingParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery());
}
/**
* @param CreateMeetingParameters $createMeetingParams
* @return CreateMeetingResponse
* @throws \RuntimeException
*/
public function createMeeting($createMeetingParams)
{
$xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML());
return new CreateMeetingResponse($xml);
}
/**
* @return string
*/
public function getDefaultConfigXMLUrl()
{
return $this->urlBuilder->buildUrl(ApiMethod::GET_DEFAULT_CONFIG_XML);
}
/**
* @return GetDefaultConfigXMLResponse
* @throws \RuntimeException
*/
public function getDefaultConfigXML()
{
$xml = $this->processXmlResponse($this->getDefaultConfigXMLUrl());
return new GetDefaultConfigXMLResponse($xml);
}
/**
* @return string
*/
public function setConfigXMLUrl()
{
return $this->urlBuilder->buildUrl(ApiMethod::SET_CONFIG_XML, '', false);
}
/**
* @param $setConfigXMLParams
* @return SetConfigXMLResponse
* @throws \RuntimeException
*/
public function setConfigXML($setConfigXMLParams)
{
$setConfigXMLPayload = $this->urlBuilder->buildQs(ApiMethod::SET_CONFIG_XML, $setConfigXMLParams->getHTTPQuery());
$xml = $this->processXmlResponse($this->setConfigXMLUrl(), $setConfigXMLPayload, 'application/x-www-form-urlencoded');
return new SetConfigXMLResponse($xml);
}
/**
* @param $joinMeetingParams JoinMeetingParameters
*
* @return string
*/
public function getJoinMeetingURL($joinMeetingParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery());
}
/**
* @param $joinMeetingParams JoinMeetingParameters
*
* @return JoinMeetingResponse
* @throws \RuntimeException
*/
public function joinMeeting($joinMeetingParams)
{
$xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams));
return new JoinMeetingResponse($xml);
}
/**
* @param $endParams EndMeetingParameters
*
* @return string
*/
public function getEndMeetingURL($endParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery());
}
/**
* @param $endParams EndMeetingParameters
*
* @return EndMeetingResponse
* @throws \RuntimeException
* */
public function endMeeting($endParams)
{
$xml = $this->processXmlResponse($this->getEndMeetingURL($endParams));
return new EndMeetingResponse($xml);
}
/* __________________ BBB MONITORING METHODS _________________ */
/* The methods in the following section support the following categories of the BBB API:
-- isMeetingRunning
-- getMeetings
-- getMeetingInfo
*/
/**
* @param $meetingParams IsMeetingRunningParameters
* @return string
*/
public function getIsMeetingRunningUrl($meetingParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery());
}
/**
* @param $meetingParams
* @return IsMeetingRunningResponse
* @throws \RuntimeException
*/
public function isMeetingRunning($meetingParams)
{
$xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams));
return new IsMeetingRunningResponse($xml);
}
/**
* @return string
*/
public function getMeetingsUrl()
{
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS);
}
/**
* @return GetMeetingsResponse
* @throws \RuntimeException
*/
public function getMeetings()
{
$xml = $this->processXmlResponse($this->getMeetingsUrl());
return new GetMeetingsResponse($xml);
}
/**
* @param $meetingParams GetMeetingInfoParameters
* @return string
*/
public function getMeetingInfoUrl($meetingParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery());
}
/**
* @param $meetingParams GetMeetingInfoParameters
* @return GetMeetingInfoResponse
* @throws \RuntimeException
*/
public function getMeetingInfo($meetingParams)
{
$xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams));
return new GetMeetingInfoResponse($xml);
}
/* __________________ BBB RECORDING METHODS _________________ */
/* The methods in the following section support the following categories of the BBB API:
-- getRecordings
-- publishRecordings
-- deleteRecordings
*/
/**
* @param $recordingsParams GetRecordingsParameters
* @return string
*/
public function getRecordingsUrl($recordingsParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery());
}
/**
* @param $recordingParams
* @return GetRecordingsResponse
* @throws \RuntimeException
*/
public function getRecordings($recordingParams)
{
$xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams));
return new GetRecordingsResponse($xml);
}
/**
* @param $recordingParams PublishRecordingsParameters
* @return string
*/
public function getPublishRecordingsUrl($recordingParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery());
}
/**
* @param $recordingParams PublishRecordingsParameters
* @return PublishRecordingsResponse
* @throws \RuntimeException
*/
public function publishRecordings($recordingParams)
{
$xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
return new PublishRecordingsResponse($xml);
}
/**
* @param $recordingParams DeleteRecordingsParameters
* @return string
*/
public function getDeleteRecordingsUrl($recordingParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery());
}
/**
* @param $recordingParams DeleteRecordingsParameters
* @return DeleteRecordingsResponse
* @throws \RuntimeException
*/
public function deleteRecordings($recordingParams)
{
$xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams));
return new DeleteRecordingsResponse($xml);
}
/**
* @param $recordingParams UpdateRecordingsParameters
* @return string
*/
public function getUpdateRecordingsUrl($recordingParams)
{
return $this->urlBuilder->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery());
}
/**
* @param $recordingParams UpdateRecordingsParameters
* @return UpdateRecordingsResponse
* @throws \RuntimeException
*/
public function updateRecordings($recordingParams)
{
$xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams));
return new UpdateRecordingsResponse($xml);
}
/* ____________________ SPECIAL METHODS ___________________ */
/**
* @return string
*/
public function getJSessionId()
{
return $this->jSessionId;
}
/**
* @param string $jSessionId
*/
public function setJSessionId($jSessionId)
{
$this->jSessionId = $jSessionId;
}
/* ____________________ INTERNAL CLASS METHODS ___________________ */
/**
* A private utility method used by other public methods to process XML responses.
*
* @param string $url
* @param string $payload
* @param string $contentType
* @return SimpleXMLElement
* @throws \RuntimeException
*/
private function processXmlResponse($url, $payload = '', $contentType = 'application/xml')
{
if (extension_loaded('curl')) {
$ch = curl_init();
if (!$ch) {
throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
}
$timeout = 10;
// Needed to store the JSESSIONID
$cookiefile = tmpfile();
$cookiefilepath = stream_get_meta_data($cookiefile)['uri'];
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefilepath);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefilepath);
if (!empty($payload)) {
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-type: ' . $contentType,
'Content-length: ' . mb_strlen($payload),
]);
}
$data = curl_exec($ch);
if ($data === false) {
throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
}
curl_close($ch);
$cookies = file_get_contents($cookiefilepath);
if (strpos($cookies, 'JSESSIONID') !== false) {
preg_match('/(?:JSESSIONID\s*)(?<JSESSIONID>.*)/', $cookies, $output_array);
$this->setJSessionId($output_array['JSESSIONID']);
}
return new SimpleXMLElement($data);
} else {
throw new \RuntimeException('Post XML data set but curl PHP module is not installed or not enabled.');
}
}
}