First working implementation of the BBB plugin. Still requires updates to course homepage and course settings.
parent
5f736886d8
commit
0140f02310
@ -0,0 +1,314 @@ |
||||
<?php |
||||
/** |
||||
* This file contains the helper libraries for the BigBlueButton conference plugin. |
||||
* It is based on code written by Dual Code Inc in GNU/GPLv2 |
||||
* Copyright (C) 2010 Dual Code Inc. (www.dualcode.com) |
||||
* Copyright (C) 2010 BeezNest Belgium SPRL (www.beeznest.com) - Yannick Warnier - y@beeznest.com |
||||
*/ |
||||
/** |
||||
* Inserts an item into the plugin_bbb table |
||||
*/ |
||||
function bigbluebutton_insert_record($table,$object) { |
||||
//ignore the first param (used for compatibility with existing code) |
||||
$table = Database::get_main_table('plugin_bbb'); |
||||
$sql = "INSERT INTO $table (course_id, name, meeting_name, meeting_id, attendee_pw, moderator_pw, auto_login, new_window, welcome_msg)" . |
||||
"VALUES (" . |
||||
intval($object->course) .", " . |
||||
"'".Database::escape_string($object->name)."'," . |
||||
"'".Database::escape_string($object->meetingname)."'," . |
||||
"'".Database::escape_string($object->meetingid)."'," . |
||||
"'".Database::escape_string($object->attendeepw)."'," . |
||||
"'".Database::escape_string($object->moderatorpw)."'," . |
||||
"'".Database::escape_string($object->autologin)."'," . |
||||
"'".Database::escape_string($object->newwindow)."'," . |
||||
"'".Database::escape_string($object->welcomemsg)."'" . |
||||
")"; |
||||
Database::query($sql); |
||||
return Database::insert_id(); |
||||
} |
||||
/** |
||||
* Updates a bigbluebutton record |
||||
*/ |
||||
function bigbluebutton_update_record($table, $object) { |
||||
//ignore the first param (used for compatibility with existing code) $table = Database::get_main_table('plugin_bbb'); |
||||
$sql = "UPDATE $table (course_id, name, meeting_name, meeting_id, attendee_pw, moderator_pw, auto_login, new_window, welcome_msg)" . |
||||
" SET course_id = ".intval($object->course) .", " . |
||||
" name = '".Database::escape_string($object->name)."'," . |
||||
" meeting_name = '".Database::escape_string($object->meetingname)."'," . |
||||
" meeting_id = '".Database::escape_string($object->meetingid)."'," . |
||||
" attendee_pw = '".Database::escape_string($object->attendeepw)."'," . |
||||
" moderator_pw = '".Database::escape_string($object->moderatorpw)."'," . |
||||
" auto_login = '".Database::escape_string($object->autologin)."'," . |
||||
" new_window = '".Database::escape_string($object->newwindow)."'," . |
||||
" welcome_msg = '".Database::escape_string($object->welcomemsg)."'," . |
||||
" WHERE id = " .intval($object->id). |
||||
")"; |
||||
Database::query($sql); |
||||
return $oject->id; |
||||
} |
||||
/** |
||||
* Gets a bigbluebutton room record from an ID |
||||
*/ |
||||
function bigbluebutton_get_record($table,$field,$id) { |
||||
//ignore the first param (used for compatibility with existing code) |
||||
$table = Database::get_main_table('plugin_bbb'); |
||||
$sql = "SELECT * FROM $table WHERE id = ".intval($id); |
||||
$res = Database::query($sql); |
||||
if (Database::num_rows($res)>0) { |
||||
$row = Database::fetch_assoc($res); |
||||
$room = null; |
||||
$room->id = $id; |
||||
$room->course = $row['course_id']; |
||||
$room->name = $row['name']; |
||||
$room->meetingname = $row['meeting_name']; |
||||
$room->meetingid = $row['meeting_id']; |
||||
$room->attendeepw = $row['attendee_pw']; |
||||
$room->moderatorpw = $row['moderator_pw']; |
||||
$room->autologin = $row['auto_login']; |
||||
$room->newwindow = $row['new_window']; |
||||
$room->welcomemsg = $row['welcome_msg']; |
||||
return $room; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
/** |
||||
* Gets a bigbluebutton room record from an ID |
||||
*/ |
||||
function bigbluebutton_delete_records($table,$field,$id) { |
||||
//ignore the first param (used for compatibility with existing code) |
||||
$table = Database::get_main_table('plugin_bbb'); |
||||
$sql = "DELETE FROM $table WHERE id = ".intval($id); |
||||
} |
||||
/** |
||||
* Add an event |
||||
*/ |
||||
function bigbluebutton_add_event($event) { |
||||
// |
||||
} |
||||
/** |
||||
* Given an object containing all the necessary data, |
||||
* (defined by the form in mod.html) this function |
||||
* will create a new instance and return the id number |
||||
* of the new instance. |
||||
*/ |
||||
function bigbluebutton_add_instance($bigbluebutton) { |
||||
$bigbluebutton->timemodified = time(); |
||||
if ($returnid = bigbluebutton_insert_record('bigbluebutton', $bigbluebutton)) { |
||||
$event = NULL; |
||||
$event->courseid = $bigbluebutton->course; |
||||
$event->name = $bigbluebutton->name; |
||||
$event->meetingname = $bigbluebutton->meetingname; |
||||
$event->meetingid = $bigbluebutton->meetingid; |
||||
$event->attendeepw = $bigbluebutton->attendeepw; |
||||
$event->moderatorpw = $bigbluebutton->moderatorpw; |
||||
$event->autologin = $bigbluebutton->autologin; |
||||
$event->newwindow = $bigbluebutton->newwindow; |
||||
$event->welcomemsg = $bigbluebutton->welcomemsg; |
||||
bigbluebutton_add_event($event); |
||||
} |
||||
return $returnid; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Given an object containing all the necessary data, |
||||
* (defined by the form in mod.html) this function |
||||
* will update an existing instance with new data. |
||||
*/ |
||||
function bigbluebutton_update_instance($bigbluebutton) { |
||||
$bigbluebutton->timemodified = time(); |
||||
$bigbluebutton->id = $bigbluebutton->instance; |
||||
if ($returnid = bigbluebutton_update_record('bigbluebutton', $bigbluebutton)) { |
||||
/* |
||||
$event = NULL; |
||||
if ($event->id = bigbluebutton_get_field('event', 'id', 'modulename', 'bigbluebutton', 'instance', $bigbluebutton->id)) { |
||||
$event->courseid = $bigbluebutton->course; |
||||
$event->name = $bigbluebutton->name; |
||||
$event->meetingname = $bigbluebutton->meetingname; |
||||
$event->meetingid = $bigbluebutton->meetingid; |
||||
$event->attendeepw = $bigbluebutton->attendeepw; |
||||
$event->moderatorpw = $bigbluebutton->moderatorpw; |
||||
$event->autologin = $bigbluebutton->autologin; |
||||
$event->newwindow = $bigbluebutton->newwindow; |
||||
$event->welcomemsg = $bigbluebutton->welcomemsg; |
||||
bigbluebutton_update_event($event); |
||||
}*/ |
||||
} |
||||
return $returnid; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* Given an ID of an instance of this module, |
||||
* this function will permanently delete the instance |
||||
* and any data that depends on it. |
||||
*/ |
||||
function bigbluebutton_delete_instance($id) { |
||||
if (! $bigbluebutton = bigbluebutton_get_record('bigbluebutton', 'id', $id)) { |
||||
return false; |
||||
} |
||||
|
||||
$result = true; |
||||
|
||||
# Delete any dependent records here # |
||||
|
||||
if (! bigbluebutton_delete_records('bigbluebutton', 'id', $bigbluebutton->id)) { |
||||
$result = false; |
||||
} |
||||
/* |
||||
$pagetypes = page_import_types('mod/bigbluebutton/'); |
||||
foreach($pagetypes as $pagetype) { |
||||
if(!delete_records('block_instance', 'pageid', $bigbluebutton->id, 'pagetype', $pagetype)) { |
||||
$result = false; |
||||
} |
||||
} |
||||
*/ |
||||
/* |
||||
if (! bigbluebutton_delete_records('event', 'modulename', 'bigbluebutton', 'instance', $bigbluebutton->id)) { |
||||
$result = false; |
||||
} |
||||
*/ |
||||
return $result; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Create string where we check if the meeting is running |
||||
*/ |
||||
function wc_isMeetingRunningURL($myIP,$mySecuritySalt,$myMeetingID) { |
||||
$checkAPI = "/bigbluebutton/api/isMeetingRunning?"; |
||||
$queryStr = "meetingID=".$myMeetingID; |
||||
$checksum = sha1('isMeetingRunning'.$queryStr.$mySecuritySalt); |
||||
$secQueryURL = "http://".$myIP.$checkAPI.$queryStr."&checksum=".$checksum; |
||||
|
||||
return $secQueryURL; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Determine if the meeting is already running (e.g. has attendees in it) |
||||
*/ |
||||
function wc_isMeetingRunning($myIP,$mySecuritySalt,$myMeetingID) { |
||||
$secQueryURL = wc_isMeetingRunningURL($myIP,$mySecuritySalt,$myMeetingID); |
||||
$myResponse = @file_get_contents($secQueryURL); |
||||
if ($myResponse === false) { return false;} |
||||
$doc = new DOMDocument(); |
||||
$doc->loadXML($myResponse); |
||||
$returnCodeNode = $doc->getElementsByTagName("returncode"); |
||||
$returnCode = $returnCodeNode->item(0)->nodeValue; |
||||
$runningNode = $doc->getElementsByTagName("running"); |
||||
$isRunning = $runningNode->item(0)->nodeValue; |
||||
return $isRunning; |
||||
} |
||||
|
||||
/** |
||||
* Create meeting if it's not already running |
||||
*/ |
||||
function wc_createMeeting($myIP,$mySecuritySalt,$myMeetingName,$myMeetingID,$myAttendeePW,$myModeratorPW,$myWelcomeMsg,$myLogoutURL) { |
||||
$createAPI = "/bigbluebutton/api/create?"; |
||||
$myVoiceBridge = rand(70000,79999); |
||||
$queryStr = "name=".urlencode($myMeetingName)."&meetingID=".urlencode($myMeetingID)."&attendeePW=".urlencode($myAttendeePW)."&moderatorPW=".urlencode($myModeratorPW)."&voiceBridge=".$myVoiceBridge."&welcome=".urlencode($myWelcomeMsg)."&logoutURL=".urlencode($myLogoutURL); |
||||
$checksum = sha1('create'.$queryStr.$mySecuritySalt); |
||||
$secQueryURL = "http://".$myIP.$createAPI.$queryStr."&checksum=".$checksum; |
||||
$myResponse = @file_get_contents($secQueryURL); |
||||
if ($myResponse === false) { return false; } |
||||
$doc= new DOMDocument(); |
||||
$doc->loadXML($myResponse); |
||||
$returnCodeNode = $doc->getElementsByTagName("returncode"); |
||||
$returnCode = $returnCodeNode->item(0)->nodeValue; |
||||
|
||||
if ($returnCode=="SUCCESS") { |
||||
return $returnCode; |
||||
} else { |
||||
$messageKeyNode = $doc->getElementsByTagName("messageKey"); |
||||
$messageKey = $messageKeyNode->item(0)->nodeValue; |
||||
return $messageKey; |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Create a URL to join the meeting |
||||
*/ |
||||
function wc_joinMeetingURL($myIP,$mySecuritySalt,$myName,$myMeetingID,$myPassword,$userID) { |
||||
$joinAPI = "/bigbluebutton/api/join?"; |
||||
$queryStr = "fullName=".urlencode($myName)."&meetingID=".urlencode($myMeetingID)."&password=".urlencode($myPassword)."&userID=".$userID; |
||||
$checksum = sha1('join'.$queryStr.$mySecuritySalt); |
||||
$createStr = "http://".$myIP.$joinAPI.$queryStr."&checksum=".$checksum; |
||||
|
||||
return $createStr; |
||||
} |
||||
|
||||
/** |
||||
* This API is not yet supported in bigbluebutton |
||||
*/ |
||||
function wc_endMeeting($myIP,$mySecuritySalt,$myMeetingID,$myModeratorPW) { |
||||
$endAPI = "/bigbluebutton/api/end?"; |
||||
$myVoiceBridge = rand(70000,79999); |
||||
$queryStr = "meetingID=".$myMeetingID."&moderatorPW=".$myModeratorPW."&voiceBridge=".$myVoiceBridge; |
||||
$checksum = sha1('create'.$queryStr.$mySecuritySalt); |
||||
$secQueryURL = "http://".$myIP.$endAPI.$queryStr."&checksum=".$checksum; |
||||
$myResponse = @file_get_contents($secQueryURL); |
||||
if ($myResponse === false) { return false; } |
||||
$doc= new DOMDocument(); |
||||
$doc->loadXML($myResponse); |
||||
$returnCodeNode = $doc->getElementsByTagName("returncode"); |
||||
$returnCode = $returnCodeNode->item(0)->nodeValue; |
||||
if ($returnCode=="SUCCESS") { |
||||
return $returnCode; |
||||
} else { |
||||
$messageKeyNode = $doc->getElementsByTagName("messageKey"); |
||||
$messageKey = $messageKeyNode->item(0)->nodeValue; |
||||
return $messageKey; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* This API is not yet supported in bigbluebutton |
||||
*/ |
||||
function wc_listAttendees() { |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* This API is not yet supported in bigbluebutton |
||||
*/ |
||||
function wc_getMeetingInfo() { |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* Determine the URL of the current page (for logoutURL) |
||||
*/ |
||||
function wc_currentPageURL() { |
||||
$isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on"); |
||||
$port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443"))); |
||||
$port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : ''; |
||||
$pageURL = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"]; |
||||
return $pageURL; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Determine the IP/Domain of the current Corporate University |
||||
*/ |
||||
function wc_currentDomain() { |
||||
$currentDomain = $_SERVER["SERVER_NAME"]; |
||||
return $currentDomain; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Determine if a new version of the plug-in is available |
||||
*/ |
||||
function wc_needUpgrade() { |
||||
$returnValue = false; |
||||
$installedVersion = "20100805"; |
||||
$availableVersion = dc_getVersion(); |
||||
if ((int)$installedVersion < (int)$availableVersion) { |
||||
$returnValue = true; |
||||
} |
||||
return $returnValue; |
||||
} |
@ -0,0 +1,45 @@ |
||||
<?php |
||||
/** |
||||
* This script closes a videoconference session, calling the BigBlueButton API |
||||
*/ |
||||
require_once '../../main/inc/global.inc.php'; |
||||
require_once 'bbb.lib.php'; |
||||
//The script receives the course_code (cidReq), which allows it to get the corresponding data |
||||
$cid = api_get_real_course_id(); |
||||
$ccode = api_get_course_id(); |
||||
// initialize conference settings from course settings |
||||
$meeting_name = api_get_course_setting('big_blue_button_meeting_name',$ccode); |
||||
if (empty($meeting_name) or $meeting_name==-1) { $meeting_name = $ccode; } |
||||
$meeting_att_pw = api_get_course_setting('big_blue_button_meeting_attendee_pw',$ccode); |
||||
if (empty($meeting_att_pw) or $meeting_att_pw==-1) { $meeting_att_pw = $ccode; } |
||||
$meeting_mod_pw = api_get_course_setting('big_blue_button_meeting_moderator_pw',$ccode); |
||||
if (empty($meeting_mod_pw) or $meeting_mod_pw==-1) { $meeting_mod_pw = $ccode.'mod'; } |
||||
$meeting_wel_ms = api_get_course_setting('big_blue_button_meeting_welcome_message',$ccode); |
||||
if (empty($meeting_wel_ms) or $meeting_wel_ms==-1) { $meeting_wel_ms = ''; } |
||||
|
||||
// initialize video server settings from global settings |
||||
$settings = api_get_settings('Extra','list',api_get_current_access_url_id()); |
||||
$bbb_settings = array(); |
||||
foreach ($settings as $setting) { |
||||
if (substr($setting['variable'],0,4)==='bbb_') { |
||||
$bbb_settings[$setting['variable']] = $setting['selected_value']; |
||||
} |
||||
} |
||||
$bbb_plugin = $bbb_settings['bbb_plugin'] === 'true'; |
||||
$bbb_host = $bbb_settings['bbb_plugin_host']; |
||||
$bbb_salt = $bbb_settings['bbb_plugin_salt']; |
||||
|
||||
if (!$bbb_plugin) { |
||||
//the BigBlueButton plugin is not enabled (strangely), return to course homepage |
||||
header('location: '.api_get_path(WEB_COURSE_PATH).'/'.$ccode); |
||||
} |
||||
$teacher = api_is_course_admin() || api_is_coach(); |
||||
$user_info = api_get_user_info(); |
||||
$full_user_name = api_get_person_name($user_info['firstname'],$user_info['lastname']); |
||||
|
||||
$is_running = wc_isMeetingRunning($bbb_host,$bbb_salt,$meeting_name); |
||||
if ($is_running == 'true' && $teacher) { |
||||
wc_endMeeting($bbb_host,$bbb_salt,$meeting_name,$meeting_mod_pw); |
||||
} else { //$is_running = false or 'false' |
||||
header('location: '.api_get_path(WEB_COURSE_PATH).'/'.$ccode); |
||||
} |
@ -0,0 +1,51 @@ |
||||
<?php |
||||
/** |
||||
* This script initiates a videoconference session, calling the BigBlueButton API |
||||
*/ |
||||
require_once '../../main/inc/global.inc.php'; |
||||
require_once 'bbb.lib.php'; |
||||
//The script receives the course_code (cidReq), which allows it to get the corresponding data |
||||
$cid = api_get_real_course_id(); |
||||
$ccode = api_get_course_id(); |
||||
// initialize conference settings from course settings |
||||
$meeting_name = api_get_course_setting('big_blue_button_meeting_name',$ccode); |
||||
if (empty($meeting_name) or $meeting_name==-1) { $meeting_name = $ccode; } |
||||
$meeting_att_pw = api_get_course_setting('big_blue_button_meeting_attendee_pw',$ccode); |
||||
if (empty($meeting_att_pw) or $meeting_att_pw==-1) { $meeting_att_pw = $ccode; } |
||||
$meeting_mod_pw = api_get_course_setting('big_blue_button_meeting_moderator_pw',$ccode); |
||||
if (empty($meeting_mod_pw) or $meeting_mod_pw==-1) { $meeting_mod_pw = $ccode.'mod'; } |
||||
$meeting_wel_ms = api_get_course_setting('big_blue_button_meeting_welcome_message',$ccode); |
||||
if (empty($meeting_wel_ms) or $meeting_wel_ms==-1) { $meeting_wel_ms = ''; } |
||||
|
||||
// initialize video server settings from global settings |
||||
$settings = api_get_settings('Extra','list',api_get_current_access_url_id()); |
||||
$bbb_settings = array(); |
||||
foreach ($settings as $setting) { |
||||
if (substr($setting['variable'],0,4)==='bbb_') { |
||||
$bbb_settings[$setting['variable']] = $setting['selected_value']; |
||||
} |
||||
} |
||||
$bbb_plugin = $bbb_settings['bbb_plugin'] === 'true'; |
||||
$bbb_host = $bbb_settings['bbb_plugin_host']; |
||||
$bbb_salt = $bbb_settings['bbb_plugin_salt']; |
||||
|
||||
if (!$bbb_plugin) { |
||||
//the BigBlueButton plugin is not enabled (strangely), return to course homepage |
||||
header('location: '.api_get_path(WEB_COURSE_PATH).'/'.$ccode); |
||||
} |
||||
$teacher = api_is_course_admin() || api_is_coach(); |
||||
$user_info = api_get_user_info(); |
||||
$full_user_name = api_get_person_name($user_info['firstname'],$user_info['lastname']); |
||||
$user_id = api_get_user_id(); |
||||
|
||||
$is_running = wc_isMeetingRunning($bbb_host,$bbb_salt,$meeting_name); |
||||
if ($is_running == 'true') { |
||||
header('location: '.wc_joinMeetingURL($bbb_host,$bbb_salt,$full_user_name,$meeting_name,($teacher?$meeting_mod_pw:$meeting_att_pw),$user_id)); |
||||
} else { //$is_running = false or 'false' |
||||
if ($teacher) { |
||||
wc_createMeeting($bbb_host,$bbb_salt,$meeting_name,$meeting_name,$meeting_att_pw,$meeting_mod_pw,$meeting_wel_ms,api_get_path(WEB_COURSE_PATH).'/'.$ccode); |
||||
header('location: '.wc_joinMeetingURL($bbb_host,$bbb_salt,$full_user_name,$meeting_name,$meeting_mod_pw,$user_id)); |
||||
} else { |
||||
header('location: '.api_get_path(WEB_COURSE_PATH).'/'.$ccode); |
||||
} |
||||
} |
Loading…
Reference in new issue