Browse Source

Adding DO support see #8183

Julio Montoya 10 years ago
parent
commit
c54ff61a95

+ 5 - 2
plugin/bbb/config.vm.dist.php

@@ -23,13 +23,16 @@ return array(
         array(
             'enabled' => true,
             'name' => 'DigitalOcean',
-            //'host' => 'server-address',
-            //'user'=> 'AjZjoXMEg0vm7P8QXEWOC',
             'vm_client_id' => 'client_id',
             'api_key' => '123456',
             'vm_id' => '123456', // The VM ID we want to access
             'vm_min_size_id' => '66', // VM size ID example for 512mb use 66
             'vm_max_size_id' => '65' // For 1GB use 63
+        ),
+        // The Amazon hook is not implemented yet
+        array(
+            'enabled' => false,
+            'name' => 'Amazon'
         )
     )
 );

+ 1 - 1
plugin/bbb/lang/english.php

@@ -52,4 +52,4 @@ $strings['plugin_tool_bbb'] = 'Video';
 
 $strings['ThereAreNotRecordingsForTheMeetings'] = 'There are not recording for the meeting sessions';
 $strings['NoRecording'] = 'No recording';
-
+$strings['ClickToContinue'] = 'Click to continue';

+ 1 - 0
plugin/bbb/lang/french.php

@@ -46,3 +46,4 @@ $strings['plugin_tool_bbb'] = 'Vidéo';
 $strings['ThereAreNotRecordingsForTheMeetings'] = 'Aucun enregistrement disponible';
 $strings['NoRecording'] = "Pas d'enregistrement";
 
+$strings['ClickToContinue'] = 'Cliquez pour continuer';

+ 1 - 0
plugin/bbb/lang/spanish.php

@@ -46,3 +46,4 @@ $strings['plugin_tool_bbb'] = 'Video';
 $strings['ThereAreNotRecordingsForTheMeetings'] = 'No hay grabaciones de sesiones de videoconferencia';
 $strings['NoRecording'] = 'No hay grabación';
 
+$strings['ClickToContinue'] = 'Hacer click para continuar';

+ 1 - 0
plugin/bbb/lib/VM.php

@@ -1,4 +1,5 @@
 <?php
+/* For licensing terms, see /license.txt */
 
 /**
  * Class VM

+ 134 - 27
plugin/bbb/lib/bbb.lib.php

@@ -1,4 +1,6 @@
 <?php
+/* For licensing terms, see /license.txt */
+
 /**
  * Class bbb
  * This script initiates a video conference session, calling the BigBlueButton
@@ -19,19 +21,29 @@ class bbb
     public $plugin_enabled = false;
 
     /**
+     *
      * Constructor (generates a connection to the API and the Chamilo settings
-     * required for the connection to the videoconference server)
+     * required for the connection to the video conference server)
+     * @param string $host
+     * @param string $salt
      */
-    public function __construct()
+    public function __construct($host = null, $salt = null)
     {
-        // initialize video server settings from global settings
+        // 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();
+        if (empty($host)) {
+            $bbb_host = $plugin->get('host');
+        } else {
+            $bbb_host = $host;
+        }
+        if (empty($salt)) {
+            $bbb_salt = $plugin->get('salt');
+        } else {
+            $bbb_salt = $salt;
+        }
 
         $this->logout_url = api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq();
         $this->table = Database::get_main_table('plugin_bbb_meeting');
@@ -65,7 +77,7 @@ class bbb
         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
@@ -123,8 +135,8 @@ class bbb
             $record             = isset($params['record']) && $params['record'] ? 'true' : 'false';
             $duration           = isset($params['duration']) ? intval($params['duration']) : 0;
             // This setting currently limits the maximum conference duration,
-            // to avoid llingering sessions on the videoconference server #6261
-            $duration           = 300;
+            // to avoid lingering sessions on the videoconference server #6261
+            $duration = 300;
 
             $bbb_params = array(
                 'meetingId' => $id, 					// REQUIRED
@@ -141,11 +153,29 @@ class bbb
                 '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);
+
+            $status = false;
+            $meeting = null;
+
+            while ($status == false) {
+                $result = $this->api->createMeetingWithXmlResponseArray(
+                    $bbb_params
+                );
+                if (isset($result) && strval(
+                        $result['returncode']
+                    ) == 'SUCCESS'
+                ) {
+                    if ($this->debug) {
+                        error_log(
+                            "create_meeting result: " . print_r($result, 1)
+                        );
+                    }
+                    $meeting = $this->join_meeting($meeting_name, true);
+
+                    return $meeting;
+                }
             }
             return $this->logout;
         }
@@ -154,7 +184,8 @@ class bbb
     /**
      * Tells whether the given meeting exists and is running
      * (using course code as name)
-     * @param string Meeting name (usually the course code)
+     * @param string $meeting_name Meeting name (usually the course code)
+     *
      * @return bool True if meeting exists, false otherwise
      * @assert ('') === false
      * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
@@ -191,30 +222,68 @@ class bbb
      * @assert ('') === false
      * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
      */
-    public function join_meeting($meeting_name)
+    public function join_meeting($meeting_name, $loop = false)
     {
-        if (empty($meeting_name)) { return false; }
+        if (empty($meeting_name)) {
+            return false;
+        }
+
         $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)) {
+
+        $meeting_data = Database::select(
+            '*',
+            $this->table,
+            array('where' => array('meeting_name = ? AND status = 1 ' => $meeting_name)),
+            'first'
+        );
+
+        if (empty($meeting_data) || !is_array($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;
+        $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
+        );
 
-        if ($this->debug) error_log("meeting is running: ".$meeting_is_running);
+        $status = false;
+        $meeting_info_exists = false;
+        while ($status == false) {
 
-        $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_is_running_info = $this->get_meeting_info($params);
 
-        $meeting_info_exists = $this->get_meeting_info($params);
+            error_log(print_r($meeting_is_running_info, 1));
 
-        if (isset($meeting_is_running) && $meeting_info_exists) {
+            if (strval($meeting_is_running_info['returncode']) == 'SUCCESS' &&
+                isset($meeting_is_running_info['meetingName']) &&
+                !empty($meeting_is_running_info['meetingName'])
+                //strval($meeting_is_running_info['running']) == 'true'
+            ) {
+                $meeting_info_exists = true;
+            }
+
+            if ($this->debug) {
+                error_log(
+                    "meeting is running: " . intval($meeting_info_exists)
+                );
+            }
+
+            if ($meeting_info_exists) {
+                $status = true;
+            }
+
+            if ($loop) {
+                continue;
+            } else {
+                break;
+            }
+        }
+
+        if ($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
@@ -495,6 +564,7 @@ class bbb
                 }
             }
         }
+
         return false;
     }
 
