First running version of OpenMeetings plugin - still misses new meeting creation code - refs BT#7046 refs #5491

1.9.x
Yannick Warnier 11 years ago
parent 573c858ceb
commit ccbbda832a
  1. 2
      plugin/openmeetings/config.php
  2. 299
      plugin/openmeetings/lib/openmeetings.class.php
  3. 184
      plugin/openmeetings/lib/openmeetings_gateway.php
  4. 6
      plugin/openmeetings/lib/openmeetings_plugin.class.php
  5. 14
      plugin/openmeetings/lib/openmeetings_rest_service.php
  6. 14
      plugin/openmeetings/lib/room.class.php
  7. 8
      plugin/openmeetings/listing.php
  8. 87
      plugin/openmeetings/start.php

@ -6,7 +6,7 @@
require_once '../../main/inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'plugin.class.php';
require_once 'lib/openmeetings.lib.php';
require_once 'lib/openmeetings.class.php';
require_once 'lib/openmeetings_plugin.class.php';
require_once 'lib/openmeetings_gateway.php';
require_once 'lib/openmeetings_rest_service.php';

@ -7,6 +7,7 @@
/**
* Initialization
*/
namespace Chamilo\Plugin\OpenMeetings;
include_once __DIR__.'/session.class.php';
include_once __DIR__.'/room.class.php';
include_once __DIR__.'/user.class.php';
@ -27,6 +28,9 @@ class OpenMeetings
public $plugin_enabled = false;
public $sessionId = "";
public $roomName = '';
public $chamiloCourseId;
public $chamiloSessionId;
public $externalType;
/**
* Constructor (generates a connection to the API and the Chamilo settings
@ -35,14 +39,21 @@ class OpenMeetings
function __construct()
{
// initialize video server settings from global settings
$plugin = OpenMeetingsPlugin::create();
$plugin = \OpenMeetingsPlugin::create();
$om_plugin = $plugin->get('tool_enable');
$om_host = $plugin->get('host');
$om_user = $plugin->get('user');
$om_pass = $plugin->get('pass');
global $_configuration;
$accessUrl = api_get_access_url($_configuration['access_url']);
$this->externalType = substr($accessUrl['url'],strpos($accessUrl['url'],'://')+3,-1);
if (strcmp($this->externalType,'localhost') == 0) {
$this->externalType = substr(api_get_path(WEB_PATH),strpos(api_get_path(WEB_PATH),'://')+3,-1);
}
$this->externalType = 'chamilolms.'.$this->externalType;
$this->table = Database::get_main_table('plugin_openmeetings');
$this->table = \Database::get_main_table('plugin_openmeetings');
if ($om_plugin) {
$user_info = api_get_user_info();
@ -56,10 +67,19 @@ class OpenMeetings
define('CONFIG_OPENMEETINGS_PASS', $this->pass);
define('CONFIG_OPENMEETINGS_SERVER_URL', $this->url);
$this->gateway = new OpenMeetingsGateway();
$this->gateway = new \OpenMeetingsGateway($this->url, $this->user, $this->pass);
$this->plugin_enabled = $om_plugin;
// The room has a name composed of C + course ID + '-' + session ID
$this->roomName = 'C'.api_get_course_int_id().'-'.api_get_session_id();
$this->chamiloCourseId = api_get_course_int_id();
$this->chamiloSessionId = api_get_session_id();
$this->roomName = 'C'.$this->chamiloCourseId.'-'.$this->chamiloSessionId;
$return = $this->gateway->loginUser();
if ($return == 0) {
$msg = 'Could not initiate session with server through OpenMeetingsGateway::loginUser()';
error_log(__FILE__.'+'.__LINE__.': '.$msg);
die($msg);
}
$this->sessionId = $this->gateway->sessionId;
}
}
/**
@ -77,100 +97,103 @@ class OpenMeetings
* It is similar to opening a PHP session. In fact, the session ID is kept
* inside the $_SESSION['openmeetings_session'] session variable
* @return bool True if the user is correct and false when is incorrect
* @deprecated loginUser now called at object instanciation
*/
/**
function loginUser()
{
try {
//$objGetSession = new Chamilo\Plugin\OpenMeetings\Session();
//$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/UserService?wsdl";
//$omServices = new SoapClient( $urlWsdl );
//Verifying if there is already an active session
if (empty($_SESSION['openmeetings_session'])) {
//$gsFun = $omServices->getSession($objGetSession);
//$loginUser = $omServices->loginUser(array('SID' => $this->sessionId, 'username' => $this->user, 'userpass' => $this->pass));
$loginUser = $this->gateway->loginUser();
$this->sessionId = $_SESSION['openmeetings_session'] = $this->gateway->session_id;
if ($loginUser) {
//error_log(__FILE__.' '.__LINE__.' user logged in and received session ID '.$this->gateway->session_id);
// Login user returns either 0 or >0, depending on the results
// Technically, as long as the SOAP user has been configured in OpenMeetings and OpenMeetings is on, this should always succeed.
if ($this->gateway->loginUser()) {
$this->sessionId = $_SESSION['openmeetings_session'] = $this->gateway->session_id;
return true;
} else {
//error_log(__FILE__.' '.__LINE__);
error_log('loginUser did not succeed');
return false;
}
} else {
//error_log(__FILE__.' '.__LINE__.' '.$_SESSION['openmeetings_session']);
$this->sessionId = $_SESSION['openmeetings_session'];
return true;
}
} catch (SoapFault $e) {
echo "<h1>Warning</h1>
<p>We have detected some problems </br>
Fault: {$e->faultstring}</p>";
return false;
error_log(__FILE__.'+'.__LINE__.' Warning: We have detected some problems. Fault: '.$e->faultstring);
return false;
}
}
*/
/*
* Creating a Room for the meeting
* @return bool True if the user is correct and false when is incorrect
*/
function createMeeting($params)
{
//$id = Database::insert($this->table, $params);
try {
$objAddRoom = new Chamilo\Plugin\OpenMeetings\Room();
$roomTypeId = $isModerated = ( $this->isTeacher() ) ? 1 : 2 ;
$params['c_id'] = api_get_course_int_id();
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/RoomService?wsdl";
$objAddRoom->SID = $this->sessionId;
$objAddRoom->name = $this->roomName;
$objAddRoom->roomtypes_id = $roomTypeId;
$objAddRoom->comment = get_lang('Course').': ' . $params['meeting_name'] . ' Plugin for Chamilo';
$objAddRoom->numberOfPartizipants = 40;
$objAddRoom->ispublic = true;
$objAddRoom->appointment = false;
$objAddRoom->isDemoRoom = false;
$objAddRoom->demoTime = false;
$objAddRoom->isModeratedRoom = $isModerated;
$objAddRoom->externalRoomType = 'chamilolms';
$omServices = new SoapClient($urlWsdl, array("trace" => 1, "exceptions" => true, "cache_wsdl" => WSDL_CACHE_NONE));
//$id = \Database::insert($this->table, $params);
// First, try to see if there is an active room for this course and session
$roomId = null;
$meetingData = \Database::select('*', $this->table, array('where' => array('c_id = ?' => $this->chamiloCourseId, ' AND session_id = ? ' => $this->chamiloSessionId)), 'first');
if (count($meetingData) > 0) {
//error_log('Found previous room reference - reusing');
// There has been a room in the past for this course. It should
// still be on the server, so update (instead of creating a new one)
// This fills the following attributes: status, name, comment, chamiloCourseId, chamiloSessionId
$room = new Room();
$room->loadRoomId($meetingData['room_id']);
$roomArray = (array)$room;
$roomArray['SID'] = $this->sessionId;
$roomId = $this->gateway->updateRoomWithModeration($room);
if ($roomId != $meetingData['room_id']) {
$msg = 'Something went wrong: the updated room ID ('.$roomId.') is not the same as the one we had ('.$meetingData['room_id'].')';
error_log($msg);
die($msg);
}
try {
$s = $omServices->addRoomWithModerationAndExternalType($objAddRoom);
//error_log($omServices->__getLastRequest());
//error_log($omServices->__getLastResponse());
error_log(print_r($s,1));
} catch (SoapFault $e) {
echo "<h1>Warning</h1>
<p>We have detected some problems </br>
Fault: {$e->faultstring}</p>";
return -1;
} else {
error_log('Found no previous room - creating');
$room = new Room();
// Room types are described here http://openmeetings.apache.org/RoomService.html#addRoomWithModerationAndExternalType
// 1 = Conference, 2 = Audience, 3 = Restricted, 4 = Interview
$roomTypeId = ( $this->isTeacher() ) ? 1 : 2 ;
$isModerated = ($roomTypeId > 0); //bool
$urlWsdl = $this->url . "/services/RoomService?wsdl";
$room->SID = $this->sessionId;
$room->name = $this->roomName;
$room->roomtypes_id = $roomTypeId;
$room->comment = get_lang('Course').': ' . $params['meeting_name'] . ' Plugin for Chamilo';
$room->numberOfPartizipants = 40;
$room->ispublic = true;
$room->appointment = false;
$room->isDemoRoom = false;
$room->demoTime = 0;
$room->isModeratedRoom = $isModerated;
$room->externalRoomType = 'chamilolms';
$roomId = $this->gateway->createRoomWithModAndType($room);
}
//if we get here, this means addRoomWithModerationAndExternalType worked
if ($s->return > -1) {
$meetingId = $params['id'] = $s->return;
if (!empty($roomId)) {
/*
// Find the biggest room_id so far, and create a new one
if (empty($roomId)) {
$roomData = \Database::select('MAX(room_id) as room_id', $this->table, array(), 'first');
$roomId = $roomData['room_id'] + 1;
}*/
$params['status'] = '1';
$params['meeting_name'] = $this->roomName;
$params['meeting_name'] = $room->name;
$params['created_at'] = api_get_utc_datetime();
$params['room_id'] = $roomId;
$params['c_id'] = api_get_course_int_id();
$params['session_id'] = api_get_session_id();
Database::insert($this->table, $params);
$id = \Database::insert($this->table, $params);
$this->joinMeeting($meetingId);
$this->joinMeeting($id);
} else {
return -1;
}
} catch(SoapFault $e) {
echo "<h1>Warning</h1>
<p>We have detected some problems </br>
Fault: {$e->faultstring}</p>";
return -1;
}
}
/**
* Returns a meeting "join" URL
@ -185,19 +208,19 @@ class OpenMeetings
if (empty($meetingId)) {
return false;
}
$meetingData = Database::select('*', $this->table, array('where' => array('id = ? AND status = 1 ' => $meetingId)), 'first');
$meetingData = \Database::select('*', $this->table, array('where' => array('id = ? AND status = 1 ' => $meetingId)), 'first');
if (empty($meetingData)) {
if ($this->debug) error_log("meeting does not exist: $meetingId ");
return false;
}
$params = array( 'room_id' => $meetingId );
$params = array( 'room_id' => $meetingData['room_id'] );
$returnVal = $this->setUserObjectAndGenerateRoomHashByURLAndRecFlag( $params );
//$urlWithoutProtocol = str_replace("http://", CONFIG_OPENMEETINGS_SERVER_URL);
//$imgWithoutProtocol = str_replace("http://", $_SESSION['_user']['avatar'] );
$iframe = CONFIG_OPENMEETINGS_SERVER_URL . "/?" .
$iframe = $this->url . "/?" .
"secureHash=" . $returnVal /*.
'&username=FRAGOTE' .
'&firstname=DD' .
@ -221,6 +244,9 @@ class OpenMeetings
*/
function isServerRunning()
{
// Always return true for now as this requires the openmeetings object
// to have been instanciated and this includes a loginUser() which
// connects to the server
return true;
}
/**
@ -254,12 +280,12 @@ class OpenMeetings
try {
$result = $this->api->getMeetingInfoArray($params);
if ($result == null) {
if ($this->debug) error_log("Failed to get any response. Maybe we can't contact the OpenMeetings server.");
if ($this->debug) error_log(__FILE__.'+'.__LINE__." Failed to get any response. Maybe we can't contact the OpenMeetings server.");
} else {
return $result;
}
} catch (Exception $e) {
if ($this->debug) error_log('Caught exception: ', $e->getMessage(), "\n");
if ($this->debug) error_log(__FILE__.'+'.__LINE__.' Caught exception: ', $e->getMessage(), "\n");
}
return false;
}
@ -277,9 +303,9 @@ class OpenMeetings
$systemType = 'chamilo';
$room_id = $params['room_id'];
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/UserService?wsdl";
$omServices = new SoapClient( $urlWsdl );
$objRec = new Chamilo\Plugin\OpenMeetings\User();
$urlWsdl = $this->url . "/services/UserService?wsdl";
$omServices = new \SoapClient( $urlWsdl );
$objRec = new User();
$objRec->SID = $this->sessionId;
$objRec->username = $username;
@ -311,9 +337,9 @@ class OpenMeetings
$becomeModerator = ( $this->isTeacher() ? 1 : 0 );
$allowRecording = 1; //Provisional
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/UserService?wsdl";
$omServices = new SoapClient( $urlWsdl );
$objRec = new Chamilo\Plugin\OpenMeetings\User();
$urlWsdl = $this->url . "/services/UserService?wsdl";
$omServices = new \SoapClient( $urlWsdl );
$objRec = new User();
$objRec->SID = $this->sessionId;
$objRec->username = $username;
@ -339,18 +365,18 @@ class OpenMeetings
*/
function getCourseMeetings()
{
$new_meeting_list = array();
$newMeetingsList = array();
$item = array();
$this->loginUser();
$meeting_list = Database::select('*', $this->table, array('where' => array('c_id = ? ' => api_get_course_int_id(), ' AND session_id = ? ' => api_get_session_id())));
$meetingsList = \Database::select('*', $this->table, array('where' => array('c_id = ? ' => api_get_course_int_id(), ' AND session_id = ? ' => api_get_session_id())));
error_log(__FILE__.' '.__FUNCTION__.' '.__LINE__.' '.print_r($meeting_list,1));
//error_log(__FILE__.'+'.__LINE__.' Meetings found: '.print_r($meetingsList,1));
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/RoomService?wsdl";
$omServices = new SoapClient($urlWsdl);
$objRoom = new Chamilo\Plugin\OpenMeetings\Room();
$urlWsdl = $this->url . "/services/RoomService?wsdl";
$omServices = new \SoapClient($urlWsdl);
$room = new Room();
/*
try {
$rooms = $this->gateway->getRoomsWithCurrentUsersByType($this->sessionId);
$rooms = $this->gateway->getRoomsWithCurrentUsersByType();
//$rooms = $omServices->getRoomsPublic(array(
//'SID' => $this->sessionId,
//'start' => 0,
@ -362,23 +388,39 @@ class OpenMeetings
//)
//);
} catch (SoapFault $e) {
error_log($e->faultstring);
error_log(__FILE__.'+'.__LINE__.' '.$e->faultstring);
//error_log($rooms->getDebug());
return false;
}
$objRoom->SID = $this->sessionId;
foreach ($meeting_list as $meeting_db) {
$objRoom->rooms_id = $meeting_db['id'];
*/
$room->SID = $this->sessionId;
//error_log(__FILE__.'+'.__LINE__.' Meetings found: '.print_r($room->SID,1));
foreach ($meetingsList as $meetingDb) {
//$room->rooms_id = $meetingDb['room_id'];
//error_log(__FILE__.'+'.__LINE__.' Meetings found: '.print_r($meetingDb['room_id'],1));
$remoteMeeting = array();
$meetingDb['created_at'] = api_get_local_time($meetingDb['created_at']);
$meetingDb['closed_at'] = (!empty($meetingDb['closed_at'])?api_get_local_time($meetingDb['closed_at']):'');
// Fixed value for now
$meetingDb['participantCount'] = 40;
// The following code is currently commented because the web service
// says this is not allowed by the SOAP user.
/*
try {
$objRoomId = $omServices->getRoomById($objRoom);
// Get the conference room object from OpenMeetings server - requires SID and rooms_id to be defined
$objRoomId = $this->gateway->getRoomById($meetingDb['room_id']);
if (empty($objRoomId->return)) {
Database::delete($this->table, "id = {$meeting_db['id']}");
error_log(__FILE__.'+'.__LINE__.' Emptyyyyy ');
//\Database::delete($this->table, "id = {$meetingDb['id']}");
// Don't delete expired rooms, just mark as closed
\Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $meetingDb['id']));
continue;
}
//$objCurUs = $omServices->getRoomWithCurrentUsersById($objCurrentUsers);
} catch (SoapFault $e) {
echo $e->faultstring;
error_log(__FILE__.'+'.__LINE__.' '.$e->faultstring);
exit;
}
//if( empty($objCurUs->returnMeetingID) ) continue;
@ -409,22 +451,26 @@ class OpenMeetings
);
}
$meeting_om = $current_room;
$remoteMeeting = $current_room;
*/
if (empty( $meeting_om )) {
if ($meeting_db['status'] == 1 && $this->isTeacher()) {
$this->endMeeting($meeting_db['id']);
if (empty( $remoteMeeting )) {
/*
error_log(__FILE__.'+'.__LINE__.' Empty remote Meeting for now');
if ($meetingDb['status'] == 1 && $this->isTeacher()) {
$this->endMeeting($meetingDb['id']);
}
*/
} else {
$meeting_om['add_to_calendar_url'] = api_get_self().'?action=add_to_calendar&id='.$meeting_db['id'].'&start='.api_strtotime($meeting_db['startTime']);
$remoteMeeting['add_to_calendar_url'] = api_get_self().'?action=add_to_calendar&id='.$meetingDb['id'].'&start='.api_strtotime($meetingDb['startTime']);
}
$meeting_om['end_url'] = api_get_self().'?action=end&id='.$meeting_db['id'];
$remoteMeeting['end_url'] = api_get_self().'?action=end&id='.$meetingDb['id'];
$record_array = array();
//$record_array = array();
// if ($meeting_db['record'] == 1) {
// if ($meetingDb['record'] == 1) {
// $recordingParams = array(
// 'meetingId' => $meeting_db['id'], //-- OPTIONAL - comma separate if multiple ids
// 'meetingId' => $meetingDb['id'], //-- OPTIONAL - comma separate if multiple ids
// );
//
// $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
@ -441,8 +487,8 @@ class OpenMeetings
// 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('link.gif',get_lang('CopyToLinkTool')), api_get_self().'?action=copy_record_to_link_tool&id='.$meetingDb['id'].'&record_id='.$record['recordId']);
// $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='.$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'];
@ -459,31 +505,32 @@ class OpenMeetings
//
// }
//
//$item['created_at'] = api_convert_and_format_date($meeting_db['created_at']);
//$item['created_at'] = api_convert_and_format_date($meetingDb['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'];
// $item['publish_url'] = api_get_self().'?action=publish&id='.$meetingDb['id'];
// $item['unpublish_url'] = api_get_self().'?action=unpublish&id='.$meetingDb['id'];
//
//if ($meeting_db['status'] == 1) {
//if ($meetingDb['status'] == 1) {
// $joinParams = array(
// 'meetingId' => $meeting_db['id'], //-- REQUIRED - A unique id for the meeting
// 'meetingId' => $meetingDb['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
// );
// $returnVal = $this->setUserObjectAndGenerateRoomHashByURLAndRecFlag( array('room_id' => $meeting_db['id']) );
// $returnVal = $this->setUserObjectAndGenerateRoomHashByURLAndRecFlag( array('room_id' => $meetingDb['id']) );
// $joinUrl = CONFIG_OPENMEETINGS_SERVER_URL . "?" .
// "secureHash=" . $returnVal;
//
// $item['go_url'] = $joinUrl;
//}
$item = array_merge($item, $meeting_db, $meeting_om);
$new_meeting_list[] = $item;
}
return $new_meeting_list;
$item = array_merge($item, $meetingDb, $remoteMeeting);
//error_log(__FILE__.'+'.__LINE__.' Item: '.print_r($item,1));
$newMeetingsList[] = $item;
} //end foreach $meetingsList
return $newMeetingsList;
}
/**
@ -494,24 +541,20 @@ class OpenMeetings
function endMeeting($meetingId)
{
try {
$this->loginUser();
$urlWsdl = CONFIG_OPENMEETINGS_SERVER_URL . "/services/RoomService?wsdl";
$omServices = new SoapClient( $urlWsdl );
$objClose = new Chamilo\Plugin\OpenMeetings\Room();
$objClose->SID = $this->sessionId;
$objClose->room_id = intval($meetingId);
$objClose->status = false;
$roomClosed = $omServices->closeRoom( $objClose );
error_log('Closing');
$urlWsdl = $this->url . "/services/RoomService?wsdl";
$ws = new \SoapClient( $urlWsdl );
$room = new Room($meetingId);
$room->SID = $this->sessionId;
$room->room_id = intval($meetingId);
$room->status = false;
$roomClosed = $ws->closeRoom($room);
if ($roomClosed > 0) {
error_log('Closing returned '.print_r($roomClosed,1));
Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $meetingId));
//error_log(__FILE__.'+'.__LINE__.' Closing returned '.print_r($roomClosed,1));
\Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $meetingId));
}
error_log('Finished closing');
//error_log(__FILE__.'+'.__LINE__.' Finished closing');
} catch (SoapFault $e) {
echo "<h1>Warning</h1>
<p>We have detected some problems </br>
Fault: {$e->faultstring}</p>";
error_log(__FILE__.'+'.__LINE__.' Warning: We have detected some problems: Fault: '.$e->faultstring);
exit;
return -1;
}

@ -29,15 +29,18 @@ require_once ('openmeetings_rest_service.php');
*/
class OpenMeetingsGateway
{
public $session_id = "";
public $sessionId = "";
public $config;
private $rest;
function __construct()
private $_user;
private $_pass;
private $_url;
function __construct($host, $user, $pass)
{
$this->_user = CONFIG_OPENMEETINGS_USER;
$this->_pass = CONFIG_OPENMEETINGS_PASS;
$this->_url = CONFIG_OPENMEETINGS_SERVER_URL;
$this->_user = urlencode($user);
$this->_pass = urlencode($pass);
$this->_url = $host;
if (substr($this->_url, -1, 1) == '/') {
$this->_url = substr($this->_url, 0, -1);
}
@ -58,7 +61,6 @@ class OpenMeetingsGateway
function getUrl()
{
// FIXME protocol should be added
return $this->_url;
}
@ -76,22 +78,27 @@ class OpenMeetingsGateway
*/
function loginUser()
{
$returnValue = 0;
$response = $this->rest->call($this->getRestUrl("UserService") . "getSession", "session_id");
if ($this->rest->getError()) {
error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($response,1));
} else {
$err = $this->rest->getError();
if ($err) {
error_log('Error: ' . $err);
} else {
$this->session_id = $response;
$result = $this->rest->call($this->getRestUrl("UserService") . "loginUser?SID=" . $this->session_id
. "&username=" . urlencode(CONFIG_OPENMEETINGS_USER)
. "&userpass=" . urlencode(CONFIG_OPENMEETINGS_PASS));
//error_log('getSession returned '.$response. ' - Storing as sessionId');
$this->sessionId = $response;
$url = $this->getRestUrl("UserService")
. "loginUser?"
. "SID=" . $this->sessionId
. "&username=" . $this->_user
. "&userpass=" . $this->_pass;
$result = $this->rest->call($url);
//error_log(__FILE__.'+'.__LINE__.': '.$url);
if ($this->rest->getError()) {
error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
} else {
@ -111,7 +118,7 @@ class OpenMeetingsGateway
return false;
}
}
function updateRoomWithModeration($openmeetings)
function updateRoomWithModeration($room)
{
$err = $this->rest->getError();
if ($err) {
@ -121,15 +128,22 @@ class OpenMeetingsGateway
}
$isModeratedRoom = false;
if ($openmeetings->is_moderated_room == 1) {
if ($room->isModeratedRoom == 1) {
$isModeratedRoom = true;
}
$result = $this->rest->call($this->getRestUrl("RoomService") . "updateRoomWithModeration?SID=" . $this->session_id
. "&room_id=" . $openmeetings->room_id . "&name=" . urlencode($openmeetings->roomname) . "&roomtypes_id="
. urlencode($openmeetings->type) . "&comment=" . urlencode("Created by SOAP-Gateway")
. "&numberOfPartizipants=" . $openmeetings->max_user . "&ispublic=false" . "&appointment=false" . "&isDemoRoom=false"
. "&demoTime=0" . "&isModeratedRoom=" . $this->var_to_str($isModeratedRoom));
$result = $this->rest->call($this->getRestUrl("RoomService")
. "updateRoomWithModeration?SID=" . $this->sessionId
. "&room_id=" . $room->room_id
. "&name=" . urlencode($room->name)
. "&roomtypes_id=" . $room->roomtypes_id
. "&comment=" . $room->comment
. "&numberOfPartizipants=" . $room->numberOfPartizipants
. "&ispublic=false"
. "&appointment=false"
. "&isDemoRoom=false"
. "&demoTime=0"
. "&isModeratedRoom=" . $this->var_to_str($isModeratedRoom));
if ($result->fault) {
error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
@ -139,6 +153,7 @@ class OpenMeetingsGateway
error_log('Error: ' . $err);
} else {
// echo '<h2>Result</h2><pre>'; print_r($result["return"]); echo '</pre>';
//error_log('Room updated successfully '.print_r($result,1));
return $result;
}
}
@ -150,9 +165,15 @@ class OpenMeetingsGateway
*/
function setUserObjectAndGenerateRecordingHashByURL($username, $firstname, $lastname, $userId, $systemType, $recording_id)
{
$result = $this->rest->call($this->getRestUrl("UserService") . 'setUserObjectAndGenerateRecordingHashByURL?SID=' . $this->session_id
. '&username=' . urlencode($username) . '&firstname=' . urlencode($firstname) . '&lastname=' . urlencode($lastname)
. '&externalUserId=' . $userId . '&externalUserType=' . urlencode($systemType) . '&recording_id=' . $recording_id, 'return');
$result = $this->rest->call($this->getRestUrl("UserService")
. 'setUserObjectAndGenerateRecordingHashByURL?'
. 'SID=' . $this->sessionId
. '&username=' . urlencode($username)
. '&firstname=' . urlencode($firstname)
. '&lastname=' . urlencode($lastname)
. '&externalUserId=' . $userId
. '&externalUserType=' . urlencode($systemType)
. '&recording_id=' . $recording_id, 'return');
if ($result->fault) {
error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
@ -175,11 +196,20 @@ class OpenMeetingsGateway
exit();
}
$result = $this->rest->call($this->getRestUrl("UserService") . "setUserObjectAndGenerateRoomHashByURLAndRecFlag?SID=" . $this->session_id
. "&username=" . urlencode($username) . "&firstname=" . urlencode($firstname) . "&lastname=" . urlencode($lastname)
. "&profilePictureUrl=" . urlencode($profilePictureUrl) . "&email=" . urlencode($email) . "&externalUserId=" . urlencode($userId)
. "&externalUserType=" . urlencode($systemType) . "&room_id=" . urlencode($room_id) . "&becomeModeratorAsInt=" . $becomeModerator
. "&showAudioVideoTestAsInt=1" . "&allowRecording=" . $this->var_to_str($allowRecording));
$result = $this->rest->call($this->getRestUrl("UserService")
. "setUserObjectAndGenerateRoomHashByURLAndRecFlag?"
. "SID=" . $this->sessionId
. "&username=" . urlencode($username)
. "&firstname=" . urlencode($firstname)
. "&lastname=" . urlencode($lastname)
. "&profilePictureUrl=" . urlencode($profilePictureUrl)
. "&email=" . urlencode($email)
. "&externalUserId=" . urlencode($userId)
. "&externalUserType=" . urlencode($systemType)
. "&room_id=" . urlencode($room_id)
. "&becomeModeratorAsInt=" . $becomeModerator
. "&showAudioVideoTestAsInt=1"
. "&allowRecording=" . $this->var_to_str($allowRecording));
if ($result->fault) {
error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
@ -203,7 +233,7 @@ class OpenMeetingsGateway
exit();
}
$result = $this->rest->call($this->getRestUrl("RoomService") . "deleteRoom?SID=" . $this->session_id
$result = $this->rest->call($this->getRestUrl("RoomService") . "deleteRoom?SID=" . $this->sessionId
. "&rooms_id=" . $openmeetings->room_id);
if ($result->fault) {
@ -226,11 +256,19 @@ class OpenMeetingsGateway
*/
function setUserObjectAndGenerateRoomHash($username, $firstname, $lastname, $profilePictureUrl, $email, $externalUserId, $externalUserType, $room_id, $becomeModeratorAsInt, $showAudioVideoTestAsInt)
{
$result = $this->rest->call($this->getRestUrl("UserService") . "setUserObjectAndGenerateRoomHash?SID=" . $this->session_id
. "&username=" . urlencode($username) . "&firstname=" . urlencode($firstname) . "&lastname=" . urlencode($lastname)
. "&profilePictureUrl=" . urlencode($profilePictureUrl) . "&email=" . urlencode($email) . "&externalUserId="
. urlencode($externalUserId) . "&externalUserType=" . urlencode($externalUserType) . "&room_id=" . $room_id
. "&becomeModeratorAsInt=" . $becomeModeratorAsInt . "&showAudioVideoTestAsInt=" . $showAudioVideoTestAsInt);
$result = $this->rest->call($this->getRestUrl("UserService")
. "setUserObjectAndGenerateRoomHash?"
. "SID=" . $this->sessionId
. "&username=" . urlencode($username)
. "&firstname=" . urlencode($firstname)
. "&lastname=" . urlencode($lastname)
. "&profilePictureUrl=" . urlencode($profilePictureUrl)
. "&email=" . urlencode($email)
. "&externalUserId=" . urlencode($externalUserId)
. "&externalUserType=" . urlencode($externalUserType)
. "&room_id=" . $room_id
. "&becomeModeratorAsInt=" . $becomeModeratorAsInt
. "&showAudioVideoTestAsInt=" . $showAudioVideoTestAsInt);
if ($result->getError()) {
error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
@ -256,10 +294,18 @@ class OpenMeetingsGateway
$isModeratedRoom = "true";
}
$url = $this->getRestUrl("RoomService") . 'addRoomWithModerationAndExternalType?SID=' . $this->session_id
. '&name=' . urlencode($openmeetings->roomname) . '&roomtypes_id=' . $openmeetings->type . '&comment='
. urlencode('Created by SOAP-Gateway') . '&numberOfPartizipants=' . $openmeetings->max_user
. '&ispublic=false' . '&appointment=false' . '&isDemoRoom=false' . '&demoTime=0' . '&isModeratedRoom=' . $isModeratedRoom
$url = $this->getRestUrl("RoomService")
. 'addRoomWithModerationAndExternalType?'
. 'SID=' . $this->sessionId
. '&name=' . urlencode($openmeetings->roomname)
. '&roomtypes_id=' . $openmeetings->type
. '&comment='. urlencode('Created by SOAP-Gateway')
. '&numberOfPartizipants=' . $openmeetings->max_user
. '&ispublic=false'
. '&appointment=false'
. '&isDemoRoom=false'
. '&demoTime=0'
. '&isModeratedRoom=' . $isModeratedRoom
. '&externalRoomType=' . urlencode($this->config["moduleKey"]);
$result = $this->rest->call($url, "return");
@ -271,6 +317,7 @@ class OpenMeetingsGateway
if ($err) {
error_log('Error: '.$err);
} else {
//error_log('Creation of a new room succeeded: ID '.$result);
return $result;
}
}
@ -279,24 +326,53 @@ class OpenMeetingsGateway
/**
* Gets the list of open rooms of type "Chamilo"
* @param string $type The type of external system connecting to OpenMeetings
*/
public function getRoomsWithCurrentUsersByType($sid)
public function getRoomsWithCurrentUsersByType($type = 'chamilolms')
{
if (empty($sid)) {
if (empty($this->session_id)) {
return false;
}
$sid = $this->session_id;
//$this->loginUser();
if (empty($this->sessionId)) {
return false;
}
//$url = $this->getRestUrl("RoomService") . "getRoomsWithCurrentUsersByListAndType?SID=" . $sid
// . "&start=1&max=100&orderby=name&asc=true&externalRoomType=chamilo";
$url = $this->getRestUrl("RoomService") . "getRoomTypes?SID=" . $sid;
// . "&roomtypes_id=1";
error_log($url);
$url = $this->getRestUrl("RoomService") . "getRoomsWithCurrentUsersByListAndType?SID=" . $this->sessionId
. "&start=1&max=1000&orderby=name&asc=true&externalRoomType=chamilolms";
//$url = $this->getRestUrl("RoomService")
// . "getRoomTypes?"
// . "SID=" . $this->sessionId;
//$url = $this->getRestUrl('JabberService') . 'getAvailableRooms?SID=' . $this->sessionId;
error_log(__FILE__.'+'.__LINE__.' Calling WS: '.$url);
$result = $this->rest->call($url, "return");
error_log(print_r($result,1));
$rooms = array();
foreach ($result as $room) {
error_log(__FILE__.'+'.__LINE__.': one room found on remote: '.print_r($room,1));
if ($room['externalRoomType'] == $type && count($room['currentusers']) > 0 ) {
$rooms[] = $room;
}
}
return $result;
}
/**
* Gets details of a remote room by room ID
* @param int $roomId The ID of the room, as of plugin_openmeetings.room_id
* @return mixed Room object
*/
public function getRoomById($roomId = 0)
{
//$this->loginUser();
if (empty($this->sessionId) or empty($roomId)) {
return false;
}
$roomId = intval($roomId);
$url = $this->getRestUrl("RoomService")
. "getRoomById?"
. "SID=" . $this->sessionId
. "&rooms_id=".$roomId;
//error_log(__FILE__.'+'.__LINE__.' Calling WS: '.$url);
$result = $this->rest->call($url, "return");
return $result;
}
/**
@ -304,7 +380,9 @@ error_log($url);
*/
function getRecordingsByExternalRooms()
{
$url = $this->getRestUrl("RoomService") . "getFlvRecordingByExternalRoomType?SID=" . $this->session_id
$url = $this->getRestUrl("RoomService")
. "getFlvRecordingByExternalRoomType?"
. "SID=" . $this->sessionId
. "&externalRoomType=" . urlencode($this->config["moduleKey"]);
$result = $this->rest->call($url, "return");
@ -317,7 +395,9 @@ error_log($url);
*/
function getRecordingsByExternalUser($id)
{
$url = $this->getRestUrl("RoomService") . "getFlvRecordingByExternalUserId?SID=" . $this->session_id
$url = $this->getRestUrl("RoomService")
. "getFlvRecordingByExternalUserId?"
. "SID=" . $this->sessionId
. "&externalUserId=" . $id;
$result = $this->rest->call($url, "return");

@ -1,5 +1,4 @@
<?php
class OpenMeetingsPlugin extends Plugin
{
public $is_course_plugin = true;
@ -23,10 +22,15 @@ class OpenMeetingsPlugin extends Plugin
function install()
{
$table = Database::get_main_table('plugin_openmeetings');
// id is the internal unique ID (keeps track of historical sessions
// status is 0 for closed, 1 for open (available)
// room_id is a reference to the meeting ID on the OpenMeetings server.
// Any c_id + session_id occurence gets a unique new meeting ID to avoid issues with the number of rooms, as indicated in https://issues.apache.org/jira/browse/OPENMEETINGS-802#comment-13860340
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
c_id INT unsigned NOT NULL DEFAULT 0,
session_id INT unsigned NOT NULL DEFAULT 0,
room_id INT unsigned NOT NULL DEFAULT 0,
meeting_name VARCHAR(255) NOT NULL DEFAULT '',
attendee_pw VARCHAR(255) NOT NULL DEFAULT '',
moderator_pw VARCHAR(255) NOT NULL DEFAULT '',

@ -57,7 +57,7 @@ class OpenMeetingsRestService
// Confirm that the request was transmitted to the OpenMeetings! Image Search Service
if (! $response) {
die ( "Request OpenMeetings! OpenMeetings Service failed and no response was returned." );
die ( "Request OpenMeetings! OpenMeetings Service failed and no response was returned in ".__CLASS__.'::'.__FUNCTION__.'()' );
}
// Create an array to store the HTTP response codes
@ -65,31 +65,33 @@ class OpenMeetingsRestService
// Use regular expressions to extract the code from the header
preg_match ( '/\d\d\d/', $response, $status_code );
$bt = debug_backtrace();
$caller = array_shift($bt);
$extra = ' (from '.$caller['file'].' at line '.$caller['line'].') ';
// Check the HTTP Response code and display message if status code is not 200 (OK)
switch ($status_code [0]) {
case 200 :
// Success
break;
case 503 :
error_log( 'Your call to OpenMeetings Web Services failed and returned an HTTP status of 503.
error_log( 'Your call to OpenMeetings Web Services '.$extra.' failed and returned an HTTP status of 503.
That means: Service unavailable. An internal problem prevented us from returning data to you.' );
return false;
break;
case 403 :
error_log( 'Your call to OpenMeetings Web Services failed and returned an HTTP status of 403.
error_log( 'Your call to OpenMeetings Web Services '.$extra.' failed and returned an HTTP status of 403.
That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.' );
return false;
break;
case 400 :
// You may want to fall through here and read the specific XML error
error_log( 'Your call to OpenMeetings Web Services failed and returned an HTTP status of 400.
error_log( 'Your call to OpenMeetings Web Services '.$extra.' failed and returned an HTTP status of 400.
That means: Bad request. The parameters passed to the service did not match as expected.
The exact error is returned in the XML response.' );
return false;
break;
default :
error_log( 'Your call to OpenMeetings Web Services returned an unexpected HTTP status of: ' . $status_code [0] . " Request " . $request );
error_log( 'Your call to OpenMeetings Web Services '.$extra.' returned an unexpected HTTP status of: ' . $status_code [0] . " Request " . $request );
return false;
}

@ -24,11 +24,21 @@ class Room
public $demoTime = 0;
public $isModeratedRoom = true;
public $externalRoomType = 'chamilolms';
public $chamiloCourseId;
public $chamiloSessionId;
private $table;
public function __construct($id = null)
public function __construct()
{
$this->table = \Database::get_main_table('plugin_openmeetings');
}
/**
* Sets the room ID and loads as much info as possible from the local table
* @param int $id The room ID (from table.room_id)
*/
public function loadRoomId($id)
{
if (!empty($id)) {
$roomData = \Database::select('*', $this->table, array('where' => array('id = ?' => $id)), 'first');
if (!empty($roomData)) {
@ -36,6 +46,8 @@ class Room
$this->status = $roomData['status'];
$this->name = $roomData['meeting_name'];
$this->comment = $roomData['welcome_msg'];
$this->chamiloCourseId = $roomData['c_id'];
$this->chamiloSessionId = $roomData['session_id'];
}
}
}

@ -9,11 +9,11 @@
$course_plugin = 'openmeetings'; //needed in order to load the plugin lang variables
require_once dirname(__FILE__).'/config.php';
$plugin = openmeetingsPlugin::create();
$plugin = \OpenMeetingsPlugin::create();
$tool_name = $plugin->get_lang('Videoconference');
$tpl = new Template($tool_name);
$om = new OpenMeetings();
$om = new Chamilo\Plugin\OpenMeetings\OpenMeetings();
$action = isset($_GET['action']) ? $_GET['action'] : null;
$teacher = $om->isTeacher();
@ -60,9 +60,11 @@ if ($teacher) {
$message = Display::return_message(get_lang('MeetingClosed').'<br />'.get_lang('MeetingClosedComment'), 'success', false);
break;
case 'publish':
// Not implemented yet
//$result = $om->publish_meeting($_GET['id']);
break;
case 'unpublish':
// Not implemented yet
//$result = $om->unpublish_meeting($_GET['id']);
break;
default:
@ -74,7 +76,7 @@ $meetings = $om->getCourseMeetings();
if (!empty($meetings)) {
$meetings = array_reverse($meetings);
}
error_log(__FILE__.':'.__LINE__.': '.print_r($meetings,1));
//error_log(__FILE__.':'.__LINE__.': '.print_r($meetings,1));
$users_online = $meetings->participantCount;
//$status = !$meetings->isClosed;

@ -11,61 +11,64 @@ $course_plugin = 'openmeetings'; //needed in order to load the plugin lang varia
require_once dirname(__FILE__).'/config.php';
$tool_name = get_lang('Videoconference');
$tpl = new Template($tool_name);
$om = new OpenMeetings();
$om = new \Chamilo\Plugin\OpenMeetings\OpenMeetings();
if ($om->plugin_enabled) {
if ($om->isServerRunning()) {
if ($om->isServerRunning()) {
if (isset($_GET['launch']) && $_GET['launch'] == 1) {
if (isset($_GET['launch']) && $_GET['launch'] == 1) {
$meeting_params = array();
$meeting_params['meeting_name'] = api_get_course_id().'-'.api_get_session_id();
$meetings = $om->getCourseMeetings();
$meeting_params = array();
$meeting_params['meeting_name'] = api_get_course_id().'-'.api_get_session_id();
$meetings = $om->getCourseMeetings();
// Select the meeting with more participantCount.
$selectedMeeting = array();
if (!empty($meetings)) {
$max = 0;
foreach ($meetings as $meeting) {
if ($meeting['participantCount'] > $max) {
$selectedMeeting = $meeting;
$max = $meeting['participantCount'];
}
$selectedMeeting = array();
/*
// Select the meeting with more participantCount.
if (!empty($meetings)) {
$max = 0;
foreach ($meetings as $meeting) {
if ($meeting['participantCount'] > $max) {
$selectedMeeting = $meeting;
$max = $meeting['participantCount'];
}
}
}
*/
// Check for the first meeting available with status = 1
// (there should be only one at a time, as createMeeting checks for that first
foreach ($meetings as $meeting) {
if ($meeting['status'] == 1) {
$selectedMeeting = $meeting;
}
}
if (!empty($selectedMeeting)) {
//if (false/*$om->meeting_exists($meeting_params['meeting_name'])*/) {
$url = $om->joinMeeting($selectedMeeting['id']);
if ($url) {
header('location: '.$url);
exit;
}
} else {
if ($om->loginUser() && !empty($selectedMeeting)) {
//if (false/*$om->meeting_exists($meeting_params['meeting_name'])*/) {
$url = $om->joinMeeting($selectedMeeting['id']);
if ($url) {
header('location: '.$url);
exit;
}
} else {
if ( $om->isTeacher() && $om->loginUser()) {
if ( $om->isTeacher()) {
//$url =
$om->createMeeting($meeting_params);
//header('location: '.$url);
exit;
} else {
$url = 'listing.php';
header('location: '.$url);
exit;
}
//$url =
$om->createMeeting($meeting_params);
//header('location: '.$url);
exit;
} else {
$url = 'listing.php';
header('location: '.$url);
exit;
}
} else {
$url = 'listing.php';
header('location: '.$url);
exit;
}
} else {
$message = Display::return_message(get_lang('ServerIsNotRunning'), 'warning');
$url = 'listing.php';
header('location: '.$url);
exit;
}
} else {
$message = Display::return_message(get_lang('ServerIsNotConfigured'), 'warning');
$message = Display::return_message(get_lang('ServerIsNotRunning'), 'warning');
}
$tpl->assign('message', $message);
$tpl->display_one_col_template();

Loading…
Cancel
Save