bbb.lib.php 35 KB

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