Skip to content

Commit d431b7d

Browse files
committed
Implemented setConfigXML
1 parent 23b7def commit d431b7d

7 files changed

Lines changed: 230 additions & 9 deletions

File tree

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ before_script:
2525

2626
script:
2727
- mkdir -p build/logs
28-
- if [ "$TRAVIS_PHP_VERSION" == "5.4" ]; then phpunit; fi
2928
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then phpunit --coverage-clover build/logs/clover.xml; fi
3029
- if [ "$TRAVIS_PHP_VERSION" == "nightly" ]; then phpunit; fi
3130

src/BigBlueButton.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use BigBlueButton\Responses\IsMeetingRunningResponse;
4040
use BigBlueButton\Responses\JoinMeetingResponse;
4141
use BigBlueButton\Responses\PublishRecordingsResponse;
42+
use BigBlueButton\Responses\SetConfigXMLResponse;
4243
use BigBlueButton\Responses\UpdateRecordingsResponse;
4344
use BigBlueButton\Util\UrlBuilder;
4445
use SimpleXMLElement;
@@ -67,7 +68,9 @@ public function __construct()
6768
*/
6869
public function getApiVersion()
6970
{
70-
return new ApiVersionResponse($this->processXmlResponse($this->urlBuilder->buildUrl()));
71+
$xml = $this->processXmlResponse($this->urlBuilder->buildUrl());
72+
73+
return new ApiVersionResponse($xml);
7174
}
7275

7376
/* __________________ BBB ADMINISTRATION METHODS _________________ */
@@ -118,6 +121,27 @@ public function getDefaultConfigXML()
118121
return new GetDefaultConfigXMLResponse($xml);
119122
}
120123

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+
121145
/**
122146
* @param $joinMeetingParams JoinMeetingParameters
123147
*
@@ -333,7 +357,7 @@ public function updateRecordings($recordingParams)
333357
* @return SimpleXMLElement
334358
* @throws \RuntimeException
335359
*/
336-
private function processXmlResponse($url, $xml = '')
360+
private function processXmlResponse($url, $xml = '', $contentType = 'application/xml')
337361
{
338362
if (extension_loaded('curl')) {
339363
$ch = curl_init();
@@ -346,13 +370,13 @@ private function processXmlResponse($url, $xml = '')
346370
curl_setopt($ch, CURLOPT_URL, $url);
347371
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
348372
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
349-
if (count($xml) !== 0) {
373+
if ($xml != '') {
350374
curl_setopt($ch, CURLOPT_HEADER, 0);
351375
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
352376
curl_setopt($ch, CURLOPT_POST, 1);
353377
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
354378
curl_setopt($ch, CURLOPT_HTTPHEADER, [
355-
'Content-type: application/xml',
379+
'Content-type: ' . $contentType,
356380
'Content-length: ' . strlen($xml),
357381
]);
358382
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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\Parameters;
20+
21+
/**
22+
* Class SetConfigXMLParameters
23+
* @package BigBlueButton\Parameters
24+
*/
25+
class SetConfigXMLParameters extends BaseParameters
26+
{
27+
/**
28+
* @var string
29+
*/
30+
private $meetingId;
31+
32+
/**
33+
* @var \SimpleXMLElement
34+
*/
35+
private $rawXml;
36+
37+
/**
38+
* SetConfigXMLParameters constructor.
39+
*
40+
* @param $meetingId
41+
*/
42+
public function __construct($meetingId)
43+
{
44+
$this->meetingId = $meetingId;
45+
}
46+
47+
/**
48+
* @return string
49+
*/
50+
public function getMeetingId()
51+
{
52+
return $this->meetingId;
53+
}
54+
55+
/**
56+
* @param string $meetingId
57+
* @return SetConfigXMLParameters
58+
*/
59+
public function setMeetingId($meetingId)
60+
{
61+
$this->meetingId = $meetingId;
62+
63+
return $this;
64+
}
65+
66+
/**
67+
* @return string
68+
*/
69+
public function getRawXml()
70+
{
71+
return $this->rawXml;
72+
}
73+
74+
/**
75+
* @param \SimpleXMLElement $rawXml
76+
* @return SetConfigXMLParameters
77+
*/
78+
public function setRawXml($rawXml)
79+
{
80+
$this->rawXml = $rawXml;
81+
82+
return $this;
83+
}
84+
85+
/**
86+
* @return string
87+
*/
88+
public function getHTTPQuery()
89+
{
90+
return $this->buildHTTPQuery(
91+
[
92+
'configXML' => urlencode($this->rawXml->asXML()),
93+
'meetingID' => $this->meetingId,
94+
]
95+
);
96+
}
97+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Responses;
20+
21+
/**
22+
* Class SetConfigXMLResponse
23+
* @package BigBlueButton\Parameters
24+
*/
25+
class SetConfigXMLResponse extends BaseResponse
26+
{
27+
/**
28+
* @return bool
29+
*/
30+
public function getToken()
31+
{
32+
return $this->rawXml->token->__toString();
33+
}
34+
}

src/Util/UrlBuilder.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,29 @@ public function __construct($salt, $serverBaseUrl)
4646
}
4747

4848
/**
49-
* Builds an API method URL and generates its checksum.
49+
* Builds an API method URL that includes the url + params + its generated checksum.
5050
*
5151
* @param string $method
5252
* @param string $params
53+
* @param string $append
5354
*
5455
* @return string
5556
*/
56-
public function buildUrl($method = '', $params = '')
57+
public function buildUrl($method = '', $params = '', $append = true)
5758
{
58-
return $this->bbbServerBaseUrl.'api/'.$method.'?'.$params.'&checksum='.sha1($method.$params.$this->securitySalt);
59+
return $this->bbbServerBaseUrl.'api/'.$method.($append ? '?'.$this->buildQs($method, $params) : '');
5960
}
61+
62+
/**
63+
* Builds a query string for an API method URL that includes the params + its generated checksum.
64+
*
65+
* @param string $method
66+
* @param string $params
67+
*
68+
* @return string
69+
*/
70+
public function buildQs($method = '', $params = '')
71+
{
72+
return $params.'&checksum='.sha1($method.$params.$this->securitySalt);
73+
}
6074
}

tests/BigBlueButtonTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function testJoinMeeting()
148148
$this->bbb->joinMeeting($joinMeetingMock);
149149
}
150150

151-
/* Default Config XML */
151+
/* Get Default Config XML */
152152

153153
public function testGetDefaultConfigXMLUrl()
154154
{
@@ -162,6 +162,36 @@ public function testGetDefaultConfigXML()
162162
$this->assertNotNull($result->getRawXml());
163163
}
164164

165+
/* Set Config XML */
166+
167+
public function testSetConfigXMLUrl()
168+
{
169+
$url = $this->bbb->setConfigXMLUrl();
170+
$this->assertContains(ApiMethod::SET_CONFIG_XML, $url);
171+
}
172+
173+
public function testSetConfigXML()
174+
{
175+
// Fetch the Default Config XML file
176+
$defaultConfigXMLResponse = $this->bbb->getDefaultConfigXML();
177+
178+
// Modify the XML file if required
179+
180+
// Create a meeting
181+
$params = $this->generateCreateParams();
182+
$createMeetingResponse = $this->bbb->createMeeting($this->getCreateParamsMock($params));
183+
$this->assertEquals('SUCCESS', $createMeetingResponse->getReturnCode());
184+
185+
// Execute setConfigXML request
186+
$params = ['meetingId' => $createMeetingResponse->getMeetingId()];
187+
$setConfigXMLParams = $this->getSetConfigXMLMock($params);
188+
$setConfigXMLParams = $setConfigXMLParams->setRawXml($defaultConfigXMLResponse->getRawXml());
189+
190+
$result = $this->bbb->setConfigXML($setConfigXMLParams);
191+
$this->assertEquals('SUCCESS', $result->getReturnCode());
192+
$this->assertNotNull($result->getRawXml()->token->__toString());
193+
}
194+
165195
/* End Meeting */
166196

167197
/**

tests/TestCase.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use BigBlueButton\Parameters\CreateMeetingParameters as CreateMeetingParameters;
2222
use BigBlueButton\Parameters\EndMeetingParameters;
2323
use BigBlueButton\Parameters\JoinMeetingParameters as JoinMeetingParameters;
24+
use BigBlueButton\Parameters\SetConfigXMLParameters as SetConfigXMLParameters;
2425
use BigBlueButton\Parameters\UpdateRecordingsParameters as UpdateRecordingsParameters;
2526
use BigBlueButton\Responses\CreateMeetingResponse;
2627
use BigBlueButton\Responses\UpdateRecordingsResponse;
@@ -183,6 +184,28 @@ protected function getUpdateRecordingsParamsMock($params)
183184
return $updateRecordingsParams;
184185
}
185186

187+
/**
188+
* @return array
189+
*/
190+
protected function generateSetConfigXMLParams()
191+
{
192+
return [
193+
'meetingId' => $this->faker->uuid,
194+
];
195+
}
196+
197+
/**
198+
* @param $params array
199+
*
200+
* @return SetConfigXMLParameters
201+
*/
202+
protected function getSetConfigXMLMock($params)
203+
{
204+
$setConfigXMLParams = new SetConfigXMLParameters($params['meetingId']);
205+
206+
return $setConfigXMLParams;
207+
}
208+
186209
// Load fixtures
187210

188211
protected function loadXmlFile($path)

0 commit comments

Comments
 (0)