diff --git a/plugin/bbb/README.md b/plugin/bbb/README.md index 238742e12a..2c7df9436f 100644 --- a/plugin/bbb/README.md +++ b/plugin/bbb/README.md @@ -25,3 +25,17 @@ You need execute this SQL query in your database after making the Chamilo migrat ALTER TABLE plugin_bbb_meeting ADD user_id int unsigned NOT NULL DEFAULT 0; ALTER TABLE plugin_bbb_meeting ADD access_url int NOT NULL DEFAULT 1; ``` +For the version 2.5 you need execute these SQL queries +```sql +CREATE TABLE plugin_bbb_room ( + id int NOT NULL AUTO_INCREMENT PRIMARY KEY, + meeting_id int(10) unsigned NOT NULL, + participant_id int(11) NOT NULL, + in_at datetime NOT NULL, + out_at datetime NOT NULL, + FOREIGN KEY (meeting_id) REFERENCES plugin_bbb_meeting (id), + FOREIGN KEY (participant_id) REFERENCES user (id) +); +ALTER TABLE plugin_bbb_meeting ADD video_url TEXT NULL; +ALTER TABLE plugin_bbb_meeting ADD has_video_m4v TINYINT NOT NULL DEFAULT 0; +``` diff --git a/plugin/bbb/admin.php b/plugin/bbb/admin.php index 34a04a8774..4566bd18ba 100644 --- a/plugin/bbb/admin.php +++ b/plugin/bbb/admin.php @@ -15,7 +15,6 @@ api_protect_admin_script(); $plugin = BBBPlugin::create(); $tool_name = $plugin->get_lang('Videoconference'); -$tpl = new Template($tool_name); $isGlobal = isset($_GET['global']) ? true : false; @@ -75,6 +74,13 @@ if (!$bbb->isServerRunning()) { ); } +$htmlHeadXtra[] = api_get_js_simple( + api_get_path(WEB_PLUGIN_PATH) . 'bbb/resources/utils.js' +); +$htmlHeadXtra[] = "<script>var _p = {web_plugin: '" . api_get_path(WEB_PLUGIN_PATH). "'}</script>"; + +$tpl = new Template($tool_name); + $tpl->assign('meetings', $meetings); $content = $tpl->fetch('bbb/admin.tpl'); diff --git a/plugin/bbb/ajax.php b/plugin/bbb/ajax.php new file mode 100644 index 0000000000..5bd3a5a77b --- /dev/null +++ b/plugin/bbb/ajax.php @@ -0,0 +1,47 @@ +<?php +/** + * This script initiates a video conference session, calling the BigBlueButton API + * @package chamilo.plugin.bigbluebutton + */ + +$course_plugin = 'bbb'; //needed in order to load the plugin lang variables +$cidReset = true; + +require_once __DIR__ . '/../../main/inc/global.inc.php'; + +$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; +$meetingId = isset($_REQUEST['meeting']) ? intval($_REQUEST['meeting']) : 0; + +$bbb = new bbb('', ''); + +switch ($action) { + case 'check_m4v': + if (!api_is_platform_admin()) { + api_not_allowed(); + exit; + } + + if (!$meetingId) { + exit; + } + + if ($bbb->checkDirectMeetingVideoUrl($meetingId)) { + $meetingInfo = Database::select( + '*', + 'plugin_bbb_meeting', + ['where' => ['id = ?' => intval($meetingId)]], + 'first' + ); + + $url = $meetingInfo['video_url'] . '/capture.m4v'; + $link = Display::url( + Display::return_icon('save.png', get_lang('DownloadFile')), + $meetingInfo['video_url'] . '/capture.m4v', + ['target' => '_blank'] + ); + + header('Content-Type: application/json'); + echo json_encode(['url' => $url, 'link' => $link]); + } + break; +} diff --git a/plugin/bbb/lib/bbb.lib.php b/plugin/bbb/lib/bbb.lib.php index 16b54c1a86..9cf286228c 100755 --- a/plugin/bbb/lib/bbb.lib.php +++ b/plugin/bbb/lib/bbb.lib.php @@ -1252,11 +1252,23 @@ class bbb ); } - $links[] = Display::url( - Display::return_icon('save.png', get_lang('DownloadFile')), - $recordInfo['playbackFormatUrl'] . '/capture.m4v', - ['target' => '_blank'] - ); + if ($meetingInfo['has_video_m4v']) { + $links[] = Display::url( + Display::return_icon('save.png', get_lang('DownloadFile')), + $recordInfo['playbackFormatUrl'] . '/capture.m4v', + ['target' => '_blank'] + ); + } else { + $links[] = Display::url( + Display::return_icon('save.png', get_lang('DownloadFile')), + '#', + [ + 'id' => "btn-check-meeting-video-{$meetingInfo['id']}", + 'class' => 'check-meeting-video', + 'data-id' => $meetingInfo['id'] + ] + ); + } if (!$isAdminReport) { $links[] = Display::url( @@ -1287,4 +1299,37 @@ class bbb ['id = ?' => intval($meetingId)] ); } + + /** + * Check if the meeting has a capture.m4v video file. If exists then the has_video_m4v field is updated + * @param int $meetingId + * @return bool + */ + public function checkDirectMeetingVideoUrl($meetingId) + { + $meetingInfo = Database::select( + '*', + 'plugin_bbb_meeting', + [ + 'where' => ['id = ?' => intval($meetingId)] + ], + 'first' + ); + + if (!isset($meetingInfo['video_url'])) { + return false; + } + + $hasCapture = SocialManager::verifyUrl($meetingInfo['video_url'] . '/capture.m4v'); + + if ($hasCapture) { + return Database::update( + 'plugin_bbb_meeting', + ['has_video_m4v' => true], + ['id = ?' => intval($meetingId)] + ); + } + + return $hasCapture; + } } diff --git a/plugin/bbb/resources/utils.js b/plugin/bbb/resources/utils.js new file mode 100644 index 0000000000..7c5e3fc683 --- /dev/null +++ b/plugin/bbb/resources/utils.js @@ -0,0 +1,27 @@ +$(document).on('ready', function () { + $('.check-meeting-video').on('click', function (e) { + e.preventDefault(); + + var $self = $(this), + meetingId = $self.data('id') || 0; + + if (!meetingId) { + return; + } + + var $loader = $('<span>', { + 'aria-hidden': 'true' + }).addClass('fa fa-spinner fa-spin fa-fw'); + + $self.replaceWith($loader); + + $.get(_p.web_plugin + 'bbb/ajax.php', { + a: 'check_m4v', + meeting: meetingId + }, function (response) { + $loader.replaceWith(response.link); + + window.open(response.url); + }); + }); +});