bbb.lib.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class bbb
  5. * This script initiates a video conference session, calling the BigBlueButton
  6. * API
  7. * @package chamilo.plugin.bigbluebutton
  8. *
  9. * BigBlueButton-Chamilo connector class
  10. */
  11. //namespace Chamilo\Plugin\BBB;
  12. /**
  13. * Class bbb
  14. * @package Chamilo\Plugin\BBB
  15. */
  16. class bbb
  17. {
  18. public $url;
  19. public $salt;
  20. public $api;
  21. public $user_complete_name = null;
  22. public $protocol = 'http://';
  23. public $debug = false;
  24. public $logout_url = null;
  25. public $plugin_enabled = false;
  26. /**
  27. *
  28. * Constructor (generates a connection to the API and the Chamilo settings
  29. * required for the connection to the video conference server)
  30. * @param string $host
  31. * @param string $salt
  32. */
  33. public function __construct($host = null, $salt = null)
  34. {
  35. // Initialize video server settings from global settings
  36. $plugin = BBBPlugin::create();
  37. $bbb_plugin = $plugin->get('tool_enable');
  38. if (empty($host)) {
  39. $bbb_host = $plugin->get('host');
  40. } else {
  41. $bbb_host = $host;
  42. }
  43. if (empty($salt)) {
  44. $bbb_salt = $plugin->get('salt');
  45. } else {
  46. $bbb_salt = $salt;
  47. }
  48. $this->logout_url = api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq();
  49. $this->table = Database::get_main_table('plugin_bbb_meeting');
  50. if ($bbb_plugin == true) {
  51. $userInfo = api_get_user_info();
  52. $this->user_complete_name = $userInfo['complete_name'];
  53. $this->salt = $bbb_salt;
  54. $info = parse_url($bbb_host);
  55. $this->url = $bbb_host.'/bigbluebutton/';
  56. if (isset($info['scheme'])) {
  57. $this->protocol = $info['scheme'].'://';
  58. $this->url = str_replace($this->protocol, '', $this->url);
  59. }
  60. // Setting BBB api
  61. define('CONFIG_SECURITY_SALT', $this->salt);
  62. define('CONFIG_SERVER_BASE_URL', $this->url);
  63. $this->api = new BigBlueButtonBN();
  64. $this->plugin_enabled = true;
  65. }
  66. }
  67. /**
  68. * Checks whether a user is teacher in the current course
  69. * @return bool True if the user can be considered a teacher in this course, false otherwise
  70. */
  71. public function isTeacher()
  72. {
  73. return api_is_course_admin() || api_is_coach() || api_is_platform_admin();
  74. }
  75. /**
  76. * See this file in you BBB to set up default values
  77. * @param array $params Array of parameters that will be completed if not containing all expected variables
  78. /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
  79. *
  80. More record information:
  81. http://code.google.com/p/bigbluebutton/wiki/RecordPlaybackSpecification
  82. # Default maximum number of users a meeting can have.
  83. # Doesn't get enforced yet but is the default value when the create
  84. # API doesn't pass a value.
  85. defaultMaxUsers=20
  86. # Default duration of the meeting in minutes.
  87. # Current default is 0 (meeting doesn't end).
  88. defaultMeetingDuration=0
  89. # Remove the meeting from memory when the end API is called.
  90. # This allows 3rd-party apps to recycle the meeting right-away
  91. # instead of waiting for the meeting to expire (see below).
  92. removeMeetingWhenEnded=false
  93. # The number of minutes before the system removes the meeting from memory.
  94. defaultMeetingExpireDuration=1
  95. # The number of minutes the system waits when a meeting is created and when
  96. # a user joins. If after this period, a user hasn't joined, the meeting is
  97. # removed from memory.
  98. defaultMeetingCreateJoinDuration=5
  99. *
  100. */
  101. public function createMeeting($params)
  102. {
  103. $params['c_id'] = api_get_course_int_id();
  104. $courseCode = api_get_course_id();
  105. $params['session_id'] = api_get_session_id();
  106. $params['attendee_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : api_get_course_id();
  107. $attendeePassword = $params['attendee_pw'];
  108. $params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getModMeetingPassword();
  109. $moderatorPassword = $params['moderator_pw'];
  110. $params['record'] = api_get_course_setting('big_blue_button_record_and_store', $courseCode) == 1 ? true : false;
  111. $max = api_get_course_setting('big_blue_button_max_students_allowed', $courseCode);
  112. $max = isset($max) ? $max : -1;
  113. $params['status'] = 1;
  114. // Generate a pseudo-global-unique-id to avoid clash of conferences on
  115. // the same BBB server with several Chamilo portals
  116. $params['remote_id'] = uniqid(true, true);
  117. // Each simultaneous conference room needs to have a different
  118. // voice_bridge composed of a 5 digits number, so generating a random one
  119. $params['voice_bridge'] = rand(10000,99999);
  120. if ($this->debug) {
  121. error_log("enter create_meeting ".print_r($params, 1));
  122. }
  123. $params['created_at'] = api_get_utc_datetime();
  124. $id = Database::insert($this->table, $params);
  125. if ($id) {
  126. if ($this->debug) {
  127. error_log("create_meeting: $id ");
  128. }
  129. $meetingName = isset($params['meeting_name']) ? $params['meeting_name'] : api_get_course_id().'-'.api_get_session_id();
  130. $welcomeMessage = isset($params['welcome_msg']) ? $params['welcome_msg'] : null;
  131. $record = isset($params['record']) && $params['record'] ? 'true' : 'false';
  132. $duration = isset($params['duration']) ? intval($params['duration']) : 0;
  133. // This setting currently limits the maximum conference duration,
  134. // to avoid lingering sessions on the video-conference server #6261
  135. $duration = 300;
  136. $bbbParams = array(
  137. 'meetingId' => $params['remote_id'], // REQUIRED
  138. 'meetingName' => $meetingName, // REQUIRED
  139. 'attendeePw' => $attendeePassword, // Match this value in getJoinMeetingURL() to join as attendee.
  140. 'moderatorPw' => $moderatorPassword, // Match this value in getJoinMeetingURL() to join as moderator.
  141. 'welcomeMsg' => $welcomeMessage, // ''= use default. Change to customize.
  142. 'dialNumber' => '', // The main number to call into. Optional.
  143. 'voiceBridge' => $params['voice_bridge'], // PIN to join voice. Required.
  144. 'webVoice' => '', // Alphanumeric to join voice. Optional.
  145. 'logoutUrl' => $this->logout_url,
  146. 'maxParticipants' => $max, // Optional. -1 = unlimitted. Not supported in BBB. [number]
  147. 'record' => $record, // New. 'true' will tell BBB to record the meeting.
  148. 'duration' => $duration, // Default = 0 which means no set duration in minutes. [number]
  149. //'meta_category' => '', // Use to pass additional info to BBB server. See API docs.
  150. );
  151. if ($this->debug) {
  152. error_log("create_meeting params: ".print_r($bbbParams,1));
  153. }
  154. $status = false;
  155. $meeting = null;
  156. while ($status == false) {
  157. $result = $this->api->createMeetingWithXmlResponseArray(
  158. $bbbParams
  159. );
  160. if (isset($result) && strval($result['returncode']) == 'SUCCESS'
  161. ) {
  162. if ($this->debug) {
  163. error_log(
  164. "create_meeting result: " . print_r($result, 1)
  165. );
  166. }
  167. $meeting = $this->joinMeeting($meetingName, true);
  168. return $meeting;
  169. }
  170. }
  171. return $this->logout;
  172. }
  173. }
  174. /**
  175. * Tells whether the given meeting exists and is running
  176. * (using course code as name)
  177. * @param string $meetingName Meeting name (usually the course code)
  178. *
  179. * @return bool True if meeting exists, false otherwise
  180. * @assert ('') === false
  181. * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
  182. */
  183. public function meetingExists($meetingName)
  184. {
  185. if (empty($meetingName)) {
  186. return false;
  187. }
  188. $courseId = api_get_course_int_id();
  189. $sessionId = api_get_session_id();
  190. $meetingData = Database::select(
  191. '*',
  192. $this->table,
  193. array(
  194. 'where' => array(
  195. 'c_id = ? AND session_id = ? AND meeting_name = ? AND status = 1 ' =>
  196. array($courseId, $sessionId, $meetingName)
  197. )
  198. ),
  199. 'first'
  200. );
  201. if ($this->debug) {
  202. error_log("meeting_exists ".print_r($meetingData, 1));
  203. }
  204. if (empty($meetingData)) {
  205. return false;
  206. } else {
  207. return true;
  208. }
  209. }
  210. /**
  211. * Returns a meeting "join" URL
  212. * @param string The name of the meeting (usually the course code)
  213. * @return mixed The URL to join the meeting, or false on error
  214. * @todo implement moderator pass
  215. * @assert ('') === false
  216. * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
  217. */
  218. public function joinMeeting($meetingName, $loop = false)
  219. {
  220. if (empty($meetingName)) {
  221. return false;
  222. }
  223. $pass = $this->getUserMeetingPassword();
  224. $meetingData = Database::select(
  225. '*',
  226. $this->table,
  227. array('where' => array('meeting_name = ? AND status = 1 ' => $meetingName)),
  228. 'first'
  229. );
  230. if (empty($meetingData) || !is_array($meetingData)) {
  231. if ($this->debug) {
  232. error_log("meeting does not exist: $meetingName");
  233. }
  234. return false;
  235. }
  236. $params = array(
  237. 'meetingId' => $meetingData['remote_id'],
  238. // -- REQUIRED - The unique id for the meeting
  239. 'password' => $this->getModMeetingPassword()
  240. // -- REQUIRED - The moderator password for the meeting
  241. );
  242. $status = false;
  243. $meetingInfoExists = false;
  244. while ($status == false) {
  245. $meetingIsRunningInfo = $this->getMeetingInfo($params);
  246. if ($meetingIsRunningInfo === false) {
  247. //checking with the remote_id didn't work, so just in case and
  248. // to provide backwards support, check with the id
  249. $params = array(
  250. 'meetingId' => $meetingData['id'],
  251. // -- REQUIRED - The unique id for the meeting
  252. 'password' => $this->getModMeetingPassword()
  253. // -- REQUIRED - The moderator password for the meeting
  254. );
  255. $meetingIsRunningInfo = $this->getMeetingInfo($params);
  256. }
  257. if ($this->debug) {
  258. error_log(print_r($meetingIsRunningInfo, 1));
  259. }
  260. if (strval($meetingIsRunningInfo['returncode']) == 'SUCCESS' &&
  261. isset($meetingIsRunningInfo['meetingName']) &&
  262. !empty($meetingIsRunningInfo['meetingName'])
  263. //strval($meetingIsRunningInfo['running']) == 'true'
  264. ) {
  265. $meetingInfoExists = true;
  266. }
  267. if ($this->debug) {
  268. error_log(
  269. "meeting is running: " . intval($meetingInfoExists)
  270. );
  271. }
  272. if ($meetingInfoExists) {
  273. $status = true;
  274. }
  275. if ($loop) {
  276. continue;
  277. } else {
  278. break;
  279. }
  280. }
  281. if ($meetingInfoExists) {
  282. $joinParams = array(
  283. 'meetingId' => $meetingData['remote_id'], // -- REQUIRED - A unique id for the meeting
  284. 'username' => $this->user_complete_name, //-- REQUIRED - The name that will display for the user in the meeting
  285. 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
  286. //'createTime' => api_get_utc_datetime(), //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  287. 'userID' => api_get_user_id(), //-- OPTIONAL - string
  288. 'webVoiceConf' => '' // -- OPTIONAL - string
  289. );
  290. $url = $this->api->getJoinMeetingURL($joinParams);
  291. $url = $this->protocol.$url;
  292. } else {
  293. $url = $this->logout_url;
  294. }
  295. if ($this->debug) {
  296. error_log("return url :" . $url);
  297. }
  298. return $url;
  299. }
  300. /**
  301. * Get information about the given meeting
  302. * @param array ...?
  303. * @return mixed Array of information on success, false on error
  304. * @assert (array()) === false
  305. */
  306. public function getMeetingInfo($params)
  307. {
  308. try {
  309. $result = $this->api->getMeetingInfoWithXmlResponseArray($params);
  310. if ($result == null) {
  311. if ($this->debug) {
  312. error_log("Failed to get any response. Maybe we can't contact the BBB server.");
  313. }
  314. } else {
  315. return $result;
  316. }
  317. } catch (Exception $e) {
  318. if ($this->debug) {
  319. error_log('Caught exception: ', $e->getMessage(), "\n");
  320. }
  321. }
  322. return false;
  323. }
  324. /**
  325. * Gets all the course meetings saved in the plugin_bbb_meeting table
  326. * @return array Array of current open meeting rooms
  327. */
  328. public function getCourseMeetings()
  329. {
  330. $pass = $this->getUserMeetingPassword();
  331. $meetingList = Database::select('*', $this->table, array('where' => array('c_id = ? AND session_id = ? ' => array(api_get_course_int_id(), api_get_session_id()))));
  332. $newMeetingList = array();
  333. $item = array();
  334. foreach ($meetingList as $meetingDB) {
  335. $meetingBBB = $this->getMeetingInfo(array('meetingId' => $meetingDB['remote_id'], 'password' => $pass));
  336. if ($meetingBBB === false) {
  337. //checking with the remote_id didn't work, so just in case and
  338. // to provide backwards support, check with the id
  339. $params = array(
  340. 'meetingId' => $meetingDB['id'],
  341. // -- REQUIRED - The unique id for the meeting
  342. 'password' => $pass
  343. // -- REQUIRED - The moderator password for the meeting
  344. );
  345. $meetingBBB = $this->getMeetingInfo($params);
  346. }
  347. if ($meetingDB['visibility'] == 0 and $this->isTeacher() == false) {
  348. continue;
  349. }
  350. $meetingBBB['end_url'] = api_get_self().'?'.api_get_cidreq().'&action=end&id='.$meetingDB['id'];
  351. if ((string)$meetingBBB['returncode'] == 'FAILED') {
  352. if ($meetingDB['status'] == 1 && $this->isTeacher()) {
  353. $this->endMeeting($meetingDB['id']);
  354. }
  355. } else {
  356. $meetingBBB['add_to_calendar_url'] = api_get_self().'?'.api_get_cidreq().'&action=add_to_calendar&id='.$meetingDB['id'].'&start='.api_strtotime($meetingDB['created_at']);
  357. }
  358. $recordArray = array();
  359. $actionLinksArray = array();
  360. if ($meetingDB['record'] == 1) {
  361. // backwards compatibility (when there was no remote ID)
  362. $mId = $meetingDB['remote_id'];
  363. if (empty($mId)) {
  364. $mId = $meetingDB['id'];
  365. }
  366. if (empty($mId)) {
  367. // if the id is still empty (should *never* occur as 'id' is
  368. // the table's primary key), skip this conference
  369. continue;
  370. }
  371. $recordingParams = array(
  372. 'meetingId' => $mId, //-- OPTIONAL - comma separate if multiple ids
  373. );
  374. //To see the recording list in your BBB server do: bbb-record --list
  375. $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
  376. if (!empty($records)) {
  377. $count = 1;
  378. if (isset($records['message']) && !empty($records['message'])) {
  379. if ($records['messageKey'] == 'noRecordings') {
  380. $recordArray[] = get_lang('NoRecording');
  381. if ($meetingDB['visibility'] == 0) {
  382. $actionLinksArray[] = Display::url(
  383. Display::return_icon(
  384. 'invisible.png',
  385. get_lang('MakeVisible'),
  386. array(),
  387. ICON_SIZE_MEDIUM
  388. ),
  389. api_get_self().'?'.
  390. api_get_cidreq().
  391. '&action=publish&id='.$meetingDB['id']
  392. );
  393. } else {
  394. $actionLinksArray[] = Display::url(
  395. Display::return_icon(
  396. 'visible.png',
  397. get_lang('MakeInvisible'),
  398. array(),
  399. ICON_SIZE_MEDIUM
  400. ),
  401. api_get_self().'?'.
  402. api_get_cidreq().
  403. '&action=unpublish&id='.$meetingDB['id']
  404. );
  405. }
  406. } else {
  407. //$recordArray[] = $records['message'];
  408. }
  409. } else {
  410. foreach ($records as $record) {
  411. //if you get several recordings here and you used a
  412. // previous version of Chamilo, you might want to
  413. // only keep the last result for each chamilo conf
  414. // (see show_links after the end of this loop)
  415. if (is_array($record) && isset($record['recordId'])) {
  416. $url = Display::url(
  417. get_lang('ViewRecord')." [~".$record['playbackFormatLength']."']",
  418. $record['playbackFormatUrl'],
  419. array('target' => '_blank')
  420. );
  421. $actionLinks = '';
  422. if ($this->isTeacher()) {
  423. $actionLinks .= Display::url(
  424. Display::return_icon(
  425. 'link.gif',
  426. get_lang('CopyToLinkTool')
  427. ),
  428. api_get_self().'?'.
  429. api_get_cidreq().
  430. '&action=copy_record_to_link_tool&id='.$meetingDB['id']
  431. );
  432. $actionLinks .= Display::url(
  433. Display::return_icon(
  434. 'agenda.png',
  435. get_lang('AddToCalendar')
  436. ),
  437. api_get_self().'?'.
  438. api_get_cidreq().
  439. '&action=add_to_calendar&id='.$meetingDB['id'].
  440. '&start='.api_strtotime($meetingDB['created_at']).
  441. '&url='.$record['playbackFormatUrl']
  442. );
  443. $actionLinks .= Display::url(
  444. Display::return_icon(
  445. 'delete.png',
  446. get_lang('Delete')
  447. ),
  448. api_get_self().'?'.
  449. api_get_cidreq().
  450. '&action=delete_record&id='.$meetingDB['id']
  451. );
  452. if ($meetingDB['visibility'] == 0) {
  453. $actionLinks .= Display::url(
  454. Display::return_icon(
  455. 'invisible.png',
  456. get_lang('MakeVisible'),
  457. array(),
  458. ICON_SIZE_MEDIUM
  459. ),
  460. api_get_self().'?'.
  461. api_get_cidreq().
  462. '&action=publish&id='.$meetingDB['id']
  463. );
  464. } else {
  465. $actionLinks .= Display::url(
  466. Display::return_icon(
  467. 'visible.png',
  468. get_lang('MakeInvisible'),
  469. array(),
  470. ICON_SIZE_MEDIUM
  471. ),
  472. api_get_self().'?'.
  473. api_get_cidreq().
  474. '&action=unpublish&id='.$meetingDB['id']
  475. );
  476. }
  477. }
  478. //$url .= api_get_self().'?action=publish&id='.$record['recordID'];
  479. $count++;
  480. $recordArray[] = $url;
  481. $actionLinksArray[] = $actionLinks;
  482. } else {
  483. /*if (is_array($record) && isset($record['recordID']) && isset($record['playbacks'])) {
  484. //Fix the bbb timestamp
  485. //$record['startTime'] = substr($record['startTime'], 0, strlen($record['startTime']) -3);
  486. //$record['endTime'] = substr($record['endTime'], 0, strlen($record['endTime']) -3);
  487. //.' - '.api_convert_and_format_date($record['startTime']).' - '.api_convert_and_format_date($record['endTime'])
  488. foreach($record['playbacks'] as $item) {
  489. $url = Display::url(get_lang('ViewRecord'), $item['url'], array('target' => '_blank'));
  490. //$url .= Display::url(get_lang('DeleteRecord'), api_get_self().'?action=delete_record&'.$record['recordID']);
  491. if ($this->isTeacher()) {
  492. $url .= Display::url(Display::return_icon('link.gif',get_lang('CopyToLinkTool')), api_get_self().'?action=copy_record_to_link_tool&id='.$meetingDB['id'].'&record_id='.$record['recordID']);
  493. $url .= Display::url(Display::return_icon('agenda.png',get_lang('AddToCalendar')), api_get_self().'?action=add_to_calendar&id='.$meetingDB['id'].'&start='.api_strtotime($meetingDB['created_at']).'&url='.$item['url']);
  494. $url .= Display::url(Display::return_icon('delete.png',get_lang('Delete')), api_get_self().'?action=delete_record&id='.$record['recordID']);
  495. }
  496. //$url .= api_get_self().'?action=publish&id='.$record['recordID'];
  497. $count++;
  498. $recordArray[] = $url;
  499. }
  500. }*/
  501. }
  502. }
  503. }
  504. } else {
  505. $actionLinks = '';
  506. if ($this->isTeacher()) {
  507. if ($meetingDB['visibility'] == 0) {
  508. $actionLinks .= Display::url(
  509. Display::return_icon(
  510. 'invisible.png',
  511. get_lang('MakeVisible'),
  512. array(),
  513. ICON_SIZE_MEDIUM
  514. ),
  515. api_get_self().'?'.
  516. api_get_cidreq().
  517. '&action=publish&id='.$meetingDB['id']
  518. );
  519. } else {
  520. $actionLinks .= Display::url(
  521. Display::return_icon(
  522. 'visible.png',
  523. get_lang('MakeInvisible'),
  524. array(),
  525. ICON_SIZE_MEDIUM
  526. ),
  527. api_get_self().'?'.
  528. api_get_cidreq().
  529. '&action=unpublish&id='.$meetingDB['id']
  530. );
  531. }
  532. }
  533. $actionLinksArray[] = $actionLinks;
  534. $item['action_links'] = implode('<br />', $actionLinksArray);
  535. }
  536. //var_dump($recordArray);
  537. $item['show_links'] = implode('<br />', $recordArray);
  538. $item['action_links'] = implode('<br />', $actionLinksArray);
  539. }
  540. $item['created_at'] = api_convert_and_format_date($meetingDB['created_at']);
  541. //created_at
  542. $meetingDB['created_at'] = $item['created_at']; //avoid overwrite in array_merge() below
  543. $item['publish_url'] = api_get_self().'?'.api_get_cidreq().'&action=publish&id='.$meetingDB['id'];
  544. $item['unpublish_url'] = api_get_self().'?'.api_get_cidreq().'&action=unpublish&id='.$meetingDB['id'];
  545. if ($meetingDB['status'] == 1) {
  546. $joinParams = array(
  547. 'meetingId' => $meetingDB['remote_id'], //-- REQUIRED - A unique id for the meeting
  548. 'username' => $this->user_complete_name, //-- REQUIRED - The name that will display for the user in the meeting
  549. 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
  550. 'createTime' => '', //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  551. 'userID' => '', // -- OPTIONAL - string
  552. 'webVoiceConf' => '' // -- OPTIONAL - string
  553. );
  554. $item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams);
  555. }
  556. $item = array_merge($item, $meetingDB, $meetingBBB);
  557. $newMeetingList[] = $item;
  558. }
  559. return $newMeetingList;
  560. }
  561. /**
  562. * Function disabled
  563. */
  564. public function publishMeeting($id)
  565. {
  566. //return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt);
  567. if (empty($id)) {
  568. return false;
  569. }
  570. $id = intval($id);
  571. Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id));
  572. return true;
  573. }
  574. /**
  575. * Function disabled
  576. */
  577. public function unpublishMeeting($id)
  578. {
  579. //return BigBlueButtonBN::setPublishRecordings($id, 'false', $this->url, $this->salt);
  580. if (empty($id)) {
  581. return false;
  582. }
  583. $id = intval($id);
  584. Database::update($this->table, array('visibility' => 0), array('id = ? ' => $id));
  585. return true;
  586. }
  587. /**
  588. * Closes a meeting (usually when the user click on the close button from
  589. * the conferences listing.
  590. * @param string The internal ID of the meeting (id field for this meeting)
  591. * @return void
  592. * @assert (0) === false
  593. */
  594. public function endMeeting($id)
  595. {
  596. if (empty($id)) {
  597. return false;
  598. }
  599. $meetingData = Database::select('*', $this->table, array('where' => array('id = ?' => array($id))), 'first');
  600. $pass = $this->getUserMeetingPassword();
  601. $endParams = array(
  602. 'meetingId' => $meetingData['remote_id'], // REQUIRED - We have to know which meeting to end.
  603. 'password' => $pass, // REQUIRED - Must match moderator pass for meeting.
  604. );
  605. $this->api->endMeetingWithXmlResponseArray($endParams);
  606. Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $id));
  607. }
  608. /**
  609. * Gets the password for a specific meeting for the current user
  610. * @return string A moderator password if user is teacher, or the course code otherwise
  611. */
  612. public function getUserMeetingPassword()
  613. {
  614. if ($this->isTeacher()) {
  615. return $this->getModMeetingPassword();
  616. } else {
  617. return api_get_course_id();
  618. }
  619. }
  620. /**
  621. * Generated a moderator password for the meeting
  622. * @return string A password for the moderation of the videoconference
  623. */
  624. public function getModMeetingPassword()
  625. {
  626. return api_get_course_id().'mod';
  627. }
  628. /**
  629. * Get users online in the current course room
  630. * @return int The number of users currently connected to the videoconference
  631. * @assert () > -1
  632. */
  633. public function getUsersOnlineInCurrentRoom()
  634. {
  635. $courseId = api_get_course_int_id();
  636. $sessionId = api_get_session_id();
  637. $meetingData = Database::select('*', $this->table, array('where' => array('c_id = ? AND session_id = ? AND status = 1 ' => array($courseId, $sessionId))), 'first');
  638. if (empty($meetingData)) {
  639. return 0;
  640. }
  641. $pass = $this->getModMeetingPassword();
  642. $info = $this->getMeetingInfo(array('meetingId' => $meetingData['remote_id'], 'password' => $pass));
  643. if ($info === false) {
  644. //checking with the remote_id didn't work, so just in case and
  645. // to provide backwards support, check with the id
  646. $params = array(
  647. 'meetingId' => $meetingData['id'],
  648. // -- REQUIRED - The unique id for the meeting
  649. 'password' => $pass
  650. // -- REQUIRED - The moderator password for the meeting
  651. );
  652. $info = $this->getMeetingInfo($params);
  653. }
  654. if (!empty($info) && isset($info['participantCount'])) {
  655. return $info['participantCount'];
  656. }
  657. return 0;
  658. }
  659. /**
  660. * Deletes a previous recording of a meeting
  661. * @param int integral ID of the recording
  662. * @return array ?
  663. * @assert () === false
  664. * @todo Also delete links and agenda items created from this recording
  665. */
  666. public function deleteRecord($id)
  667. {
  668. if (empty($id)) {
  669. return false;
  670. }
  671. $meetingData = Database::select(
  672. '*',
  673. $this->table,
  674. array('where' => array('id = ?' => array($id))),
  675. 'first'
  676. );
  677. $recordingParams = array(
  678. /*
  679. * NOTE: Set the recordId below to a valid id after you have
  680. * created a recorded meeting, and received a real recordID
  681. * back from your BBB server using the
  682. * getRecordingsWithXmlResponseArray method.
  683. */
  684. // REQUIRED - We have to know which recording:
  685. 'recordId' => $meetingData['remote_id'],
  686. );
  687. $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
  688. if (!empty($result) && isset($result['deleted']) && $result['deleted'] == 'true') {
  689. Database::delete(
  690. $this->table,
  691. array('id = ?' => array($id))
  692. );
  693. }
  694. return $result;
  695. }
  696. /**
  697. * Creates a link in the links tool from the given videoconference recording
  698. * @param int ID of the item in the plugin_bbb_meeting table
  699. * @param string Hash identifying the recording, as provided by the API
  700. * @return mixed ID of the newly created link, or false on error
  701. * @assert (null, null) === false
  702. * @assert (1, null) === false
  703. * @assert (null, 'abcdefabcdefabcdefabcdef') === false
  704. */
  705. public function copyRecordToLinkTool($id)
  706. {
  707. if (empty($id)) {
  708. return false;
  709. }
  710. //$records = BigBlueButtonBN::getRecordingsUrl($id);
  711. $meetingData = Database::select('*', $this->table, array('where' => array('id = ?' => array($id))), 'first');
  712. $records = $this->api->getRecordingsWithXmlResponseArray(array('meetingId' => $meetingData['remote_id']));
  713. if (!empty($records)) {
  714. $count = 1;
  715. if (isset($records['message']) && !empty($records['message'])) {
  716. if ($records['messageKey'] == 'noRecordings') {
  717. $recordArray[] = get_lang('NoRecording');
  718. } else {
  719. //$recordArray[] = $records['message'];
  720. }
  721. return false;
  722. } else {
  723. $record = $records[0];
  724. if (is_array($record) && isset($record['recordId'])) {
  725. $url = $record['playbackFormatUrl'];
  726. $link = new Link();
  727. $params['url'] = $url;
  728. $params['title'] = $meetingData['meeting_name'];
  729. $id = $link->save($params);
  730. return $id;
  731. }
  732. }
  733. }
  734. return false;
  735. }
  736. /**
  737. * Checks if the videoconference server is running.
  738. * Function currently disabled (always returns 1)
  739. * @return bool True if server is running, false otherwise
  740. * @assert () === false
  741. */
  742. public function isServerRunning()
  743. {
  744. return true;
  745. //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
  746. }
  747. /**
  748. * Get active session in the all platform
  749. */
  750. public function getActiveSessionsCount()
  751. {
  752. $meetingList = Database::select(
  753. 'count(id) as count',
  754. $this->table,
  755. array('where' => array('status = ?' => array(1))),
  756. 'first'
  757. );
  758. return $meetingList['count'];
  759. }
  760. /**
  761. * @param string $url
  762. */
  763. public function redirectToBBB($url)
  764. {
  765. if (file_exists(__DIR__ . '/../config.vm.php')) {
  766. // Using VM
  767. echo Display::url(get_lang('ClickToContinue'), $url);
  768. exit;
  769. } else {
  770. // Classic
  771. header("Location: $url");
  772. exit;
  773. }
  774. // js
  775. /*echo '<script>';
  776. echo 'window.location = "'.$url.'"';
  777. echo '</script>';
  778. exit;*/
  779. }
  780. }