bbb_api.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. /*
  3. Copyright 2010 Blindside Networks
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Versions:
  16. 1.0 -- Initial version written by DJP
  17. (email: djp [a t ] architectes DOT .org)
  18. 1.1 -- Updated by Omar Shammas and Sebastian Schneider
  19. (email : omar DOT shammas [a t ] g m ail DOT com)
  20. (email : seb DOT sschneider [ a t ] g m ail DOT com)
  21. 1.2 -- Updated by Omar Shammas
  22. (email : omar DOT shammas [a t ] g m ail DOT com)
  23. 1.3 -- Refactored by Peter Mentzer
  24. (email : peter@petermentzerdesign.com)
  25. - This update will BREAK your external existing code if
  26. you've used the previous versions <= 1.2 already so:
  27. -- update your external code to use new method names if needed
  28. -- update your external code to pass new parameters to methods
  29. - Working example of joinIfRunning.php now included
  30. - Added support for BBB 0.8b recordings
  31. - Now using Zend coding, naming and style conventions
  32. - Refactored methods to accept standardized parameters & match BBB API structure
  33. -- See included samples for usage examples
  34. */
  35. /* _______________________________________________________________________*/
  36. /* get the config values */
  37. //require_once "config.php";
  38. class BigBlueButtonBN {
  39. private $_securitySalt;
  40. private $_bbbServerBaseUrl;
  41. /* ___________ General Methods for the BigBlueButton Class __________ */
  42. function __construct() {
  43. /*
  44. Establish just our basic elements in the constructor:
  45. */
  46. // BASE CONFIGS - set these for your BBB server in config.php and they will
  47. // simply flow in here via the constants:
  48. $this->_securitySalt = CONFIG_SECURITY_SALT;
  49. $this->_bbbServerBaseUrl = CONFIG_SERVER_BASE_URL;
  50. }
  51. private function _processXmlResponse($url){
  52. /*
  53. A private utility method used by other public methods to process XML responses.
  54. */
  55. if (extension_loaded('curl')) {
  56. $ch = curl_init() or die ( curl_error() );
  57. $timeout = 10;
  58. curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
  59. curl_setopt( $ch, CURLOPT_URL, $url );
  60. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  61. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  62. $data = curl_exec( $ch );
  63. curl_close( $ch );
  64. if($data)
  65. return (new SimpleXMLElement($data));
  66. else
  67. return false;
  68. }
  69. return (simplexml_load_file($url));
  70. }
  71. private function _requiredParam($param) {
  72. /* Process required params and throw errors if we don't get values */
  73. if ((isset($param)) && ($param != '')) {
  74. return $param;
  75. }
  76. elseif (!isset($param)) {
  77. throw new Exception('Missing parameter.');
  78. }
  79. else {
  80. throw new Exception(''.$param.' is required.');
  81. }
  82. }
  83. private function _optionalParam($param) {
  84. /* Pass most optional params through as set value, or set to '' */
  85. /* Don't know if we'll use this one, but let's build it in case. */
  86. if ((isset($param)) && ($param != '')) {
  87. return $param;
  88. }
  89. else {
  90. $param = '';
  91. return $param;
  92. }
  93. }
  94. /* __________________ BBB ADMINISTRATION METHODS _________________ */
  95. /* The methods in the following section support the following categories of the BBB API:
  96. -- create
  97. -- join
  98. -- end
  99. */
  100. public function getCreateMeetingUrl($creationParams) {
  101. /*
  102. USAGE:
  103. (see $creationParams array in createMeetingArray method.)
  104. */
  105. $this->_meetingId = $this->_requiredParam($creationParams['meetingId']);
  106. $this->_meetingName = $this->_requiredParam($creationParams['meetingName']);
  107. // Set up the basic creation URL:
  108. $creationUrl = $this->_bbbServerBaseUrl."api/create?";
  109. // Add params:
  110. $params =
  111. 'name='.urlencode($this->_meetingName).
  112. '&meetingID='.urlencode($this->_meetingId).
  113. '&attendeePW='.urlencode($creationParams['attendeePw']).
  114. '&moderatorPW='.urlencode($creationParams['moderatorPw']).
  115. '&dialNumber='.urlencode($creationParams['dialNumber']).
  116. '&voiceBridge='.urlencode($creationParams['voiceBridge']).
  117. '&webVoice='.urlencode($creationParams['webVoice']).
  118. '&logoutURL='.urlencode($creationParams['logoutUrl']).
  119. '&maxParticipants='.urlencode($creationParams['maxParticipants']).
  120. '&record='.urlencode($creationParams['record']).
  121. '&duration='.urlencode($creationParams['duration']);
  122. //'&meta_category='.urlencode($creationParams['meta_category']);
  123. $welcomeMessage = $creationParams['welcomeMsg'];
  124. if(trim($welcomeMessage))
  125. $params .= '&welcome='.urlencode($welcomeMessage);
  126. // Return the complete URL:
  127. return ( $creationUrl.$params.'&checksum='.sha1("create".$params.$this->_securitySalt) );
  128. }
  129. public function createMeetingWithXmlResponseArray($creationParams) {
  130. /*
  131. USAGE:
  132. $creationParams = array(
  133. 'name' => 'Meeting Name', -- A name for the meeting (or username)
  134. 'meetingId' => '1234', -- A unique id for the meeting
  135. 'attendeePw' => 'ap', -- Set to 'ap' and use 'ap' to join = no user pass required.
  136. 'moderatorPw' => 'mp', -- Set to 'mp' and use 'mp' to join = no user pass required.
  137. 'welcomeMsg' => '', -- ''= use default. Change to customize.
  138. 'dialNumber' => '', -- The main number to call into. Optional.
  139. 'voiceBridge' => '', -- 5 digits PIN to join voice. Required.
  140. 'webVoice' => '', -- Alphanumeric to join voice. Optional.
  141. 'logoutUrl' => '', -- Default in bigbluebutton.properties. Optional.
  142. 'maxParticipants' => '-1', -- Optional. -1 = unlimitted. Not supported in BBB. [number]
  143. 'record' => 'false', -- New. 'true' will tell BBB to record the meeting.
  144. 'duration' => '0', -- Default = 0 which means no set duration in minutes. [number]
  145. 'meta_category' => '', -- Use to pass additional info to BBB server. See API docs to enable.
  146. );
  147. */
  148. $xml = $this->_processXmlResponse($this->getCreateMeetingURL($creationParams));
  149. if($xml) {
  150. if($xml->meetingID)
  151. return array(
  152. 'returncode' => $xml->returncode,
  153. 'message' => $xml->message,
  154. 'messageKey' => $xml->messageKey,
  155. 'meetingId' => $xml->meetingID,
  156. 'attendeePw' => $xml->attendeePW,
  157. 'moderatorPw' => $xml->moderatorPW,
  158. 'hasBeenForciblyEnded' => $xml->hasBeenForciblyEnded,
  159. 'createTime' => $xml->createTime
  160. );
  161. else
  162. return array(
  163. 'returncode' => $xml->returncode,
  164. 'message' => $xml->message,
  165. 'messageKey' => $xml->messageKey
  166. );
  167. }
  168. else {
  169. return null;
  170. }
  171. }
  172. public function getJoinMeetingURL($joinParams) {
  173. /*
  174. NOTE: At this point, we don't use a corresponding joinMeetingWithXmlResponse here because the API
  175. doesn't respond on success, but you can still code that method if you need it. Or, you can take the URL
  176. that's returned from this method and simply send your users off to that URL in your code.
  177. USAGE:
  178. $joinParams = array(
  179. 'meetingId' => '1234', -- REQUIRED - A unique id for the meeting
  180. 'username' => 'Jane Doe', -- REQUIRED - The name that will display for the user in the meeting
  181. 'password' => 'ap', -- REQUIRED - The attendee or moderator password, depending on what's passed here
  182. 'createTime' => '', -- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  183. 'userID' => '', -- OPTIONAL - string
  184. 'webVoiceConf' => '' -- OPTIONAL - string
  185. );
  186. */
  187. $this->_meetingId = $this->_requiredParam($joinParams['meetingId']);
  188. $this->_username = $this->_requiredParam($joinParams['username']);
  189. $this->_password = $this->_requiredParam($joinParams['password']);
  190. // Establish the basic join URL:
  191. $joinUrl = $this->_bbbServerBaseUrl."api/join?";
  192. // Add parameters to the URL:
  193. $params =
  194. 'meetingID='.urlencode($this->_meetingId).
  195. '&fullName='.urlencode($this->_username).
  196. '&password='.urlencode($this->_password).
  197. '&userID='.urlencode($joinParams['userId']).
  198. '&webVoiceConf='.urlencode($joinParams['webVoiceConf']);
  199. // Only use createTime if we really want to use it. If it's '', then don't pass it:
  200. if (((isset($joinParams['createTime'])) && ($joinParams['createTime'] != ''))) {
  201. $params .= '&createTime='.urlencode($joinParams['createTime']);
  202. }
  203. // Return the URL:
  204. return ($joinUrl.$params.'&checksum='.sha1("join".$params.$this->_securitySalt));
  205. }
  206. public function getEndMeetingURL($endParams) {
  207. /* USAGE:
  208. $endParams = array (
  209. 'meetingId' => '1234', -- REQUIRED - The unique id for the meeting
  210. 'password' => 'mp' -- REQUIRED - The moderator password for the meeting
  211. );
  212. */
  213. $this->_meetingId = $this->_requiredParam($endParams['meetingId']);
  214. $this->_password = $this->_requiredParam($endParams['password']);
  215. $endUrl = $this->_bbbServerBaseUrl."api/end?";
  216. $params =
  217. 'meetingID='.urlencode($this->_meetingId).
  218. '&password='.urlencode($this->_password);
  219. return ($endUrl.$params.'&checksum='.sha1("end".$params.$this->_securitySalt));
  220. }
  221. public function endMeetingWithXmlResponseArray($endParams) {
  222. /* USAGE:
  223. $endParams = array (
  224. 'meetingId' => '1234', -- REQUIRED - The unique id for the meeting
  225. 'password' => 'mp' -- REQUIRED - The moderator password for the meeting
  226. );
  227. */
  228. $xml = $this->_processXmlResponse($this->getEndMeetingURL($endParams));
  229. if($xml) {
  230. return array(
  231. 'returncode' => $xml->returncode,
  232. 'message' => $xml->message,
  233. 'messageKey' => $xml->messageKey
  234. );
  235. }
  236. else {
  237. return null;
  238. }
  239. }
  240. /* __________________ BBB MONITORING METHODS _________________ */
  241. /* The methods in the following section support the following categories of the BBB API:
  242. -- isMeetingRunning
  243. -- getMeetings
  244. -- getMeetingInfo
  245. */
  246. public function getIsMeetingRunningUrl($meetingId) {
  247. /* USAGE:
  248. $meetingId = '1234' -- REQUIRED - The unique id for the meeting
  249. */
  250. $this->_meetingId = $this->_requiredParam($meetingId);
  251. $runningUrl = $this->_bbbServerBaseUrl."api/isMeetingRunning?";
  252. $params =
  253. 'meetingID='.urlencode($this->_meetingId);
  254. return ($runningUrl.$params.'&checksum='.sha1("isMeetingRunning".$params.$this->_securitySalt));
  255. }
  256. public function isMeetingRunningWithXmlResponseArray($meetingId) {
  257. /* USAGE:
  258. $meetingId = '1234' -- REQUIRED - The unique id for the meeting
  259. */
  260. $xml = $this->_processXmlResponse($this->getIsMeetingRunningUrl($meetingId));
  261. if($xml) {
  262. return array(
  263. 'returncode' => $xml->returncode,
  264. 'running' => $xml->running // -- Returns true/false.
  265. );
  266. }
  267. else {
  268. return null;
  269. }
  270. }
  271. public function getGetMeetingsUrl() {
  272. /* Simply formulate the getMeetings URL
  273. We do this in a separate function so we have the option to just get this
  274. URL and print it if we want for some reason.
  275. */
  276. $getMeetingsUrl = $this->_bbbServerBaseUrl."api/getMeetings?checksum=".sha1("getMeetings".$this->_securitySalt);
  277. return $getMeetingsUrl;
  278. }
  279. public function getMeetingsWithXmlResponseArray() {
  280. /* USAGE:
  281. We don't need to pass any parameters with this one, so we just send the query URL off to BBB
  282. and then handle the results that we get in the XML response.
  283. */
  284. $xml = $this->_processXmlResponse($this->getGetMeetingsUrl());
  285. if($xml) {
  286. // If we don't get a success code, stop processing and return just the returncode:
  287. if ($xml->returncode != 'SUCCESS') {
  288. $result = array(
  289. 'returncode' => $xml->returncode
  290. );
  291. return $result;
  292. }
  293. elseif ($xml->messageKey == 'noMeetings') {
  294. /* No meetings on server, so return just this info: */
  295. $result = array(
  296. 'returncode' => $xml->returncode,
  297. 'messageKey' => $xml->messageKey,
  298. 'message' => $xml->message
  299. );
  300. return $result;
  301. }
  302. else {
  303. // In this case, we have success and meetings. First return general response:
  304. $result = array(
  305. 'returncode' => $xml->returncode,
  306. 'messageKey' => $xml->messageKey,
  307. 'message' => $xml->message
  308. );
  309. // Then interate through meeting results and return them as part of the array:
  310. foreach ($xml->meetings->meeting as $m) {
  311. $result[] = array(
  312. 'meetingId' => $m->meetingID,
  313. 'meetingName' => $m->meetingName,
  314. 'createTime' => $m->createTime,
  315. 'attendeePw' => $m->attendeePW,
  316. 'moderatorPw' => $m->moderatorPW,
  317. 'hasBeenForciblyEnded' => $m->hasBeenForciblyEnded,
  318. 'running' => $m->running
  319. );
  320. }
  321. return $result;
  322. }
  323. }
  324. else {
  325. return null;
  326. }
  327. }
  328. public function getMeetingInfoUrl($infoParams) {
  329. /* USAGE:
  330. $infoParams = array(
  331. 'meetingId' => '1234', -- REQUIRED - The unique id for the meeting
  332. 'password' => 'mp' -- REQUIRED - The moderator password for the meeting
  333. );
  334. */
  335. $this->_meetingId = $this->_requiredParam($infoParams['meetingId']);
  336. $this->_password = $this->_requiredParam($infoParams['password']);
  337. $infoUrl = $this->_bbbServerBaseUrl."api/getMeetingInfo?";
  338. $params =
  339. 'meetingID='.urlencode($this->_meetingId).
  340. '&password='.urlencode($this->_password);
  341. return ($infoUrl.$params.'&checksum='.sha1("getMeetingInfo".$params.$this->_securitySalt));
  342. }
  343. public function getMeetingInfoWithXmlResponseArray($infoParams) {
  344. /* USAGE:
  345. $infoParams = array(
  346. 'meetingId' => '1234', -- REQUIRED - The unique id for the meeting
  347. 'password' => 'mp' -- REQUIRED - The moderator password for the meeting
  348. );
  349. */
  350. $xml = $this->_processXmlResponse($this->getMeetingInfoUrl($infoParams));
  351. if($xml) {
  352. // If we don't get a success code or messageKey, find out why:
  353. if (($xml->returncode != 'SUCCESS') || ($xml->messageKey == null)) {
  354. $result = array(
  355. 'returncode' => $xml->returncode,
  356. 'messageKey' => $xml->messageKey,
  357. 'message' => $xml->message
  358. );
  359. return $result;
  360. }
  361. else {
  362. // In this case, we have success and meeting info:
  363. $result = array(
  364. 'returncode' => $xml->returncode,
  365. 'meetingName' => $xml->meetingName,
  366. 'meetingId' => $xml->meetingID,
  367. 'createTime' => $xml->createTime,
  368. 'voiceBridge' => $xml->voiceBridge,
  369. 'attendeePw' => $xml->attendeePW,
  370. 'moderatorPw' => $xml->moderatorPW,
  371. 'running' => $xml->running,
  372. 'recording' => $xml->recording,
  373. 'hasBeenForciblyEnded' => $xml->hasBeenForciblyEnded,
  374. 'startTime' => $xml->startTime,
  375. 'endTime' => $xml->endTime,
  376. 'participantCount' => $xml->participantCount,
  377. 'maxUsers' => $xml->maxUsers,
  378. 'moderatorCount' => $xml->moderatorCount,
  379. );
  380. // Then interate through attendee results and return them as part of the array:
  381. foreach ($xml->attendees->attendee as $a) {
  382. $result[] = array(
  383. 'userId' => $a->userID,
  384. 'fullName' => $a->fullName,
  385. 'role' => $a->role
  386. );
  387. }
  388. return $result;
  389. }
  390. }
  391. else {
  392. return null;
  393. }
  394. }
  395. /* __________________ BBB RECORDING METHODS _________________ */
  396. /* The methods in the following section support the following categories of the BBB API:
  397. -- getRecordings
  398. -- publishRecordings
  399. -- deleteRecordings
  400. */
  401. public function getRecordingsUrl($recordingParams) {
  402. /* USAGE:
  403. $recordingParams = array(
  404. 'meetingId' => '1234', -- OPTIONAL - comma separate if multiple ids
  405. );
  406. */
  407. $recordingsUrl = $this->_bbbServerBaseUrl."api/getRecordings?";
  408. $params =
  409. 'meetingID='.urlencode($recordingParams['meetingId']);
  410. return ($recordingsUrl.$params.'&checksum='.sha1("getRecordings".$params.$this->_securitySalt));
  411. }
  412. public function getRecordingsWithXmlResponseArray($recordingParams) {
  413. /* USAGE:
  414. $recordingParams = array(
  415. 'meetingId' => '1234', -- OPTIONAL - comma separate if multiple ids
  416. );
  417. NOTE: 'duration' DOES work when creating a meeting, so if you set duration
  418. when creating a meeting, it will kick users out after the duration. Should
  419. probably be required in user code when 'recording' is set to true.
  420. */
  421. $xml = $this->_processXmlResponse($this->getRecordingsUrl($recordingParams));
  422. if($xml) {
  423. // If we don't get a success code or messageKey, find out why:
  424. if (($xml->returncode != 'SUCCESS') || ($xml->messageKey == null)) {
  425. $result = array(
  426. 'returncode' => $xml->returncode,
  427. 'messageKey' => $xml->messageKey,
  428. 'message' => $xml->message
  429. );
  430. return $result;
  431. }
  432. else {
  433. // In this case, we have success and recording info:
  434. $result = array(
  435. 'returncode' => $xml->returncode,
  436. 'messageKey' => $xml->messageKey,
  437. 'message' => $xml->message
  438. );
  439. foreach ($xml->recordings->recording as $r) {
  440. $result[] = array(
  441. 'recordId' => $r->recordID,
  442. 'meetingId' => $r->meetingID,
  443. 'name' => $r->name,
  444. 'published' => $r->published,
  445. 'startTime' => $r->startTime,
  446. 'endTime' => $r->endTime,
  447. 'playbackFormatType' => $r->playback->format->type,
  448. 'playbackFormatUrl' => $r->playback->format->url,
  449. 'playbackFormatLength' => $r->playback->format->length,
  450. 'metadataTitle' => $r->metadata->title,
  451. 'metadataSubject' => $r->metadata->subject,
  452. 'metadataDescription' => $r->metadata->description,
  453. 'metadataCreator' => $r->metadata->creator,
  454. 'metadataContributor' => $r->metadata->contributor,
  455. 'metadataLanguage' => $r->metadata->language,
  456. // Add more here as needed for your app depending on your
  457. // use of metadata when creating recordings.
  458. );
  459. }
  460. return $result;
  461. }
  462. }
  463. else {
  464. return null;
  465. }
  466. }
  467. public function getPublishRecordingsUrl($recordingParams) {
  468. /* USAGE:
  469. $recordingParams = array(
  470. 'recordId' => '1234', -- REQUIRED - comma separate if multiple ids
  471. 'publish' => 'true', -- REQUIRED - boolean: true/false
  472. );
  473. */
  474. $recordingsUrl = $this->_bbbServerBaseUrl."api/publishRecordings?";
  475. $params =
  476. 'recordID='.urlencode($recordingParams['recordId']).
  477. '&publish='.urlencode($recordingParams['publish']);
  478. return ($recordingsUrl.$params.'&checksum='.sha1("publishRecordings".$params.$this->_securitySalt));
  479. }
  480. public function publishRecordingsWithXmlResponseArray($recordingParams) {
  481. /* USAGE:
  482. $recordingParams = array(
  483. 'recordId' => '1234', -- REQUIRED - comma separate if multiple ids
  484. 'publish' => 'true', -- REQUIRED - boolean: true/false
  485. );
  486. */
  487. $xml = $this->_processXmlResponse($this->getPublishRecordingsUrl($recordingParams));
  488. if($xml) {
  489. return array(
  490. 'returncode' => $xml->returncode,
  491. 'published' => $xml->published // -- Returns true/false.
  492. );
  493. }
  494. else {
  495. return null;
  496. }
  497. }
  498. public function getDeleteRecordingsUrl($recordingParams) {
  499. /* USAGE:
  500. $recordingParams = array(
  501. 'recordId' => '1234', -- REQUIRED - comma separate if multiple ids
  502. );
  503. */
  504. $recordingsUrl = $this->_bbbServerBaseUrl."api/deleteRecordings?";
  505. $params =
  506. 'recordID='.urlencode($recordingParams['recordId']);
  507. return ($recordingsUrl.$params.'&checksum='.sha1("deleteRecordings".$params.$this->_securitySalt));
  508. }
  509. public function deleteRecordingsWithXmlResponseArray($recordingParams) {
  510. /* USAGE:
  511. $recordingParams = array(
  512. 'recordId' => '1234', -- REQUIRED - comma separate if multiple ids
  513. );
  514. */
  515. $xml = $this->_processXmlResponse($this->getDeleteRecordingsUrl($recordingParams));
  516. if($xml) {
  517. return array(
  518. 'returncode' => $xml->returncode,
  519. 'deleted' => $xml->deleted // -- Returns true/false.
  520. );
  521. }
  522. else {
  523. return null;
  524. }
  525. }
  526. } // END OF BIGBLUEBUTTON CLASS
  527. ?>