1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 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
|
|
|
namespace BigBlueButton; |
20
|
|
|
|
21
|
|
|
use BigBlueButton\Core\ApiMethod; |
22
|
|
|
use BigBlueButton\Parameters\CreateMeetingParameters; |
23
|
|
|
use BigBlueButton\Parameters\DeleteRecordingsParameters; |
24
|
|
|
use BigBlueButton\Parameters\EndMeetingParameters; |
25
|
|
|
use BigBlueButton\Parameters\GetMeetingInfoParameters; |
26
|
|
|
use BigBlueButton\Parameters\GetRecordingsParameters; |
27
|
|
|
use BigBlueButton\Parameters\IsMeetingRunningParameters; |
28
|
|
|
use BigBlueButton\Parameters\JoinMeetingParameters; |
29
|
|
|
use BigBlueButton\Parameters\PublishRecordingsParameters; |
30
|
|
|
use BigBlueButton\Parameters\UpdateRecordingsParameters; |
31
|
|
|
use BigBlueButton\Responses\ApiVersionResponse; |
32
|
|
|
use BigBlueButton\Responses\CreateMeetingResponse; |
33
|
|
|
use BigBlueButton\Responses\DeleteRecordingsResponse; |
34
|
|
|
use BigBlueButton\Responses\EndMeetingResponse; |
35
|
|
|
use BigBlueButton\Responses\GetDefaultConfigXMLResponse; |
36
|
|
|
use BigBlueButton\Responses\GetMeetingInfoResponse; |
37
|
|
|
use BigBlueButton\Responses\GetMeetingsResponse; |
38
|
|
|
use BigBlueButton\Responses\GetRecordingsResponse; |
39
|
|
|
use BigBlueButton\Responses\IsMeetingRunningResponse; |
40
|
|
|
use BigBlueButton\Responses\JoinMeetingResponse; |
41
|
|
|
use BigBlueButton\Responses\PublishRecordingsResponse; |
42
|
|
|
use BigBlueButton\Responses\SetConfigXMLResponse; |
43
|
|
|
use BigBlueButton\Responses\UpdateRecordingsResponse; |
44
|
|
|
use BigBlueButton\Util\UrlBuilder; |
45
|
|
|
use SimpleXMLElement; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Class BigBlueButton |
49
|
|
|
* @package BigBlueButton |
50
|
|
|
*/ |
51
|
|
|
class BigBlueButton |
52
|
|
|
{ |
53
|
|
|
private $securitySalt; |
54
|
|
|
private $bbbServerBaseUrl; |
55
|
|
|
private $urlBuilder; |
56
|
|
|
|
57
|
|
|
public function __construct() |
58
|
|
|
{ |
59
|
|
|
$this->securitySalt = getenv('BBB_SECURITY_SALT'); |
60
|
|
|
$this->bbbServerBaseUrl = getenv('BBB_SERVER_BASE_URL'); |
61
|
|
|
$this->urlBuilder = new UrlBuilder($this->securitySalt, $this->bbbServerBaseUrl); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return ApiVersionResponse |
66
|
|
|
* |
67
|
|
|
* @throws \RuntimeException |
68
|
|
|
*/ |
69
|
|
|
public function getApiVersion() |
70
|
|
|
{ |
71
|
|
|
$xml = $this->processXmlResponse($this->urlBuilder->buildUrl()); |
72
|
|
|
|
73
|
|
|
return new ApiVersionResponse($xml); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/* __________________ BBB ADMINISTRATION METHODS _________________ */ |
77
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
78
|
|
|
-- create |
79
|
|
|
-- getDefaultConfigXML |
80
|
|
|
-- join |
81
|
|
|
-- end |
82
|
|
|
*/ |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param CreateMeetingParameters $createMeetingParams |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getCreateMeetingUrl($createMeetingParams) |
89
|
|
|
{ |
90
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param CreateMeetingParameters $createMeetingParams |
95
|
|
|
* @return CreateMeetingResponse |
96
|
|
|
* @throws \RuntimeException |
97
|
|
|
*/ |
98
|
|
|
public function createMeeting($createMeetingParams) |
99
|
|
|
{ |
100
|
|
|
$xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML()); |
|
|
|
|
101
|
|
|
|
102
|
|
|
return new CreateMeetingResponse($xml); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getDefaultConfigXMLUrl() |
109
|
|
|
{ |
110
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::GET_DEFAULT_CONFIG_XML); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return GetDefaultConfigXMLResponse |
115
|
|
|
* @throws \RuntimeException |
116
|
|
|
*/ |
117
|
|
|
public function getDefaultConfigXML() |
118
|
|
|
{ |
119
|
|
|
$xml = $this->processXmlResponse($this->getDefaultConfigXMLUrl()); |
120
|
|
|
|
121
|
|
|
return new GetDefaultConfigXMLResponse($xml); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function setConfigXMLUrl() |
128
|
|
|
{ |
129
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::SET_CONFIG_XML, '', false); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return SetConfigXMLResponse |
134
|
|
|
* @throws \RuntimeException |
135
|
|
|
*/ |
136
|
|
|
public function setConfigXML($setConfigXMLParams) |
137
|
|
|
{ |
138
|
|
|
$setConfigXMLPayload = $this->urlBuilder->buildQs(ApiMethod::SET_CONFIG_XML, $setConfigXMLParams->getHTTPQuery()); |
139
|
|
|
|
140
|
|
|
$xml = $this->processXmlResponse($this->setConfigXMLUrl(), $setConfigXMLPayload, 'application/x-www-form-urlencoded'); |
141
|
|
|
|
142
|
|
|
return new SetConfigXMLResponse($xml); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param $joinMeetingParams JoinMeetingParameters |
147
|
|
|
* |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
public function getJoinMeetingURL($joinMeetingParams) |
151
|
|
|
{ |
152
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery()); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param $joinMeetingParams JoinMeetingParameters |
157
|
|
|
* |
158
|
|
|
* @return JoinMeetingResponse |
159
|
|
|
* @throws \RuntimeException |
160
|
|
|
*/ |
161
|
|
|
public function joinMeeting($joinMeetingParams) |
162
|
|
|
{ |
163
|
|
|
$xml = $this->processXmlResponse($this->getJoinMeetingURL($joinMeetingParams)); |
164
|
|
|
|
165
|
|
|
return new JoinMeetingResponse($xml); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param $endParams EndMeetingParameters |
170
|
|
|
* |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getEndMeetingURL($endParams) |
174
|
|
|
{ |
175
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery()); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param $endParams EndMeetingParameters |
180
|
|
|
* |
181
|
|
|
* @return EndMeetingResponse |
182
|
|
|
* @throws \RuntimeException |
183
|
|
|
* */ |
184
|
|
|
public function endMeeting($endParams) |
185
|
|
|
{ |
186
|
|
|
$xml = $this->processXmlResponse($this->getEndMeetingURL($endParams)); |
187
|
|
|
|
188
|
|
|
return new EndMeetingResponse($xml); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/* __________________ BBB MONITORING METHODS _________________ */ |
192
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
193
|
|
|
-- isMeetingRunning |
194
|
|
|
-- getMeetings |
195
|
|
|
-- getMeetingInfo |
196
|
|
|
*/ |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param $meetingParams IsMeetingRunningParameters |
200
|
|
|
* @return string |
201
|
|
|
*/ |
202
|
|
|
public function getIsMeetingRunningUrl($meetingParams) |
203
|
|
|
{ |
204
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery()); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param $meetingParams |
209
|
|
|
* @return IsMeetingRunningResponse |
210
|
|
|
* @throws \RuntimeException |
211
|
|
|
*/ |
212
|
|
|
public function isMeetingRunning($meetingParams) |
213
|
|
|
{ |
214
|
|
|
$xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams)); |
215
|
|
|
|
216
|
|
|
return new IsMeetingRunningResponse($xml); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return string |
221
|
|
|
*/ |
222
|
|
|
public function getMeetingsUrl() |
223
|
|
|
{ |
224
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return GetMeetingsResponse |
229
|
|
|
* @throws \RuntimeException |
230
|
|
|
*/ |
231
|
|
|
public function getMeetings() |
232
|
|
|
{ |
233
|
|
|
$xml = $this->processXmlResponse($this->getMeetingsUrl()); |
234
|
|
|
|
235
|
|
|
return new GetMeetingsResponse($xml); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param $meetingParams GetMeetingInfoParameters |
240
|
|
|
* @return string |
241
|
|
|
*/ |
242
|
|
|
public function getMeetingInfoUrl($meetingParams) |
243
|
|
|
{ |
244
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETING_INFO, $meetingParams->getHTTPQuery()); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param $meetingParams GetMeetingInfoParameters |
249
|
|
|
* @return GetMeetingInfoResponse |
250
|
|
|
* @throws \RuntimeException |
251
|
|
|
*/ |
252
|
|
|
public function getMeetingInfo($meetingParams) |
253
|
|
|
{ |
254
|
|
|
$xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams)); |
255
|
|
|
|
256
|
|
|
return new GetMeetingInfoResponse($xml); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/* __________________ BBB RECORDING METHODS _________________ */ |
260
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
261
|
|
|
-- getRecordings |
262
|
|
|
-- publishRecordings |
263
|
|
|
-- deleteRecordings |
264
|
|
|
*/ |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param $recordingsParams GetRecordingsParameters |
268
|
|
|
* @return string |
269
|
|
|
*/ |
270
|
|
|
public function getRecordingsUrl($recordingsParams) |
271
|
|
|
{ |
272
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery()); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @param $recordingParams |
277
|
|
|
* @return GetRecordingsResponse |
278
|
|
|
* @throws \RuntimeException |
279
|
|
|
*/ |
280
|
|
|
public function getRecordings($recordingParams) |
281
|
|
|
{ |
282
|
|
|
$xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams)); |
283
|
|
|
|
284
|
|
|
return new GetRecordingsResponse($xml); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param $recordingParams PublishRecordingsParameters |
289
|
|
|
* @return string |
290
|
|
|
*/ |
291
|
|
|
public function getPublishRecordingsUrl($recordingParams) |
292
|
|
|
{ |
293
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery()); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @param $recordingParams PublishRecordingsParameters |
298
|
|
|
* @return PublishRecordingsResponse |
299
|
|
|
* @throws \RuntimeException |
300
|
|
|
*/ |
301
|
|
|
public function publishRecordings($recordingParams) |
302
|
|
|
{ |
303
|
|
|
$xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams)); |
304
|
|
|
|
305
|
|
|
return new PublishRecordingsResponse($xml); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @param $recordingParams DeleteRecordingsParameters |
310
|
|
|
* @return string |
311
|
|
|
*/ |
312
|
|
|
public function getDeleteRecordingsUrl($recordingParams) |
313
|
|
|
{ |
314
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery()); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @param $recordingParams DeleteRecordingsParameters |
319
|
|
|
* @return DeleteRecordingsResponse |
320
|
|
|
* @throws \RuntimeException |
321
|
|
|
*/ |
322
|
|
|
public function deleteRecordings($recordingParams) |
323
|
|
|
{ |
324
|
|
|
$xml = $this->processXmlResponse($this->getDeleteRecordingsUrl($recordingParams)); |
325
|
|
|
|
326
|
|
|
return new DeleteRecordingsResponse($xml); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* @param $recordingParams UpdateRecordingsParameters |
331
|
|
|
* @return string |
332
|
|
|
*/ |
333
|
|
|
public function getUpdateRecordingsUrl($recordingParams) |
334
|
|
|
{ |
335
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::UPDATE_RECORDINGS, $recordingParams->getHTTPQuery()); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @param $recordingParams UpdateRecordingsParameters |
340
|
|
|
* @return UpdateRecordingsResponse |
341
|
|
|
* @throws \RuntimeException |
342
|
|
|
*/ |
343
|
|
|
public function updateRecordings($recordingParams) |
344
|
|
|
{ |
345
|
|
|
$xml = $this->processXmlResponse($this->getUpdateRecordingsUrl($recordingParams)); |
346
|
|
|
|
347
|
|
|
return new UpdateRecordingsResponse($xml); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/* ____________________ INTERNAL CLASS METHODS ___________________ */ |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* A private utility method used by other public methods to process XML responses. |
354
|
|
|
* |
355
|
|
|
* @param string $url |
356
|
|
|
* @param string $xml |
357
|
|
|
* @return SimpleXMLElement |
358
|
|
|
* @throws \RuntimeException |
359
|
|
|
*/ |
360
|
|
|
private function processXmlResponse($url, $xml = '', $contentType = 'application/xml') |
361
|
|
|
{ |
362
|
|
|
if (extension_loaded('curl')) { |
363
|
|
|
$ch = curl_init(); |
364
|
|
|
if (!$ch) { |
365
|
|
|
throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch)); |
366
|
|
|
} |
367
|
|
|
$timeout = 10; |
368
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
369
|
|
|
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); |
370
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
371
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
372
|
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); |
373
|
|
|
if ($xml != '') { |
374
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0); |
375
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); |
376
|
|
|
curl_setopt($ch, CURLOPT_POST, 1); |
377
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); |
378
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [ |
379
|
|
|
'Content-type: ' . $contentType, |
380
|
|
|
'Content-length: ' . strlen($xml), |
381
|
|
|
]); |
382
|
|
|
} |
383
|
|
|
$data = curl_exec($ch); |
384
|
|
|
if ($data === false) { |
385
|
|
|
throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch)); |
386
|
|
|
} |
387
|
|
|
curl_close($ch); |
388
|
|
|
|
389
|
|
|
return new SimpleXMLElement($data); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
if ($xml != '') { |
393
|
|
|
throw new \RuntimeException('Post XML data set but curl PHP module is not installed or not enabled.'); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
try { |
397
|
|
|
$response = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS); |
398
|
|
|
|
399
|
|
|
return new SimpleXMLElement($response); |
400
|
|
|
} catch (\RuntimeException $e) { |
401
|
|
|
throw new \RuntimeException('Failover curl error: ' . $e->getMessage()); |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
|