@@ -80,8 +80,8 @@ public function __construct(?string $baseUrl = null, ?string $secret = null, ?ar
8080 {
8181 // Keeping backward compatibility with older deployed versions
8282 // BBB_SECRET is the new variable name and have higher priority against the old named BBB_SECURITY_SALT
83- $ this ->securitySecret = $ secret ?: getenv ('BBB_SECRET ' ) ?: getenv ('BBB_SECURITY_SALT ' );
84- $ this ->bbbServerBaseUrl = $ baseUrl ?: getenv ('BBB_SERVER_BASE_URL ' );
83+ $ this ->securitySecret = $ secret ?: getenv ('BBB_SECRET ' ) ?: getenv ('BBB_SECURITY_SALT ' ) ?: '' ;
84+ $ this ->bbbServerBaseUrl = $ baseUrl ?: getenv ('BBB_SERVER_BASE_URL ' ) ?: '' ;
8585 $ this ->hashingAlgorithm = HashingAlgorithm::SHA_256 ;
8686 $ this ->urlBuilder = new UrlBuilder ($ this ->securitySecret , $ this ->bbbServerBaseUrl , $ this ->hashingAlgorithm );
8787 $ this ->curlOpts = $ opts ['curl ' ] ?? [];
@@ -117,7 +117,7 @@ public function getCreateMeetingUrl(CreateMeetingParameters $createMeetingParams
117117 }
118118
119119 /**
120- * @throws \RuntimeException
120+ * @throws BadResponseException| \RuntimeException
121121 */
122122 public function createMeeting (CreateMeetingParameters $ createMeetingParams ): CreateMeetingResponse
123123 {
@@ -186,7 +186,7 @@ public function getIsMeetingRunningUrl(IsMeetingRunningParameters $meetingParams
186186 /**
187187 * @param mixed $meetingParams
188188 *
189- * @throws \RuntimeException
189+ * @throws BadResponseException| \RuntimeException
190190 */
191191 public function isMeetingRunning ($ meetingParams ): IsMeetingRunningResponse
192192 {
@@ -201,7 +201,7 @@ public function getMeetingsUrl(): string
201201 }
202202
203203 /**
204- * @throws \RuntimeException
204+ * @throws BadResponseException| \RuntimeException
205205 */
206206 public function getMeetings (): GetMeetingsResponse
207207 {
@@ -410,65 +410,85 @@ public function buildUrl(string $method = '', string $params = '', bool $append
410410 */
411411 private function sendRequest (string $ url , string $ payload = '' , string $ contentType = 'application/xml ' ): string
412412 {
413- if (extension_loaded ('curl ' )) {
414- $ ch = curl_init ();
415- if (!$ ch ) { // @phpstan-ignore-line
416- throw new \RuntimeException ('Unhandled curl error: ' . curl_error ($ ch ));
417- }
413+ if (!extension_loaded ('curl ' )) {
414+ throw new \RuntimeException ('Post XML data set but curl PHP module is not installed or not enabled. ' );
415+ }
416+
417+ $ ch = curl_init ();
418+ $ cookieFile = tmpfile ();
418419
419- // Needed to store the JSESSIONID
420- $ cookieFile = tmpfile ();
420+ if (!$ ch ) { // @phpstan-ignore-line
421+ throw new \RuntimeException ('Unhandled curl error: ' . curl_error ($ ch ));
422+ }
423+
424+ // JSESSIONID
425+ if ($ cookieFile ) {
421426 $ cookieFilePath = stream_get_meta_data ($ cookieFile )['uri ' ];
427+ $ cookies = file_get_contents ($ cookieFilePath );
422428
423- foreach ($ this ->curlOpts as $ opt => $ value ) {
424- curl_setopt ($ ch , $ opt , $ value );
425- }
426- curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , 1 );
427- curl_setopt ($ ch , CURLOPT_ENCODING , 'UTF-8 ' );
428- curl_setopt ($ ch , CURLOPT_URL , $ url );
429- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
430- curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , 1 );
431- curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , $ this ->timeOut );
432429 curl_setopt ($ ch , CURLOPT_COOKIEFILE , $ cookieFilePath );
433430 curl_setopt ($ ch , CURLOPT_COOKIEJAR , $ cookieFilePath );
434- if (!empty ($ payload )) {
435- curl_setopt ($ ch , CURLOPT_HEADER , 0 );
436- curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , 'POST ' );
437- curl_setopt ($ ch , CURLOPT_POST , 1 );
438- curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ payload );
439- curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
440- 'Content-type: ' . $ contentType ,
441- 'Content-length: ' . mb_strlen ($ payload ),
442- ]);
443- }
444- $ data = curl_exec ($ ch );
445- if (false === $ data ) {
446- throw new \RuntimeException ('Unhandled curl error: ' . curl_error ($ ch ));
447- }
448- $ httpCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
449- if ($ httpCode < 200 || $ httpCode >= 300 ) {
450- throw new BadResponseException ('Bad response, HTTP code: ' . $ httpCode );
451- }
452- curl_close ($ ch );
453- unset($ ch );
454431
455- $ cookies = file_get_contents ($ cookieFilePath );
456- if (false !== mb_strpos ($ cookies , 'JSESSIONID ' )) {
457- preg_match ('/(?:JSESSIONID\s*)(?<JSESSIONID>.*)/ ' , $ cookies , $ output_array );
458- $ this ->setJSessionId ($ output_array ['JSESSIONID ' ]);
432+ if ($ cookies ) {
433+ if (false !== mb_strpos ($ cookies , 'JSESSIONID ' )) {
434+ preg_match ('/(?:JSESSIONID\s*)(?<JSESSIONID>.*)/ ' , $ cookies , $ output_array );
435+ $ this ->setJSessionId ($ output_array ['JSESSIONID ' ]);
436+ }
459437 }
438+ }
439+
440+ // PAYLOAD
441+ if (!empty ($ payload )) {
442+ curl_setopt ($ ch , CURLOPT_HEADER , 0 );
443+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , 'POST ' );
444+ curl_setopt ($ ch , CURLOPT_POST , 1 );
445+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ payload );
446+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , [
447+ 'Content-type: ' . $ contentType ,
448+ 'Content-length: ' . mb_strlen ($ payload ),
449+ ]);
450+ }
460451
461- return $ data ;
452+ // OTHERS
453+ foreach ($ this ->curlOpts as $ opt => $ value ) {
454+ curl_setopt ($ ch , $ opt , $ value );
455+ }
456+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , 1 );
457+ curl_setopt ($ ch , CURLOPT_ENCODING , 'UTF-8 ' );
458+ curl_setopt ($ ch , CURLOPT_URL , $ url );
459+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
460+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , 1 );
461+ curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , $ this ->timeOut );
462+
463+ // EXECUTE and RESULT
464+ $ data = curl_exec ($ ch );
465+ $ httpCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
466+
467+ // ANALYSE
468+ if (false === $ data ) {
469+ throw new \RuntimeException ('Unhandled curl error: ' . curl_error ($ ch ));
462470 }
463471
464- throw new \RuntimeException ('Post XML data set but curl PHP module is not installed or not enabled. ' );
472+ if (is_bool ($ data )) {
473+ throw new \RuntimeException ('Curl error: BOOL received, but STRING expected. ' );
474+ }
475+
476+ if ($ httpCode < 200 || $ httpCode >= 300 ) {
477+ throw new BadResponseException ('Bad response, HTTP code: ' . $ httpCode );
478+ }
479+
480+ // CLOSE AND UNSET
481+ curl_close ($ ch );
482+ unset($ ch );
483+
484+ // RETURN
485+ return $ data ;
465486 }
466487
467488 /**
468489 * A private utility method used by other public methods to process XML responses.
469490 *
470- * @throws BadResponseException
471- * @throws \Exception
491+ * @throws BadResponseException|\Exception
472492 */
473493 private function processXmlResponse (string $ url , string $ payload = '' , string $ contentType = 'application/xml ' ): \SimpleXMLElement
474494 {
0 commit comments