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\Responses\ApiVersionResponse; |
31
|
|
|
use BigBlueButton\Responses\CreateMeetingResponse; |
32
|
|
|
use BigBlueButton\Responses\DeleteRecordingsResponse; |
33
|
|
|
use BigBlueButton\Responses\EndMeetingResponse; |
34
|
|
|
use BigBlueButton\Responses\GetDefaultConfigXMLResponse; |
35
|
|
|
use BigBlueButton\Responses\GetMeetingInfoResponse; |
36
|
|
|
use BigBlueButton\Responses\GetMeetingsResponse; |
37
|
|
|
use BigBlueButton\Responses\GetRecordingsResponse; |
38
|
|
|
use BigBlueButton\Responses\IsMeetingRunningResponse; |
39
|
|
|
use BigBlueButton\Responses\PublishRecordingsResponse; |
40
|
|
|
use BigBlueButton\Util\UrlBuilder; |
41
|
|
|
use SimpleXMLElement; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Class BigBlueButton |
45
|
|
|
* @package BigBlueButton |
46
|
|
|
*/ |
47
|
|
|
class BigBlueButton |
48
|
|
|
{ |
49
|
|
|
private $securitySalt; |
50
|
|
|
private $bbbServerBaseUrl; |
51
|
|
|
private $urlBuilder; |
52
|
|
|
|
53
|
|
|
public function __construct() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$this->securitySalt = $_SERVER['BBB_SECURITY_SALT']; |
56
|
|
|
$this->bbbServerBaseUrl = $_SERVER['BBB_SERVER_BASE_URL']; |
57
|
|
|
$this->urlBuilder = new UrlBuilder($this->securitySalt, $this->bbbServerBaseUrl); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return ApiVersionResponse |
62
|
|
|
* |
63
|
|
|
* @throws \Exception |
64
|
|
|
*/ |
65
|
|
|
public function getApiVersion() |
66
|
|
|
{ |
67
|
|
|
return new ApiVersionResponse($this->processXmlResponse($this->urlBuilder->buildUrl())); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/* __________________ BBB ADMINISTRATION METHODS _________________ */ |
71
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
72
|
|
|
-- create |
73
|
|
|
-- getDefaultConfigXML |
74
|
|
|
-- join |
75
|
|
|
-- end |
76
|
|
|
*/ |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param $createMeetingParams CreateMeetingParameters |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getCreateMeetingUrl($createMeetingParams) |
84
|
|
|
{ |
85
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::CREATE, $createMeetingParams->getHTTPQuery()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param CreateMeetingParameters $createMeetingParams |
90
|
|
|
* @return CreateMeetingResponse |
91
|
|
|
* @throws \Exception |
92
|
|
|
*/ |
93
|
|
|
public function createMeeting($createMeetingParams) |
94
|
|
|
{ |
95
|
|
|
$xml = $this->processXmlResponse($this->getCreateMeetingUrl($createMeetingParams), $createMeetingParams->getPresentationsAsXML()); |
|
|
|
|
96
|
|
|
|
97
|
|
|
return new CreateMeetingResponse($xml); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getDefaultConfigXMLUrl() |
104
|
|
|
{ |
105
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::GET_DEFAULT_CONFIG_XML); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* |
110
|
|
|
* @return GetDefaultConfigXMLResponse |
111
|
|
|
*/ |
112
|
|
|
public function getDefaultConfigXML() |
113
|
|
|
{ |
114
|
|
|
$xml = $this->processXmlResponse($this->getDefaultConfigXMLUrl()); |
115
|
|
|
|
116
|
|
|
return new GetDefaultConfigXMLResponse($xml); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param $joinMeetingParams JoinMeetingParameters |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getJoinMeetingURL($joinMeetingParams) |
125
|
|
|
{ |
126
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::JOIN, $joinMeetingParams->getHTTPQuery()); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param $endParams EndMeetingParameters |
131
|
|
|
* |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getEndMeetingURL($endParams) |
135
|
|
|
{ |
136
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::END, $endParams->getHTTPQuery()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param $endParams EndMeetingParameters |
141
|
|
|
* |
142
|
|
|
* @return EndMeetingResponse |
143
|
|
|
*/ |
144
|
|
|
public function endMeeting($endParams) |
145
|
|
|
{ |
146
|
|
|
$xml = $this->processXmlResponse($this->getEndMeetingURL($endParams)); |
147
|
|
|
|
148
|
|
|
return new EndMeetingResponse($xml); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/* __________________ BBB MONITORING METHODS _________________ */ |
152
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
153
|
|
|
-- isMeetingRunning |
154
|
|
|
-- getMeetings |
155
|
|
|
-- getMeetingInfo |
156
|
|
|
*/ |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param $meetingParams IsMeetingRunningParameters |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function getIsMeetingRunningUrl($meetingParams) |
163
|
|
|
{ |
164
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery()); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param $meetingParams |
169
|
|
|
* @return IsMeetingRunningResponse |
170
|
|
|
* @throws \Exception |
171
|
|
|
*/ |
172
|
|
|
public function isMeetingRunning($meetingParams) |
173
|
|
|
{ |
174
|
|
|
$xml = $this->processXmlResponse($this->getIsMeetingRunningUrl($meetingParams)); |
175
|
|
|
|
176
|
|
|
return new IsMeetingRunningResponse($xml); |
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return string |
181
|
|
|
*/ |
182
|
|
|
public function getMeetingsUrl() |
183
|
|
|
{ |
184
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::GET_MEETINGS); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return GetMeetingsResponse |
189
|
|
|
*/ |
190
|
|
|
public function getMeetings() |
191
|
|
|
{ |
192
|
|
|
$xml = $this->processXmlResponse($this->getMeetingsUrl()); |
193
|
|
|
|
194
|
|
|
return new GetMeetingsResponse($xml); |
|
|
|
|
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param $meetingParams GetMeetingInfoParameters |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
|
public function getMeetingInfoUrl($meetingParams) |
202
|
|
|
{ |
203
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::IS_MEETING_RUNNING, $meetingParams->getHTTPQuery()); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param $meetingParams GetMeetingInfoParameters |
208
|
|
|
* @return GetMeetingInfoResponse |
209
|
|
|
*/ |
210
|
|
|
public function getMeetingInfo($meetingParams) |
211
|
|
|
{ |
212
|
|
|
$xml = $this->processXmlResponse($this->getMeetingInfoUrl($meetingParams)); |
213
|
|
|
|
214
|
|
|
return new GetMeetingInfoResponse($xml); |
|
|
|
|
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/* __________________ BBB RECORDING METHODS _________________ */ |
218
|
|
|
/* The methods in the following section support the following categories of the BBB API: |
219
|
|
|
-- getRecordings |
220
|
|
|
-- publishRecordings |
221
|
|
|
-- deleteRecordings |
222
|
|
|
*/ |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param $recordingsParams GetRecordingsParameters |
226
|
|
|
* @return string |
227
|
|
|
*/ |
228
|
|
|
public function getRecordingsUrl($recordingsParams) |
229
|
|
|
{ |
230
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::GET_RECORDINGS, $recordingsParams->getHTTPQuery()); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @param $recordingParams |
235
|
|
|
* @return GetRecordingsResponse |
236
|
|
|
* @throws \Exception |
237
|
|
|
*/ |
238
|
|
|
public function getRecordings($recordingParams) |
239
|
|
|
{ |
240
|
|
|
$xml = $this->processXmlResponse($this->getRecordingsUrl($recordingParams)); |
241
|
|
|
|
242
|
|
|
return new GetRecordingsResponse($xml); |
|
|
|
|
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param $recordingParams PublishRecordingsParameters |
247
|
|
|
* @return string |
248
|
|
|
*/ |
249
|
|
|
public function getPublishRecordingsUrl($recordingParams) |
250
|
|
|
{ |
251
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::PUBLISH_RECORDINGS, $recordingParams->getHTTPQuery()); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @param $recordingParams PublishRecordingsParameters |
256
|
|
|
* @return PublishRecordingsResponse |
257
|
|
|
* @throws \Exception |
258
|
|
|
*/ |
259
|
|
|
public function publishRecordings($recordingParams) |
260
|
|
|
{ |
261
|
|
|
$xml = $this->processXmlResponse($this->getPublishRecordingsUrl($recordingParams)); |
262
|
|
|
|
263
|
|
|
return new PublishRecordingsResponse($xml); |
|
|
|
|
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param $recordingParams DeleteRecordingsParameters |
268
|
|
|
* @return string |
269
|
|
|
*/ |
270
|
|
|
public function deleteRecordingsUrl($recordingParams) |
271
|
|
|
{ |
272
|
|
|
return $this->urlBuilder->buildUrl(ApiMethod::DELETE_RECORDINGS, $recordingParams->getHTTPQuery()); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @param $recordingParams |
277
|
|
|
* @return DeleteRecordingsResponse |
278
|
|
|
* @throws \Exception |
279
|
|
|
*/ |
280
|
|
|
public function deleteRecordings($recordingParams) |
281
|
|
|
{ |
282
|
|
|
$xml = $this->processXmlResponse($this->deleteRecordingsUrl($recordingParams)); |
283
|
|
|
|
284
|
|
|
return new DeleteRecordingsResponse($xml); |
|
|
|
|
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/* ____________________ INTERNAL CLASS METHODS ___________________ */ |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* A private utility method used by other public methods to process XML responses. |
291
|
|
|
* |
292
|
|
|
* @param $url |
293
|
|
|
* @param string $xml |
294
|
|
|
* @return bool|SimpleXMLElement |
295
|
|
|
* @throws \Exception |
296
|
|
|
*/ |
297
|
|
|
private function processXmlResponse($url, $xml = '') |
298
|
|
|
{ |
299
|
|
|
/* |
300
|
|
|
|
301
|
|
|
*/ |
302
|
|
|
if (extension_loaded('curl')) { |
303
|
|
|
$ch = curl_init() or die(curl_error()); |
|
|
|
|
304
|
|
|
$timeout = 10; |
305
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
306
|
|
|
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); |
307
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
308
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
309
|
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); |
310
|
|
|
if (!empty($xml)) { |
311
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0); |
312
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); |
313
|
|
|
curl_setopt($ch, CURLOPT_POST, 1); |
314
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); |
315
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [ |
316
|
|
|
'Content-type: application/xml', |
317
|
|
|
'Content-length: ' . strlen($xml), |
318
|
|
|
]); |
319
|
|
|
} |
320
|
|
|
$data = curl_exec($ch); |
321
|
|
|
curl_close($ch); |
322
|
|
|
|
323
|
|
|
if ($data) { |
324
|
|
|
return new SimpleXMLElement($data); |
325
|
|
|
} else { |
326
|
|
|
return false; |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
if (!empty($xml)) { |
330
|
|
|
throw new \Exception('Set xml, but curl does not installed.'); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
return simplexml_load_file($url); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: