Skip to content

Commit 6cfff31

Browse files
committed
Enable the use of dynamic API URL
1 parent 568ae13 commit 6cfff31

5 files changed

Lines changed: 125 additions & 30 deletions

File tree

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Specify the value of your BigBlueButton secret
1+
# Specify the Server Base URL of your BigBlueButton
22
BBB_SERVER_BASE_URL="https://test-install.blindsidenetworks.com/bigbluebutton/"
33

4-
# Specify the Server Base URL of your BigBlueButton
4+
# Specify the value of your BigBlueButton secret
55
BBB_SECRET="8cd8ef52e8e101574e400365b55e11a6"

src/BigBlueButton.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,28 @@
5959
*/
6060
class BigBlueButton
6161
{
62+
/**
63+
* @deprecated Replaced by getter/setter in UrlBuilder-class
64+
*/
6265
protected string $bbbSecret;
66+
67+
/**
68+
* @deprecated Replaced by getter/setter in UrlBuilder-class
69+
*/
6370
protected string $bbbBaseUrl;
64-
protected string $jSessionId;
65-
protected string $hashingAlgorithm;
6671

67-
protected UrlBuilder $urlBuilder;
72+
/**
73+
* @deprecated Replaced by getter/setter in UrlBuilder-class
74+
*/
75+
protected string $hashingAlgorithm;
6876

6977
/**
7078
* @var array<int, mixed>
7179
*/
7280
protected array $curlOpts = [];
7381
protected int $timeOut = 10;
82+
protected string $jSessionId;
83+
protected UrlBuilder $urlBuilder;
7484

7585
/**
7686
* @param null|array<string, mixed> $opts
@@ -94,11 +104,17 @@ public function __construct(?string $baseUrl = null, ?string $secret = null, ?ar
94104
// nor $this->bbbBaseUrl (only strings), thus FALSE will be converted automatically to an empty
95105
// string (''). Having a bool should be not possible due to the checks above and the automated
96106
// conversion, but PHPStan is still unhappy, so it's covered explicit by adding `?: ''`.
97-
$this->bbbBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL') ?: '';
98-
$this->bbbSecret = $secret ?: getenv('BBB_SECRET') ?: getenv('BBB_SECURITY_SALT') ?: '';
99-
$this->hashingAlgorithm = HashingAlgorithm::SHA_256;
100-
$this->urlBuilder = new UrlBuilder($this->bbbSecret, $this->bbbBaseUrl, $this->hashingAlgorithm);
101-
$this->curlOpts = $opts['curl'] ?? [];
107+
$bbbBaseUrl = $baseUrl ?: getenv('BBB_SERVER_BASE_URL') ?: '';
108+
$bbbSecret = $secret ?: getenv('BBB_SECRET') ?: getenv('BBB_SECURITY_SALT') ?: '';
109+
$hashingAlgorithm = HashingAlgorithm::SHA_256;
110+
111+
// initialize deprecated properties
112+
$this->bbbBaseUrl = $bbbBaseUrl;
113+
$this->bbbSecret = $bbbSecret;
114+
$this->hashingAlgorithm = $hashingAlgorithm;
115+
116+
$this->urlBuilder = new UrlBuilder($bbbSecret, $bbbBaseUrl, $hashingAlgorithm);
117+
$this->curlOpts = $opts['curl'] ?? [];
102118
}
103119

104120
/**
@@ -469,9 +485,9 @@ public function setTimeOut(int $TimeOutInSeconds): self
469485
}
470486

471487
/**
472-
* @deprecated Replaced by same function-name provided by UrlBuilder-BigBlueButton
488+
* @deprecated replaced by same function-name provided by UrlBuilder-BigBlueButton
473489
*
474-
* Public accessor for buildUrl.
490+
* Public accessor for buildUrl
475491
*/
476492
public function buildUrl(string $method = '', string $params = '', bool $append = true): string
477493
{

src/Util/UrlBuilder.php

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,81 @@
3636
use BigBlueButton\Parameters\PutRecordingTextTrackParameters;
3737
use BigBlueButton\Parameters\UpdateRecordingsParameters;
3838

39-
/**
40-
* Class UrlBuilder.
41-
*/
4239
class UrlBuilder
4340
{
41+
/** @deprecated Property will be private soon. Use setter/getter instead. */
4442
protected string $hashingAlgorithm;
4543

46-
private string $securitySalt;
44+
private string $secret;
4745

48-
private string $bbbServerBaseUrl;
46+
private string $serverBaseUrl;
4947

5048
public function __construct(string $secret, string $serverBaseUrl, string $hashingAlgorithm)
5149
{
52-
$this->securitySalt = $secret;
53-
$this->bbbServerBaseUrl = $serverBaseUrl;
54-
$this->hashingAlgorithm = $hashingAlgorithm;
50+
$this->setSecret($secret);
51+
$this->setServerBaseUrl($serverBaseUrl);
52+
$this->setHashingAlgorithm($hashingAlgorithm);
5553
}
5654

57-
/**
58-
* Sets the hashing algorithm.
59-
*/
60-
public function setHashingAlgorithm(string $hashingAlgorithm): void
55+
// Getters & Setters
56+
public function setSecret(string $secret): self
57+
{
58+
$this->secret = $secret;
59+
60+
return $this;
61+
}
62+
63+
public function getSecret(): string
64+
{
65+
return $this->secret;
66+
}
67+
68+
public function setServerBaseUrl(string $serverBaseUrl): self
69+
{
70+
// add trailing dir-separator if missing
71+
if ('/' != mb_substr($serverBaseUrl, -1)) {
72+
$serverBaseUrl .= '/';
73+
}
74+
75+
$this->serverBaseUrl = $serverBaseUrl;
76+
77+
return $this;
78+
}
79+
80+
public function getServerBaseUrl(): string
81+
{
82+
return $this->serverBaseUrl;
83+
}
84+
85+
public function setHashingAlgorithm(string $hashingAlgorithm): self
6186
{
6287
$this->hashingAlgorithm = $hashingAlgorithm;
88+
89+
return $this;
90+
}
91+
92+
public function getHashingAlgorithm(): string
93+
{
94+
return $this->hashingAlgorithm;
6395
}
6496

97+
// Basic functions
6598
/**
6699
* Builds an API method URL that includes the url + params + its generated checksum.
67100
*/
68101
public function buildUrl(string $method = '', string $params = '', bool $append = true): string
69102
{
70-
return $this->bbbServerBaseUrl . 'api/' . $method . ($append ? '?' . $this->buildQs($method, $params) : '');
103+
return $this->serverBaseUrl . 'api/' . $method . ($append ? '?' . $this->buildQs($method, $params) : '');
71104
}
72105

73106
/**
74107
* Builds a query string for an API method URL that includes the params + its generated checksum.
108+
*
109+
* @deprecated Function only used internal. Function will be private soon. No replacement.
75110
*/
76111
public function buildQs(string $method = '', string $params = ''): string
77112
{
78-
return $params . '&checksum=' . hash($this->hashingAlgorithm, $method . $params . $this->securitySalt);
113+
return $params . '&checksum=' . hash($this->hashingAlgorithm, $method . $params . $this->secret);
79114
}
80115

81116
// URL-Generators

tests/BigBlueButtonTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function testApiVersion(): void
8888
/**
8989
* @deprecated Test will be removed together with the deprecated function from BigBlueButton::class
9090
*
91-
* Test create meeting URL.
91+
* Test create meeting URL
9292
*/
9393
public function testCreateMeetingUrl(): void
9494
{
@@ -178,7 +178,7 @@ public function testCreateMeetingWithMultiDocument(): void
178178
/**
179179
* @deprecated Test will be removed together with the deprecated function from BigBlueButton::class
180180
*
181-
* Test create join meeting URL.
181+
* Test create join meeting URL
182182
*/
183183
public function testCreateJoinMeetingUrl(): void
184184
{
@@ -232,7 +232,7 @@ public function testJoinMeeting(): void
232232
/**
233233
* @deprecated Test will be removed together with the deprecated function from BigBlueButton::class
234234
*
235-
* Test generate end meeting URL.
235+
* Test generate end meeting URL
236236
*/
237237
public function testCreateEndMeetingUrl(): void
238238
{

tests/Util/UrlBuilderTest.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,51 @@ public function setUp(): void
4141
{
4242
parent::setUp();
4343

44-
$this->urlBuilder = new UrlBuilder('any text', 'any text', HashingAlgorithm::SHA_256);
44+
$this->urlBuilder = new UrlBuilder('any secret', 'any url', HashingAlgorithm::SHA_256);
45+
}
46+
47+
public function testSecret(): void
48+
{
49+
// arrange
50+
$newSecret = $this->faker->password(128);
51+
52+
// initial value
53+
$this->assertEquals('any secret', $this->urlBuilder->getSecret());
54+
55+
// set new value
56+
$this->urlBuilder->setSecret($newSecret);
57+
$this->assertEquals($newSecret, $this->urlBuilder->getSecret());
58+
}
59+
60+
public function testServerBaseUrl(): void
61+
{
62+
// arrange
63+
$urlWithoutTrailingSeparator = $this->faker->url;
64+
$urlWithTrailingSeparator = $urlWithoutTrailingSeparator . '/';
65+
66+
// initial value
67+
$this->assertEquals('any url/', $this->urlBuilder->getServerBaseUrl());
68+
69+
// set value 1 (without)
70+
$this->urlBuilder->setServerBaseUrl($urlWithoutTrailingSeparator);
71+
$this->assertEquals($urlWithTrailingSeparator, $this->urlBuilder->getServerBaseUrl());
72+
73+
// set value 2 (with)
74+
$this->urlBuilder->setServerBaseUrl($urlWithTrailingSeparator);
75+
$this->assertEquals($urlWithTrailingSeparator, $this->urlBuilder->getServerBaseUrl());
76+
}
77+
78+
public function testHashingAlgorithm(): void
79+
{
80+
// arrange
81+
$newHashingAlgorithm = HashingAlgorithm::SHA_512;
82+
83+
// initial value
84+
$this->assertEquals(HashingAlgorithm::SHA_256, $this->urlBuilder->getHashingAlgorithm());
85+
86+
// set new value
87+
$this->urlBuilder->setHashingAlgorithm($newHashingAlgorithm);
88+
$this->assertEquals($newHashingAlgorithm, $this->urlBuilder->getHashingAlgorithm());
4589
}
4690

4791
public function testCreateMeetingUrl(): void

0 commit comments

Comments
 (0)