/** * * @global type $course_id * @global type $langBBBCreationRoomError * @global type $langBBBConnectionError * @param type $title * @param type $meeting_id * @param type $mod_pw * @param type $att_pw * @param type $record */ function create_meeting($title, $meeting_id, $mod_pw, $att_pw, $record) { global $course_id, $langBBBCreationRoomError, $langBBBConnectionError; $run_to = -1; $min_users = 10000000; //Get all course participants $users_to_join = Database::get()->querySingle("SELECT COUNT(*) AS count FROM course_user, user WHERE course_user.course_id = ?d AND course_user.user_id = user.id", $course_id)->count; //Algorithm to select BBB server GOES HERE ... if ($record == 'true') { $query = Database::get()->queryArray("SELECT * FROM bbb_servers WHERE enabled='true' AND enable_recordings=?s ORDER BY weight ASC",$record); } else { $query = Database::get()->queryArray("SELECT * FROM bbb_servers WHERE enabled='true' ORDER BY weight ASC"); } if ($query) { foreach ($query as $row) { $max_rooms = $row->max_rooms; $max_users = $row->max_users; // GET connected Participants $connected_users = get_connected_users($row->server_key, $row->api_url, $row->ip); $active_rooms = get_active_rooms($row->server_key,$row->api_url); if ($connected_users<$min_users) { $run_to=$row->id; $min_users = $connected_users; } //cases // max_users = 0 && max_rooms = 0 - UNLIMITED // active_rooms < max_rooms && active_users < max_users // active_rooms < max_rooms && max_users = 0 (UNLIMITED) // active_users < max_users && max_rooms = 0 (UNLIMITED) if (($max_rooms == 0 && $max_users == 0) || (($max_users > ($users_to_join + $connected_users)) && $active_rooms < $max_rooms) || ($active_rooms < $max_rooms && $max_users == 0) || (($max_users > ($users_to_join + $connected_users)) && $max_rooms == 0)) // YOU FOUND THE SERVER { $run_to = $row->id; Database::get()->querySingle("UPDATE bbb_session SET running_at=?s WHERE meeting_id=?s",$row->id, $meeting_id); break; } } } if ($run_to == -1) { // WE SHOULD TAKE ACTION IF NO SERVER AVAILABLE DUE TO CAPACITY PROBLEMS // If no server available we select server with min connected users $temp_conn = 10000000; $query = Database::get()->queryArray("SELECT * FROM bbb_servers WHERE enabled='true' AND enable_recordings=?s ORDER BY weight ASC",$record); if ($query) { foreach ($query as $row) { // GET connected Participants $connected_users = get_connected_users($row->server_key, $row->api_url, $row->ip); if ($connected_users<$temp_conn) { $run_to=$row->id; $temp_conn = $connected_users; } } } Database::get()->querySingle("UPDATE bbb_session SET running_at=?d WHERE meeting_id=?s",$run_to,$meeting_id); } // we find the bbb server that will serve the session $res = Database::get()->querySingle("SELECT * FROM bbb_servers WHERE id=?d", $run_to); if ($res) { $salt = $res->server_key; $bbb_url = $res->api_url; $bbb = new BigBlueButton($salt, $bbb_url); $creationParams = array( 'meetingId' => $meeting_id, // REQUIRED 'meetingName' => $title, // REQUIRED 'attendeePw' => $att_pw, // Match this value in getJoinMeetingURL() to join as attendee. 'moderatorPw' => $mod_pw, // Match this value in getJoinMeetingURL() to join as moderator. 'welcomeMsg' => '', // ''= use default. Change to customize. 'dialNumber' => '', // The main number to call into. Optional. 'voiceBridge' => '', // PIN to join voice. Optional. 'webVoice' => '', // Alphanumeric to join voice. Optional. 'logoutUrl' => '', // Default in bigbluebutton.properties. Optional. 'maxParticipants' => '-1', // Optional. -1 = unlimitted. Not supported in BBB. [number] 'record' => $record, // New. 'true' will tell BBB to record the meeting. 'duration' => '0', // Default = 0 which means no set duration in minutes. [number] //'meta_category' => '', // Use to pass additional info to BBB server. See API docs. ); // Create the meeting and get back a response: $result = $bbb->createMeetingWithXmlResponseArray($creationParams); // If it's all good, then we've interfaced with our BBB php api OK: if ($result == null) { // If we get a null response, then we're not getting any XML back from BBB. echo "<div class='alert-danger'>$langBBBConnectionError</div>"; exit; } else { if ($result['returncode'] == 'SUCCESS') { // Then do stuff ... //echo "<p>Meeting succesfullly created.</p>"; } else { echo "<div class='alert alert-danger'>$langBBBCreationRoomError.</div>"; exit; } } } }
chkValidator.addValidation("max_rooms_form","req","' . $langΒΒΒServerAlertMaxRooms . '"); chkValidator.addValidation("max_rooms_form","numeric","' . $langΒΒΒServerAlertMaxRooms . '"); chkValidator.addValidation("max_users_form","req","' . $langΒΒΒServerAlertMaxUsers . '"); chkValidator.addValidation("max_users_form","numeric","' . $langΒΒΒServerAlertMaxUsers . '"); chkValidator.addValidation("weight","req","' . $langΒΒΒServerAlertOrder . '"); chkValidator.addValidation("weight","numeric","' . $langΒΒΒServerAlertOrder . '"); //]]></script>'; } else { //display available BBB servers $tool_content .= action_bar(array(array('title' => $langAddBBBServer, 'url' => "bbbmoduleconf.php?add_server", 'icon' => 'fa-plus-circle', 'level' => 'primary-label', 'button-class' => 'btn-success'))); $q = Database::get()->queryArray("SELECT * FROM bbb_servers"); $tool_content .= "<div class='table-responsive'>"; $tool_content .= "<table class='table-default'>\r\n <thead>\r\n <tr><th class = 'text-center'>{$langHost}</th>\r\n <th class = 'text-center'>IP</th>\r\n <th class = 'text-center'>{$langBBBEnabled}</th>\r\n <th class = 'text-center'>{$langBBBConnectedUsers}</th>\r\n <th class = 'text-center'>{$langBBBServerOrderP}</th>\r\n <th class = 'text-center'>" . icon('fa-gears') . "</th></tr>\r\n </thead>"; foreach ($q as $srv) { $enabled_bbb_server = $srv->enabled ? $langYes : $langNo; $connected_users = get_connected_users($srv->server_key, $srv->api_url, $srv->ip) . '/' . $srv->max_rooms; $tool_content .= "<tr>"; $tool_content .= "<td>{$srv->hostname}</td>"; $tool_content .= "<td>{$srv->ip}</td>"; $tool_content .= "<td>{$enabled_bbb_server}</td>"; $tool_content .= "<td>{$connected_users}</td>"; $tool_content .= "<td>{$srv->weight}</td>"; $tool_content .= "<td class='option-btn-cell'>" . action_button(array(array('title' => $langEdit, 'url' => "{$_SERVER['SCRIPT_NAME']}?edit_server={$srv->id}", 'icon' => 'fa-edit'), array('title' => $langDelete, 'url' => "{$_SERVER['SCRIPT_NAME']}?delete_server={$srv->id}", 'icon' => 'fa-times', 'class' => 'delete', 'confirm' => $langConfirmDelete))) . "</td>"; $tool_content .= "</tr>"; } $tool_content .= "</table></div>"; } } } } draw($tool_content, 3, null, $head_content);
/** * * @global type $course_id * @global type $langBBBCreationRoomError * @global type $langBBBConnectionError * @param type $title * @param type $meeting_id * @param type $mod_pw * @param type $att_pw * @param type $record */ function create_meeting($title, $meeting_id, $mod_pw, $att_pw, $record) { global $course_id, $langBBBCreationRoomError, $langBBBConnectionError; $run_to = -1; $min_users = 10000000; //Get all course participants $users_to_join = Database::get()->querySingle("SELECT COUNT(*) AS count FROM course_user, user\n WHERE course_user.course_id = ?d AND course_user.user_id = user.id", $course_id)->count; //Algorithm to select BBB server GOES HERE ... $query = Database::get()->queryArray("SELECT * FROM bbb_servers WHERE enabled='true' AND enable_recordings=?s ORDER BY weight ASC", $record); if ($query) { foreach ($query as $row) { $max_rooms = $row->max_rooms; $max_users = $row->max_users; // GET connected Participants $connected_users = get_connected_users($row->server_key, $row->api_url, $row->ip); $active_rooms = get_active_rooms($row->server_key, $row->api_url); if ($connected_users < $min_users) { $run_to = $row->id; $min_users = $connected_users; } //cases // max_users = 0 && max_rooms = 0 - UNLIMITED // active_rooms < max_rooms && active_users < max_users // active_rooms < max_rooms && max_users = 0 (UNLIMITED) // active_users < max_users && max_rooms = 0 (UNLIMITED) if ($max_rooms == 0 && $max_users == 0 || $max_users > $users_to_join + $connected_users && $active_rooms < $max_rooms || $active_rooms < $max_rooms && $max_users == 0 || $max_users > $users_to_join + $connected_users && $max_rooms == 0) { $run_to = $row->id; Database::get()->querySingle("UPDATE bbb_session SET running_at=?s WHERE meeting_id=?s", $row->id, $meeting_id); break; } } } if ($run_to == -1) { //WE SHOULD TAKE ACTION IF NO SERVER AVAILABLE DUE TO CAPACITY PROBLEMS // If no server available we select server with min connected users $temp_conn = 10000000; $query = Database::get()->queryArray("SELECT * FROM bbb_servers WHERE enabled='true' AND enable_recordings=?s ORDER BY weight ASC", $record); if ($query) { foreach ($query as $row) { // GET connected Participants $connected_users = get_connected_users($row->server_key, $row->api_url, $row->ip); if ($connected_users < $temp_conn) { $run_to = $row->id; $temp_conn = $connected_users; } } } Database::get()->querySingle("UPDATE bbb_session SET running_at=?d WHERE meeting_id=?s", $run_to, $meeting_id); } //we find the bbb server that will serv the session $res = Database::get()->querySingle("SELECT * FROM bbb_servers WHERE id=?d", $run_to); if ($res) { $salt = $res->server_key; $bbb_url = $res->api_url; $bbb = new BigBlueButton($salt, $bbb_url); $creationParams = array('meetingId' => $meeting_id, 'meetingName' => $title, 'attendeePw' => $att_pw, 'moderatorPw' => $mod_pw, 'welcomeMsg' => '', 'dialNumber' => '', 'voiceBridge' => '', 'webVoice' => '', 'logoutUrl' => '', 'maxParticipants' => '-1', 'record' => $record, 'duration' => '0'); // Create the meeting and get back a response: $result = $bbb->createMeetingWithXmlResponseArray($creationParams); // If it's all good, then we've interfaced with our BBB php api OK: if ($result == null) { // If we get a null response, then we're not getting any XML back from BBB. echo "<div class='alert-danger'>{$langBBBConnectionError}</div>"; exit; } else { if ($result['returncode'] == 'SUCCESS') { // Then do stuff ... //echo "<p>Meeting succesfullly created.</p>"; } else { echo "<div class='alert alert-danger'>{$langBBBCreationRoomError}.</div>"; exit; } } } }