Skip to content

Commit b741c45

Browse files
committed
Store JSESSIONID if returned by the server.
1 parent 99caf67 commit b741c45

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/BigBlueButton.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ class BigBlueButton
5353
protected $securitySecret;
5454
protected $bbbServerBaseUrl;
5555
protected $urlBuilder;
56+
protected $jSessionId;
5657

5758
public function __construct()
5859
{
5960
// Keeping backward compatibility with older deployed versions
60-
$this->securitySecret = (getenv('BBB_SECURITY_SALT') === false) ? getenv('BBB_SECRET') : $this->securitySecret = getenv('BBB_SECURITY_SALT');
61+
$this->securitySecret = (getenv('BBB_SECURITY_SALT') === false) ? getenv('BBB_SECRET') : $this->securitySecret = getenv('BBB_SECURITY_SALT');
6162
$this->bbbServerBaseUrl = getenv('BBB_SERVER_BASE_URL');
6263
$this->urlBuilder = new UrlBuilder($this->securitySecret, $this->bbbServerBaseUrl);
6364
}
@@ -350,6 +351,23 @@ public function updateRecordings($recordingParams)
350351
return new UpdateRecordingsResponse($xml);
351352
}
352353

354+
/* ____________________ SPECIAL METHODS ___________________ */
355+
/**
356+
* @return string
357+
*/
358+
public function getJSessionId()
359+
{
360+
return $this->jSessionId;
361+
}
362+
363+
/**
364+
* @param string $jSessionId
365+
*/
366+
public function setJSessionId($jSessionId)
367+
{
368+
$this->jSessionId = $jSessionId;
369+
}
370+
353371
/* ____________________ INTERNAL CLASS METHODS ___________________ */
354372

355373
/**
@@ -369,11 +387,18 @@ private function processXmlResponse($url, $payload = '', $contentType = 'applica
369387
throw new \RuntimeException('Unhandled curl error: ' . curl_error($ch));
370388
}
371389
$timeout = 10;
390+
391+
// Needed to store the JSESSIONID
392+
$cookiefile = tmpfile();
393+
$cookiefilepath = stream_get_meta_data($cookiefile)['uri'];
394+
372395
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
373396
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
374397
curl_setopt($ch, CURLOPT_URL, $url);
375398
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
376399
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
400+
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefilepath);
401+
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefilepath);
377402
if (!empty($payload)) {
378403
curl_setopt($ch, CURLOPT_HEADER, 0);
379404
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
@@ -390,6 +415,12 @@ private function processXmlResponse($url, $payload = '', $contentType = 'applica
390415
}
391416
curl_close($ch);
392417

418+
$cookies = file_get_contents($cookiefilepath);
419+
if (strpos($cookies, 'JSESSIONID') !== false) {
420+
preg_match('/(?:JSESSIONID\s*)(?<JSESSIONID>.*)/', $cookies, $output_array);
421+
$this->setJSessionId($output_array['JSESSIONID']);
422+
}
423+
393424
return new SimpleXMLElement($data);
394425
} else {
395426
throw new \RuntimeException('Post XML data set but curl PHP module is not installed or not enabled.');

0 commit comments

Comments
 (0)