Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
chamilo-lms/plugin/bbb/lib/bbb.lib.php

397 lines
19 KiB

<?php
/**
* This script initiates a videoconference session, calling the BigBlueButton API
* @package chamilo.plugin.bigbluebutton
*/
class bbb {
var $url;
var $salt;
var $api;
var $user_complete_name = null;
var $protocol = 'http://';
var $debug = true;
var $logout_url = null;
var $plugin_enabled = false;
function __construct() {
// initialize video server settings from global settings
$plugin = BBBPlugin::create();
$bbb_plugin = $plugin->get('tool_enable');
$bbb_host = $plugin->get('host');
$bbb_salt = $plugin->get('salt');
//$course_code = api_get_course_id();
$this->logout_url = api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php';
$this->table = Database::get_main_table('plugin_bbb_meeting');
if ($bbb_plugin == true) {
$user_info = api_get_user_info();
$this->user_complete_name = $user_info['complete_name'];
$this->salt = $bbb_salt;
$info = parse_url($bbb_host);
$this->url = $bbb_host.'/bigbluebutton/';
if (isset($info['scheme'])) {
$this->protocol = $info['scheme'].'://';
$this->url = str_replace($this->protocol, '', $this->url);
}
// Setting BBB api
define('CONFIG_SECURITY_SALT', $this->salt);
define('CONFIG_SERVER_BASE_URL', $this->url);
$this->api = new BigBlueButtonBN();
$this->plugin_enabled = true;
}
}
function is_teacher() {
return api_is_course_admin() || api_is_coach() || api_is_platform_admin();
}
/*
* See this file in you BBB to set up default values
/var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
*
More record information:
http://code.google.com/p/bigbluebutton/wiki/RecordPlaybackSpecification
# Default maximum number of users a meeting can have.
# Doesn't get enforced yet but is the default value when the create
# API doesn't pass a value.
defaultMaxUsers=20
# Default duration of the meeting in minutes.
# Current default is 0 (meeting doesn't end).
defaultMeetingDuration=0
# Remove the meeting from memory when the end API is called.
# This allows 3rd-party apps to recycle the meeting right-away
# instead of waiting for the meeting to expire (see below).
removeMeetingWhenEnded=false
# The number of minutes before the system removes the meeting from memory.
defaultMeetingExpireDuration=1
# The number of minutes the system waits when a meeting is created and when
# a user joins. If after this period, a user hasn't joined, the meeting is
# removed from memory.
defaultMeetingCreateJoinDuration=5
*
*/
function create_meeting($params) {
$params['c_id'] = api_get_course_int_id();
$course_code = api_get_course_id();
$attende_password = $params['attendee_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : api_get_course_id();
$moderator_password = $params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->get_mod_meeting_password();
$params['record'] = api_get_course_setting('big_blue_button_record_and_store', $course_code) == 1 ? true : false;
$max = api_get_course_setting('big_blue_button_max_students_allowed', $course_code);
$max = isset($max) ? $max : -1;
$params['status'] = 1;
if ($this->debug) error_log("enter create_meeting ".print_r($params, 1));
$params['created_at'] = api_get_utc_datetime();
$id = Database::insert($this->table, $params);
if ($id) {
if ($this->debug) error_log("create_meeting: $id ");
$meeting_name = isset($params['meeting_name']) ? $params['meeting_name'] : api_get_course_id();
$welcome_msg = isset($params['welcome_msg']) ? $params['welcome_msg'] : null;
$record = isset($params['record']) && $params['record'] ? 'true' : 'false';
$duration = isset($params['duration']) ? intval($params['duration']) : 0;
$duration = 30;
$bbb_params = array(
'meetingId' => $id, // REQUIRED
'meetingName' => $meeting_name, // REQUIRED
'attendeePw' => $attende_password, // Match this value in getJoinMeetingURL() to join as attendee.
'moderatorPw' => $moderator_password, // Match this value in getJoinMeetingURL() to join as moderator.
'welcomeMsg' => $welcome_msg, // ''= use default. Change to customize.
'dialNumber' => '', // The main number to call into. Optional.
'voiceBridge' => '0', // PIN to join voice. Optional.
'webVoice' => '', // Alphanumeric to join voice. Optional.
'logoutUrl' => $this->logout_url,
'maxParticipants' => $max, // Optional. -1 = unlimitted. Not supported in BBB. [number]
'record' => $record, // New. 'true' will tell BBB to record the meeting.
'duration' => $duration, // Default = 0 which means no set duration in minutes. [number]
//'meta_category' => '', // Use to pass additional info to BBB server. See API docs.
);
if ($this->debug) error_log("create_meeting params: ".print_r($bbb_params,1));
$result = $this->api->createMeetingWithXmlResponseArray($bbb_params);
if (isset($result) && (string)$result['returncode'] == 'SUCCESS') {
if ($this->debug) error_log("create_meeting result: ".print_r($result,1));
return $this->join_meeting($meeting_name);
}
return $this->logout;
}
}
function is_meeting_exist($meeting_name) {
$course_id = api_get_course_int_id();
$meeting_data = Database::select('*', $this->table, array('where' => array('c_id = ? AND meeting_name = ? AND status = 1 ' => array($course_id, $meeting_name))), 'first');
if ($this->debug) error_log("is_meeting_exist ".print_r($meeting_data,1));
if (empty($meeting_data)) {
return false;
} else {
return true;
}
}
/**
* @todo implement moderator pass
*/
function join_meeting($meeting_name) {
$pass = $this->get_user_meeting_password();
$meeting_data = Database::select('*', $this->table, array('where' => array('meeting_name = ? AND status = 1 ' => $meeting_name)), 'first');
if (empty($meeting_data)) {
if ($this->debug) error_log("meeting does not exist: $meeting_name ");
return false;
}
$meeting_is_running_info = $this->api->isMeetingRunningWithXmlResponseArray($meeting_data['id']);
$meeting_is_running = $meeting_is_running_info['running'] == 'true' ? true : false;
if ($this->debug) error_log("meeting is running: ".$meeting_is_running);
$params = array(
'meetingId' => $meeting_data['id'], // -- REQUIRED - The unique id for the meeting
'password' => $this->get_mod_meeting_password() // -- REQUIRED - The moderator password for the meeting
);
$meeting_info_exists = $this->get_meeting_info($params);
if (isset($meeting_is_running) && $meeting_info_exists) {
$joinParams = array(
'meetingId' => $meeting_data['id'], // -- REQUIRED - A unique id for the meeting
'username' => $this->user_complete_name, //-- REQUIRED - The name that will display for the user in the meeting
'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
//'createTime' => api_get_utc_datetime(), //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
'userID' => api_get_user_id(), //-- OPTIONAL - string
'webVoiceConf' => '' // -- OPTIONAL - string
);
$url = $this->api->getJoinMeetingURL($joinParams);
$url = $this->protocol.$url;
} else {
$url = $this->logout_url;
}
if ($this->debug) error_log("return url :".$url);
return $url;
}
function get_meeting_info($params) {
try {
$result = $this->api->getMeetingInfoWithXmlResponseArray($params);
if ($result == null) {
if ($this->debug) error_log("Failed to get any response. Maybe we can't contact the BBB server.");
} else {
return $result;
}
} catch (Exception $e) {
if ($this->debug) error_log('Caught exception: ', $e->getMessage(), "\n");
}
return false;
}
/**
* Gets all the course meetings saved in the plugin_bbb_meeting table
* @return string
*/
function get_course_meetings() {
$pass = $this->get_user_meeting_password();
$meeting_list = Database::select('*', $this->table, array('where' => array('c_id = ? ' => api_get_course_int_id())));
$new_meeting_list = array();
$item = array();
foreach ($meeting_list as $meeting_db) {
$meeting_bbb = $this->get_meeting_info(array('meetingId' => $meeting_db['id'], 'password' => $pass));
$meeting_bbb['end_url'] = api_get_self().'?action=end&id='.$meeting_db['id'];
if ((string)$meeting_bbb['returncode'] == 'FAILED') {
if ($meeting_db['status'] == 1) {
$this->end_meeting($meeting_db['id']);
}
} else {
$meeting_bbb['add_to_calendar_url'] = api_get_self().'?action=add_to_calendar&id='.$meeting_db['id'].'&start='.api_strtotime($meeting_db['created_at']);
}
$record_array = array();
if ($meeting_db['record'] == 1) {
$recordingParams = array(
'meetingId' => $meeting_db['id'], //-- OPTIONAL - comma separate if multiple ids
);
//To see the recording list in your BBB server do: bbb-record --list
$records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
if (!empty($records)) {
$count = 1;
if (isset($records['message']) && !empty($records['message'])) {
if ($records['messageKey'] == 'noRecordings') {
//$record_array[] = get_lang('ThereAreNotRecordingsForTheMeetings');
} else {
//$record_array[] = $records['message'];
}
} else {
foreach ($records as $record) {
if (is_array($record) && isset($record['recordId'])) {
$url = Display::url(get_lang('ViewRecord'), $record['playbackFormatUrl'], array('target' => '_blank'));
if ($this->is_teacher()) {
$url .= Display::url(Display::return_icon('link.gif',get_lang('CopyToLinkTool')), api_get_self().'?action=copy_record_to_link_tool&id='.$meeting_db['id'].'&record_id='.$record['recordId']);
$url .= Display::url(Display::return_icon('agenda.png',get_lang('AddToCalendar')), api_get_self().'?action=add_to_calendar&id='.$meeting_db['id'].'&start='.api_strtotime($meeting_db['created_at']).'&url='.$record['playbackFormatUrl']);
$url .= Display::url(Display::return_icon('delete.png',get_lang('Delete')), api_get_self().'?action=delete_record&id='.$record['recordId']);
}
//$url .= api_get_self().'?action=publish&id='.$record['recordID'];
$count++;
$record_array[] = $url;
} else {
/*if (is_array($record) && isset($record['recordID']) && isset($record['playbacks'])) {
//Fix the bbb timestamp
//$record['startTime'] = substr($record['startTime'], 0, strlen($record['startTime']) -3);
//$record['endTime'] = substr($record['endTime'], 0, strlen($record['endTime']) -3);
//.' - '.api_convert_and_format_date($record['startTime']).' - '.api_convert_and_format_date($record['endTime'])
foreach($record['playbacks'] as $item) {
$url = Display::url(get_lang('ViewRecord'), $item['url'], array('target' => '_blank'));
//$url .= Display::url(get_lang('DeleteRecord'), api_get_self().'?action=delete_record&'.$record['recordID']);
if ($this->is_teacher()) {
$url .= Display::url(Display::return_icon('link.gif',get_lang('CopyToLinkTool')), api_get_self().'?action=copy_record_to_link_tool&id='.$meeting_db['id'].'&record_id='.$record['recordID']);
$url .= Display::url(Display::return_icon('agenda.png',get_lang('AddToCalendar')), api_get_self().'?action=add_to_calendar&id='.$meeting_db['id'].'&start='.api_strtotime($meeting_db['created_at']).'&url='.$item['url']);
$url .= Display::url(Display::return_icon('delete.png',get_lang('Delete')), api_get_self().'?action=delete_record&id='.$record['recordID']);
}
//$url .= api_get_self().'?action=publish&id='.$record['recordID'];
$count++;
$record_array[] = $url;
}
}*/
}
}
}
}
//var_dump($record_array);
$item['show_links'] = implode('<br />', $record_array);
}
$item['created_at'] = api_convert_and_format_date($meeting_db['created_at']);
//created_at
$item['publish_url'] = api_get_self().'?action=publish&id='.$meeting_db['id'];
$item['unpublish_url'] = api_get_self().'?action=unpublish&id='.$meeting_db['id'];
if ($meeting_db['status'] == 1) {
$joinParams = array(
'meetingId' => $meeting_db['id'], //-- REQUIRED - A unique id for the meeting
'username' => $this->user_complete_name, //-- REQUIRED - The name that will display for the user in the meeting
'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
'createTime' => '', //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
'userID' => '', // -- OPTIONAL - string
'webVoiceConf' => '' // -- OPTIONAL - string
);
$item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams);
}
$item = array_merge($item, $meeting_db, $meeting_bbb);
$new_meeting_list[] = $item;
}
return $new_meeting_list;
}
function publish_meeting($id) {
//return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt);
}
function unpublish_meeting($id) {
//return BigBlueButtonBN::setPublishRecordings($id, 'false', $this->url, $this->salt);
}
function end_meeting($id) {
$pass = $this->get_user_meeting_password();
$endParams = array(
'meetingId' => $id, // REQUIRED - We have to know which meeting to end.
'password' => $pass, // REQUIRED - Must match moderator pass for meeting.
);
$this->api->endMeetingWithXmlResponseArray($endParams);
Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $id));
}
function get_user_meeting_password() {
if ($this->is_teacher()) {
return $this->get_mod_meeting_password();
} else {
return api_get_course_id();
}
}
function get_mod_meeting_password() {
return api_get_course_id().'mod';
}
/**
* Get users online in the current course room
*/
function get_users_online_in_current_room() {
$course_id = api_get_course_int_id();
$meeting_data = Database::select('*', $this->table, array('where' => array('c_id = ? AND status = 1 ' => $course_id)), 'first');
if (empty($meeting_data)) {
return 0;
}
$pass = $this->get_mod_meeting_password();
$info = $this->get_meeting_info(array('meetingId' => $meeting_data['id'], 'password' => $pass));
if (!empty($info) && isset($info['participantCount'])) {
return $info['participantCount'];
}
return 0;
}
function delete_record($ids) {
$recordingParams = array(
/*
* NOTE: Set the recordId below to a valid id after you have created a recorded meeting,
* and received back a real recordID back from your BBB server using the
* getRecordingsWithXmlResponseArray method.
*/
// REQUIRED - We have to know which recording:
'recordId' => $ids,
);
return $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
}
function copy_record_to_link_tool($id, $record_id) {
require_once api_get_path(LIBRARY_PATH).'link.lib.php';
$records = BigBlueButtonBN::getRecordingsArray($id, $this->url, $this->salt);
if (!empty($records)) {
foreach ($records as $record) {
if ($record['recordID'] == $record_id) {
if (is_array($record) && isset($record['recordID']) && isset($record['playbacks'])) {
foreach ($record['playbacks'] as $item) {
$link = new Link();
$params['url'] = $item['url'];
$params['title'] = 'bbb 1';
$id = $link->save($params);
return $id;
}
}
}
}
}
return false;
}
function is_server_running() {
return true;
//return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
}
}