@@ -509,4 +579,41 @@ class bbb
         return true;
         //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
     }
+
+    /**
+     * Get active session in the all platform
+     */
+    public function getActiveSessionsCount()
+    {
+        $meetingList = Database::select(
+            'count(id) as count',
+            $this->table,
+            array('where' => array('status = ?' => array(1))),
+            'first'
+        );
+
+        return $meetingList['count'];
+    }
+
+    /**
+     * @param string $url
+     */
+    public function redirectToBBB($url)
+    {
+        if (file_exists(__DIR__ . '/../config.vm.php')) {
+            // Using VM
+            echo Display::url(get_lang('ClickToContinue'), $url);
+            exit;
+        } else {
+            // Classic
+            header("Location: $url");
+            exit;
+        }
+
+        // js
+        /*echo '<script>';
+        echo 'window.location = "'.$url.'"';
+        echo '</script>';
+        exit;*/
+    }
 }

+ 1 - 0
plugin/bbb/lib/vm/AbstractVM.php

@@ -1,4 +1,5 @@
 <?php
+/* For licensing terms, see /license.txt */
 
 /**
  * Class AbstractVM

+ 2 - 1
plugin/bbb/lib/vm/AmazonVM.php

@@ -1,10 +1,11 @@
 <?php
+/* For licensing terms, see /license.txt */
 
 use DigitalOcean\DigitalOcean;
 use DigitalOcean\Credentials;
 
 /**
- * Class DigitalOceanWrapper
+ * Class AmazonVM
  */
 class AmazonVM extends AbstractVM implements VirtualMachineInterface
 {

+ 2 - 1
plugin/bbb/lib/vm/DigitalOceanVM.php

@@ -1,10 +1,11 @@
 <?php
+/* For licensing terms, see /license.txt */
 
 use DigitalOcean\DigitalOcean;
 use DigitalOcean\Credentials;
 
 /**
- * Class DigitalOceanWrapper
+ * Class DigitalOceanVM
  */
 class DigitalOceanVM extends AbstractVM implements VirtualMachineInterface
 {

+ 1 - 0
plugin/bbb/lib/vm/VMInterface.php

@@ -1,4 +1,5 @@
 <?php
+/* For licensing terms, see /license.txt */
 
 /**
  * Interface VirtualMachineInterface

+ 5 - 9
plugin/bbb/start.php

@@ -54,27 +54,23 @@ if ($bbb->plugin_enabled) {
             if ($bbb->meeting_exists($meeting_params['meeting_name'])) {
                 $url = $bbb->join_meeting($meeting_params['meeting_name']);
                 if ($url) {
-                    header('location: '.$url);
-                    exit;
+                    $bbb->redirectToBBB($url);
                 } else {
                     $url = $bbb->create_meeting($meeting_params);
-                    header('location: '.$url);
-                    exit;
+                    $bbb->redirectToBBB($url);
                 }
             } else {
                 if ($bbb->is_teacher()) {
                     $url = $bbb->create_meeting($meeting_params);
-                    header('location: '.$url);
-                    exit;
+                    $bbb->redirectToBBB($url);
                 } else {
                     $url = 'listing.php?'.api_get_cidreq();
-                    header('location: '.$url);
-                    exit;
+                    $bbb->redirectToBBB($url);
                 }
             }
         } else {
             $url = 'listing.php?'.api_get_cidreq();
-            header('location: '.$url);
+            header('Location: ' . $url);
             exit;
         }
     } else {