Advertisement
Guest User

bbb-mobile-api

a guest
Mar 8th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.94 KB | None | 0 0
  1. <?php
  2. /*
  3. Copyright 2010 Blindside Networks
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. Versions:
  20.    1.0  --  Initial version written by DJP
  21.                    (email: djp [a t ]  architectes DOT .org)
  22.    1.1  --  Updated by Omar Shammas and Sebastian Schneider
  23.                     (email : omar DOT shammas [a t ] g m ail DOT com)
  24.                     (email : seb DOT sschneider [ a t ] g m ail DOT com)
  25.    1.2  --  Updated by Omar Shammas
  26.                     (email : omar DOT shammas [a t ] g m ail DOT com)
  27.    1.3  --  Updated by Jesus Federico
  28.                     (email : jesus [a t ] blind side n e t w o rks DOT com)
  29.  
  30. */
  31.  
  32. function bbb_wrap_simplexml_load_file($url){
  33.     $response = false;
  34.  
  35.     if (extension_loaded('curl')) {
  36.         $ch = curl_init() or die ( curl_error() );
  37.         $timeout = 10;
  38.         curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);  
  39.         curl_setopt( $ch, CURLOPT_URL, $url );
  40.         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  41.         curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  42.         $data = curl_exec( $ch );
  43.         curl_close( $ch );
  44.        
  45.         if($data)
  46.             $response = new SimpleXMLElement($data);
  47.     } else {
  48.         $response = simplexml_load_file($url);
  49.     }
  50.  
  51.     return $response;
  52. }
  53.  
  54. class BigBlueButton {
  55.    
  56.     var $userName = array();
  57.     var $meetingID; // the meeting id
  58.    
  59.     var $welcomeString;
  60.     // the next 2 fields are maybe not needed?!?
  61.     var $modPW; // the moderator password
  62.     var $attPW; // the attendee pw
  63.    
  64.     var $securitySalt; // the security salt; gets encrypted with sha1
  65.     var $URL; // the url the bigbluebutton server is installed
  66.     var $sessionURL; // the url for the administrator to join the sessoin
  67.     var $userURL;
  68.    
  69.     var $conferenceIsRunning = false;
  70.    
  71.     // this constructor is used to create a BigBlueButton Object
  72.     // use this object to create servers
  73.     // Use is either 0 arguments or all 7 arguments
  74.     public function __construct() {
  75.         $numargs = func_num_args();
  76.  
  77.         if( $numargs == 0 ) {
  78.         }
  79.         // pass the information to the class variables
  80.         else if( $numargs >= 6 ) {
  81.             $this->userName = func_get_arg(0);
  82.             $this->meetingID = func_get_arg(1);
  83.             $this->welcomeString = func_get_arg(2);
  84.             $this->modPW = func_get_arg(3);
  85.             $this->attPW = func_get_arg(4);
  86.             $this->securitySalt = func_get_arg(5);
  87.             $this->URL = func_get_arg(6);
  88.            
  89.  
  90.             $arg_list = func_get_args();
  91.         }// end else if
  92.     }
  93.    
  94.     //------------------------------------------------GET URLs-------------------------------------------------
  95.     /**
  96.     *This method returns the url to join the specified meeting.
  97.     *
  98.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  99.     *@param username -- the display name to be used when the user joins the meeting
  100.     *@param PW -- the attendee or moderator password of the meeting
  101.     *@param SALT -- the security salt of the bigbluebutton server
  102.     *@param URL -- the url of the bigbluebutton server
  103.     *
  104.     *@return The url to join the meeting
  105.     */
  106.     private function isMobile() {
  107.         $useragent=$_SERVER['HTTP_USER_AGENT'];
  108.  
  109.         if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4)))
  110.         {
  111.             return true;
  112.         }else {
  113.             return false;
  114.         }
  115.     }
  116.  
  117.     public function getJoinURL( $meetingID, $userName, $PW, $SALT, $URL ) {
  118.         if (self::isMobile()) {
  119.             $URL = str_replace("http:", "bigbluebutton:", $URL);
  120.         }
  121.         $url_join = $URL."api/join?";
  122.         $params = 'meetingID='.urlencode($meetingID).'&fullName='.urlencode($userName).'&password='.urlencode($PW);
  123.         return ($url_join.$params.'&checksum='.sha1("join".$params.$SALT) );
  124.     }
  125.    
  126.     /**
  127.     *This method returns the url to join the specified meeting.
  128.     *
  129.     *@param name -- a name fot the meeting
  130.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  131.     *@param attendeePW -- the attendee of the meeting
  132.     *@param moderatorPW -- the moderator of the meeting
  133.     *@param welcome -- the welcome message that gets displayed on the chat window
  134.     *@param logoutURL -- the URL that the bbb client will go to after users logouut
  135.     *@param SALT -- the security salt of the bigbluebutton server
  136.     *@param URL -- the url of the bigbluebutton server
  137.     *
  138.     *@return The url to join the meeting
  139.     */
  140.     public function getCreateMeetingURL($name, $meetingID, $attendeePW, $moderatorPW, $welcome, $logoutURL, $SALT, $URL, $record = 'false', $duration=0, $voiceBridge=0, $metadata = array() ) {
  141.         $url_create = $URL."api/create?";
  142.         if ( $voiceBridge == 0)
  143.             $voiceBridge = 70000 + rand(0, 9999);
  144.    
  145.         $meta = '';
  146.         foreach ($metadata as $key => $value) {
  147.             $meta = $meta.'&'.$key.'='.urlencode($value);
  148.         }
  149.    
  150.         $params = 'name='.urlencode($name).'&meetingID='.urlencode($meetingID).'&attendeePW='.urlencode($attendeePW).'&moderatorPW='.urlencode($moderatorPW).'&voiceBridge='.$voiceBridge.'&logoutURL='.urlencode($logoutURL).'&record='.$record.$meta;
  151.    
  152.         $duration = intval($duration);
  153.         if( $duration > 0 )
  154.             $params .= '&duration='.$duration;
  155.    
  156.         if( trim( $welcome ) )
  157.             $params .= '&welcome='.urlencode($welcome);
  158.    
  159.         return ( $url_create.$params.'&checksum='.sha1("create".$params.$SALT) );
  160.     }
  161.  
  162.     public function getCreateMeetingURL_mobile($name, $meetingID, $attendeePW, $moderatorPW, $welcome, $logoutURL, $SALT, $URL, $record = 'false', $duration=0, $voiceBridge=0, $metadata = array() ) {
  163.         $URL = str_replace("http", "bigbluebutton", $URL);
  164.         $url_create = $URL."api/create?";
  165.         if ( $voiceBridge == 0)
  166.             $voiceBridge = 70000 + rand(0, 9999);
  167.    
  168.         $meta = '';
  169.         foreach ($metadata as $key => $value) {
  170.             $meta = $meta.'&'.$key.'='.urlencode($value);
  171.         }
  172.    
  173.         $params = 'name='.urlencode($name).'&meetingID='.urlencode($meetingID).'&attendeePW='.urlencode($attendeePW).'&moderatorPW='.urlencode($moderatorPW).'&voiceBridge='.$voiceBridge.'&logoutURL='.urlencode($logoutURL).'&record='.$record.$meta;
  174.    
  175.         $duration = intval($duration);
  176.         if( $duration > 0 )
  177.             $params .= '&duration='.$duration;
  178.    
  179.         if( trim( $welcome ) )
  180.             $params .= '&welcome='.urlencode($welcome);
  181.    
  182.         return ( $url_create.$params.'&checksum='.sha1("create".$params.$SALT) );
  183.     }
  184.    
  185.    
  186.     /**
  187.     *This method returns the url to check if the specified meeting is running.
  188.     *
  189.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  190.     *@param SALT -- the security salt of the bigbluebutton server
  191.     *@param URL -- the url of the bigbluebutton server
  192.     *
  193.     *@return The url to check if the specified meeting is running.
  194.     */
  195.     public function getIsMeetingRunningURL( $meetingID, $URL, $SALT ) {
  196.         $base_url = $URL."api/isMeetingRunning?";
  197.         $params = 'meetingID='.urlencode($meetingID);
  198.         return ($base_url.$params.'&checksum='.sha1("isMeetingRunning".$params.$SALT) );   
  199.     }
  200.  
  201.     /**
  202.     *This method returns the url to getMeetingInfo of the specified meeting.
  203.     *
  204.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  205.     *@param modPW -- the moderator password of the meeting
  206.     *@param SALT -- the security salt of the bigbluebutton server
  207.     *@param URL -- the url of the bigbluebutton server
  208.     *
  209.     *@return The url to check if the specified meeting is running.
  210.     */
  211.     public function getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) {
  212.         $base_url = $URL."api/getMeetingInfo?";
  213.         $params = 'meetingID='.urlencode($meetingID).'&password='.urlencode($modPW);
  214.         return ( $base_url.$params.'&checksum='.sha1("getMeetingInfo".$params.$SALT)); 
  215.     }
  216.    
  217.     /**
  218.     *This method returns the url for listing all meetings in the bigbluebutton server.
  219.     *
  220.     *@param SALT -- the security salt of the bigbluebutton server
  221.     *@param URL -- the url of the bigbluebutton server
  222.     *
  223.     *@return The url of getMeetings.
  224.     */
  225.     public function getMeetingsURL($URL, $SALT) {
  226.         $base_url = $URL."api/getMeetings?";
  227.         $params = 'random='.(rand() * 1000 );
  228.         return ( $base_url.$params.'&checksum='.sha1("getMeetings".$params.$SALT));
  229.     }
  230.  
  231.     /**
  232.     *This method returns the url to end the specified meeting.
  233.     *
  234.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  235.     *@param modPW -- the moderator password of the meeting
  236.     *@param SALT -- the security salt of the bigbluebutton server
  237.     *@param URL -- the url of the bigbluebutton server
  238.     *
  239.     *@return The url to end the specified meeting.
  240.     */
  241.     public function getEndMeetingURL( $meetingID, $modPW, $URL, $SALT ) {
  242.         $base_url = $URL."api/end?";
  243.         $params = 'meetingID='.urlencode($meetingID).'&password='.urlencode($modPW);
  244.         return ( $base_url.$params.'&checksum='.sha1("end".$params.$SALT) );
  245.     }  
  246.  
  247.    
  248.     public function getRecordingsURL($meetingID, $URL, $SALT ) {
  249.         $base_url_record = $URL."api/getRecordings?";
  250.         $params = "meetingID=".urlencode($meetingID);
  251.    
  252.         return ($base_url_record.$params."&checksum=".sha1("getRecordings".$params.$SALT) );
  253.     }
  254.    
  255.     public function getDeleteRecordingsURL( $recordID, $URL, $SALT ) {
  256.         $url_delete = $URL."api/deleteRecordings?";
  257.         $params = 'recordID='.urlencode($recordID);
  258.         return ($url_delete.$params.'&checksum='.sha1("deleteRecordings".$params.$SALT) );
  259.     }
  260.    
  261.     public function getPublishRecordingsURL( $recordID, $set, $URL, $SALT ) {
  262.         $url_delete = $URL."api/publishRecordings?";
  263.         $params = 'recordID='.$recordID."&publish=".$set;
  264.         return ($url_delete.$params.'&checksum='.sha1("publishRecordings".$params.$SALT) );
  265.     }
  266.    
  267.     //-----------------------------------------------CREATE----------------------------------------------------
  268.     /**
  269.     *This method creates a meeting and returnS the join url for moderators.
  270.     *
  271.     *@param username
  272.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  273.     *@param welcomeString -- the welcome message to be displayed when a user logs in to the meeting
  274.     *@param mPW -- the moderator password of the meeting
  275.     *@param aPW -- the attendee password of the meeting
  276.     *@param SALT -- the security salt of the bigbluebutton server
  277.     *@param URL -- the url of the bigbluebutton server
  278.     *@param logoutURL -- the url the user should be redirected to when they logout of bigbluebutton
  279.     *
  280.     *@return The getJoinURL if successful or an error message if unsuccessful
  281.     */
  282.     public function createMeetingAndGetJoinURL( $username, $meetingID, $meetingName, $welcomeString, $mPW, $aPW, $SALT, $URL, $logoutURL, $record='false', $duration=0, $voiceBridge=0, $metadata = array() ) {
  283.  
  284.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getCreateMeetingURL($meetingName, $meetingID, $aPW, $mPW, $welcomeString, $logoutURL, $SALT, $URL, $record, $duration, $voiceBridge, $metadata ) );
  285.        
  286.         if( $xml && $xml->returncode == 'SUCCESS' ) {
  287.             return ( BigBlueButton::getJoinURL( $meetingID, $username, $mPW, $SALT, $URL ) );
  288.         }  
  289.         else if( $xml ) {
  290.             return ( (string)$xml->messageKey.' : '.(string)$xml->message );
  291.         }
  292.         else {
  293.             return ('Unable to fetch URL '.$url_create.$params.'&checksum='.sha1("create".$params.$SALT) );
  294.         }
  295.     }
  296.  
  297.     /**
  298.     *This method creates a meeting and return an array of the xml packet
  299.     *
  300.     *@param username
  301.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  302.     *@param welcomeString -- the welcome message to be displayed when a user logs in to the meeting
  303.     *@param mPW -- the moderator password of the meeting
  304.     *@param aPW -- the attendee password of the meeting
  305.     *@param SALT -- the security salt of the bigbluebutton server
  306.     *@param URL -- the url of the bigbluebutton server
  307.     *@param logoutURL -- the url the user should be redirected to when they logout of bigbluebutton
  308.     *
  309.     *@return
  310.     *   - Null if unable to reach the bigbluebutton server
  311.     *   - If failed it returns an array containing a returncode, messageKey, message.
  312.     *   - If success it returns an array containing a returncode, messageKey, message, meetingID, attendeePW, moderatorPW, hasBeenForciblyEnded.
  313.     */
  314.     public function createMeetingArray( $username, $meetingID, $meetingName, $welcomeString, $mPW, $aPW, $SALT, $URL, $logoutURL, $record='false', $duration=0, $voiceBridge=0, $metadata = array() ) {
  315.    
  316.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getCreateMeetingURL($meetingName, $meetingID, $aPW, $mPW, $welcomeString, $logoutURL, $SALT, $URL, $record, $duration, $voiceBridge, $metadata ) );
  317.        
  318.         if( $xml ) {
  319.             if($xml->meetingID)
  320.                 return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey, 'meetingID' => (string)$xml->meetingID, 'attendeePW' => (string)$xml->attendeePW, 'moderatorPW' => (string)$xml->moderatorPW, 'hasBeenForciblyEnded' => (string)$xml->hasBeenForciblyEnded );
  321.             else
  322.                 return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey );
  323.         }
  324.         else {
  325.             return null;
  326.         }
  327.     }
  328.    
  329.     //-------------------------------------------getMeetingInfo---------------------------------------------------
  330.     /**
  331.     *This method calls the getMeetingInfo on the bigbluebutton server and returns an xml packet.
  332.     *
  333.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  334.     *@param modPW -- the moderator password of the meeting
  335.     *@param SALT -- the security salt of the bigbluebutton server
  336.     *@param URL -- the url of the bigbluebutton server
  337.     *
  338.     *@return An xml packet.
  339.     *   If failed it returns an xml packet containing a returncode, messagekey, and message.
  340.     *   If success it returnsan xml packet containing a returncode,
  341.     */
  342.     public function getMeetingInfo( $meetingID, $modPW, $URL, $SALT ) {
  343.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) );
  344.         if($xml){
  345.             return ( str_replace('</response>', '', str_replace("<?xml version=\"1.0\"?>\n<response>", '', $xml->asXML())));
  346.         }
  347.         return false;
  348.     }
  349.  
  350.     /**
  351.     *This method calls the getMeetingInfo on the bigbluebutton server and returns an array.
  352.     *
  353.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  354.     *@param modPW -- the moderator password of the meeting
  355.     *@param SALT -- the security salt of the bigbluebutton server
  356.     *@param URL -- the url of the bigbluebutton server
  357.     *
  358.     *@return An Array.
  359.     *   - Null if unable to reach the bigbluebutton server
  360.     *   - If failed it returns an array containing a returncode, messagekey, message.
  361.     *   - If success it returns an array containing a meetingID, moderatorPW, attendeePW, hasBeenForciblyEnded, running, startTime, endTime,  
  362.           participantCount, moderatorCount, attendees.
  363.     */
  364.     public function getMeetingInfoArray( $meetingID, $modPW, $URL, $SALT ) {
  365.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) );
  366.                
  367.         if($xml && $xml->returncode == 'SUCCESS'){ //If there were meetings already created
  368.             return array( 'returncode' => (string)$xml->returncode, 'meetingID' => (string)$xml->meetingID, 'moderatorPW' => (string)$xml->moderatorPW, 'attendeePW' => (string)$xml->attendeePW, 'hasBeenForciblyEnded' => (string)$xml->hasBeenForciblyEnded, 'running' => (string)$xml->running, 'startTime' => (string)$xml->startTime, 'endTime' => (string)$xml->endTime, 'participantCount' => (string)$xml->participantCount, 'moderatorCount' => (string)$xml->moderatorCount, 'attendees' => (string)$xml->attendees );
  369.         }
  370.         else if( ($xml && $xml->returncode == 'FAILED') || $xml) { //If the xml packet returned failure it displays the message to the user
  371.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey);
  372.         }
  373.         else { //If the server is unreachable, then prompts the user of the necessary action
  374.             return null;
  375.         }
  376.  
  377.     }
  378.    
  379.     //-----------------------------------------------getMeetings------------------------------------------------------
  380.     /**
  381.     *This method calls getMeetings on the bigbluebutton server, then calls getMeetingInfo for each meeting and concatenates the result.
  382.     *
  383.     *@param URL -- the url of the bigbluebutton server
  384.     *@param SALT -- the security salt of the bigbluebutton server
  385.     *
  386.     *@return
  387.     *   - If failed then returns a boolean of false.
  388.     *   - If succeeded then returns an xml of all the meetings.
  389.     */
  390.     public function getMeetings( $URL, $SALT ) {
  391.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getMeetingsURL( $URL, $SALT ) );
  392.         if( $xml && $xml->returncode == 'SUCCESS' ) {
  393.             if( (string)$xml->messageKey )
  394.                 return ( $xml->message->asXML() ); 
  395.             ob_start();
  396.             echo '<meetings>';
  397.             if( count( $xml->meetings ) && count( $xml->meetings->meeting ) ) {
  398.                 foreach ($xml->meetings->meeting as $meeting)
  399.                 {
  400.                     echo '<meeting>';
  401.                     echo BigBlueButton::getMeetingInfo($meeting->meetingID, $meeting->moderatorPW, $URL, $SALT);
  402.                     echo '</meeting>';
  403.                 }
  404.             }
  405.             echo '</meetings>';
  406.             return (ob_get_clean());
  407.         }
  408.         else {
  409.             return (false);
  410.         }
  411.     }
  412.  
  413.     /**
  414.     *This method calls getMeetings on the bigbluebutton server, then calls getMeetingInfo for each meeting and concatenates the result.
  415.     *
  416.     *@param URL -- the url of the bigbluebutton server
  417.     *@param SALT -- the security salt of the bigbluebutton server
  418.     *
  419.     *@return
  420.     *   - Null if the server is unreachable
  421.     *   - If FAILED then returns an array containing a returncode, messageKey, message.
  422.     *   - If SUCCESS then returns an array of all the meetings. Each element in the array is an array containing a meetingID,
  423.           moderatorPW, attendeePW, hasBeenForciblyEnded, running.
  424.     */
  425.     public function getMeetingsArray( $URL, $SALT ) {
  426.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getMeetingsURL( $URL, $SALT ) );
  427.  
  428.         if( $xml && $xml->returncode == 'SUCCESS' && $xml->messageKey ) {//The meetings were returned
  429.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey);
  430.         }
  431.         else if($xml && $xml->returncode == 'SUCCESS'){ //If there were meetings already created
  432.        
  433.             foreach ($xml->meetings->meeting as $meeting) {
  434.                 $meetings[] = array( 'meetingID' => $meeting->meetingID, 'moderatorPW' => $meeting->moderatorPW, 'attendeePW' => $meeting->attendeePW, 'hasBeenForciblyEnded' => $meeting->hasBeenForciblyEnded, 'running' => $meeting->running );
  435.             }
  436.  
  437.             return $meetings;
  438.  
  439.         }
  440.         else if( $xml ) { //If the xml packet returned failure it displays the message to the user
  441.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey);
  442.         }
  443.         else { //If the server is unreachable, then prompts the user of the necessary action
  444.             return null;
  445.         }
  446.     }
  447.    
  448.     public function getRecordingsArray($meetingID, $URL, $SALT ) {
  449.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getRecordingsURL( $meetingID, $URL, $SALT ) );
  450.         if( $xml && $xml->returncode == 'SUCCESS' && $xml->messageKey ) {//The meetings were returned
  451.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey);
  452.         } else if($xml && $xml->returncode == 'SUCCESS'){ //If there were meetings already created
  453.             $recordings = array();
  454.  
  455.             foreach ($xml->recordings->recording as $recording) {
  456.                 $playbackArray = array();
  457.                 foreach ( $recording->playback->format as $format ){
  458.                     $playbackArray[(string) $format->type] = array( 'type' => (string) $format->type, 'url' => (string) $format->url );
  459.                 }
  460.  
  461.                 //Add the metadata to the recordings array
  462.                $metadataArray = array();
  463.                 $metadata = get_object_vars($recording->metadata);
  464.                 foreach ($metadata as $key => $value) {
  465.                     if(is_object($value)) $value = '';
  466.                     $metadataArray['meta_'.$key] = $value;
  467.                 }
  468.    
  469.                 $recordings[] = array( 'recordID' => (string) $recording->recordID, 'meetingID' => (string) $recording->meetingID, 'meetingName' => (string) $recording->name, 'published' => (string) $recording->published, 'startTime' => (string) $recording->startTime, 'endTime' => (string) $recording->endTime, 'playbacks' => $playbackArray ) + $metadataArray;
  470.  
  471.             }
  472.    
  473.             usort($recordings, 'BigBlueButton::recordingBuildSorter');
  474.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey, 'recordings' => $recordings);
  475.    
  476.         } else if( $xml ) { //If the xml packet returned failure it displays the message to the user
  477.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey);
  478.         } else { //If the server is unreachable, then prompts the user of the necessary action
  479.             return NULL;
  480.         }
  481.     }
  482.  
  483.     private function recordingBuildSorter($a, $b){
  484.         if( $a['startTime'] < $b['startTime']) return -1;
  485.         else if( $a['startTime'] == $b['startTime']) return 0;
  486.         else return 1;
  487.     }
  488.    
  489.     //----------------------------------------------getUsers---------------------------------------
  490.     /**
  491.     *This method prints the usernames of the attendees in the specified conference.
  492.     *
  493.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  494.     *@param modPW -- the moderator password of the meeting
  495.     *@param URL -- the url of the bigbluebutton server
  496.     *@param SALT -- the security salt of the bigbluebutton server
  497.     *@param UNAME -- is a boolean to determine how the username is formatted when printed. Default if false.
  498.     *
  499.     *@return A boolean of true if the attendees were printed successfully and false otherwise.
  500.     */
  501.     public function getUsers( $meetingID, $modPW, $URL, $SALT, $UNAME = false ) {
  502.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) );
  503.         if( $xml && $xml->returncode == 'SUCCESS' ) {
  504.             ob_start();
  505.             if( count( $xml->attendees ) && count( $xml->attendees->attendee ) ) {
  506.                 foreach ( $xml->attendees->attendee as $attendee ) {
  507.                     if( $UNAME  == true ) {
  508.                         echo "User name: ".$attendee->fullName.'<br />';
  509.                     }
  510.                     else {
  511.                         echo $attendee->fullName.'<br />';
  512.                     }
  513.                 }
  514.             }
  515.             return (ob_end_flush());
  516.         }
  517.         else {
  518.             return (false);
  519.         }
  520.     }
  521.    
  522.     /**
  523.     *This method returns an array of the attendees in the specified meeting.
  524.     *
  525.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  526.     *@param modPW -- the moderator password of the meeting
  527.     *@param URL -- the url of the bigbluebutton server
  528.     *@param SALT -- the security salt of the bigbluebutton server
  529.     *
  530.     *@return
  531.     *   - Null if the server is unreachable.
  532.     *   - If FAILED, returns an array containing a returncode, messageKey, message.
  533.     *   - If SUCCESS, returns an array of array containing the userID, fullName, role of each attendee
  534.     */
  535.     public function getUsersArray( $meetingID, $modPW, $URL, $SALT ) {
  536.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) );
  537.  
  538.         if( $xml && $xml->returncode == 'SUCCESS' && $xml->messageKey == null ) {//The meetings were returned
  539.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey);
  540.         }
  541.         else if($xml && $xml->returncode == 'SUCCESS'){ //If there were meetings already created
  542.             foreach ($xml->attendees->attendee as $attendee){
  543.                     $users[] = array(  'userID' => $attendee->userID, 'fullName' => $attendee->fullName, 'role' => $attendee->role );
  544.             }
  545.             return $users;
  546.         }
  547.         else if( $xml ) { //If the xml packet returned failure it displays the message to the user
  548.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey);
  549.         }
  550.         else { //If the server is unreachable, then prompts the user of the necessary action
  551.             return null;
  552.         }
  553.     }
  554.    
  555.        
  556.     //------------------------------------------------Other Methods------------------------------------
  557.     /**
  558.     *This method calls end meeting on the specified meeting in the bigbluebutton server.
  559.     *
  560.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  561.     *@param modPW -- the moderator password of the meeting
  562.     *@param SALT -- the security salt of the bigbluebutton server
  563.     *@param URL -- the url of the bigbluebutton server
  564.     *
  565.     *@return
  566.     *   - Null if the server is unreachable
  567.     *   - An array containing a returncode, messageKey, message.
  568.     */
  569.     public function endMeeting( $meetingID, $modPW, $URL, $SALT ) {
  570.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getEndMeetingURL( $meetingID, $modPW, $URL, $SALT ) );
  571.  
  572.         if( $xml ) { //If the xml packet returned failure it displays the message to the user
  573.             return array('returncode' => (string)$xml->returncode, 'message' => (string)$xml->message, 'messageKey' => (string)$xml->messageKey);
  574.         }
  575.         else { //If the server is unreachable, then prompts the user of the necessary action
  576.             return null;
  577.         }
  578.  
  579.     }
  580.  
  581.     public function doDeleteRecordings( $recordIDs, $URL, $SALT ) {
  582.    
  583.         $ids =  explode(",", $recordIDs);
  584.         foreach( $ids as $id){
  585.             $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getDeleteRecordingsURL($id, $URL, $SALT) );
  586.             if( $xml && $xml->returncode != 'SUCCESS' )
  587.                 return false;
  588.         }
  589.         return true;
  590.     }
  591.    
  592.     public function doPublishRecordings( $recordIDs, $set, $URL, $SALT ) {
  593.         $ids =  explode(",", $recordIDs);
  594.         foreach( $ids as $id){
  595.             $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getPublishRecordingsURL($id, $set, $URL, $SALT) );
  596.             if( $xml && $xml->returncode != 'SUCCESS' )
  597.                 return false;
  598.         }
  599.         return true;
  600.     }
  601.    
  602.     public function getServerVersion( $URL ){
  603.         $base_url_record = $URL."api";
  604.    
  605.         $xml = bbb_wrap_simplexml_load_file( $base_url_record );
  606.         if( $xml && $xml->returncode == 'SUCCESS' )
  607.             return $xml->version;
  608.         else
  609.             return NULL;
  610.    
  611.     }
  612.    
  613.    
  614.     /**
  615.     *This method check the BigBlueButton server to see if the meeting is running (i.e. there is someone in the meeting)
  616.     *
  617.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  618.     *@param SALT -- the security salt of the bigbluebutton server
  619.     *@param URL -- the url of the bigbluebutton server
  620.     *
  621.     *@return A boolean of true if the meeting is running and false if it is not running
  622.     */
  623.     public function isMeetingRunning( $meetingID, $URL, $SALT ) {
  624.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getIsMeetingRunningURL( $meetingID, $URL, $SALT ) );
  625.         if( $xml && $xml->returncode == 'SUCCESS' )
  626.             return ( ( (string)$xml->running == 'true' ) ? true : false);
  627.         else
  628.             return ( false );
  629.     }
  630.    
  631.     /**
  632.     *This method calls isMeetingRunning on the BigBlueButton server.
  633.     *
  634.     *@param meetingID -- the unique meeting identifier used to store the meeting in the bigbluebutton server
  635.     *@param SALT -- the security salt of the bigbluebutton server
  636.     *@param URL -- the url of the bigbluebutton server
  637.     *
  638.     *@return
  639.     *   - If SUCCESS it returns an xml packet
  640.     *   - If the FAILED or the server is unreachable returns a string of 'false'
  641.     */
  642.     public function getMeetingXML( $meetingID, $URL, $SALT ) {
  643.         $xml = bbb_wrap_simplexml_load_file( BigBlueButton::getIsMeetingRunningURL( $meetingID, $URL, $SALT ) );
  644.         if( $xml && $xml->returncode == 'SUCCESS')
  645.             return ( str_replace('</response>', '', str_replace("<?xml version=\"1.0\"?>\n<response>", '', $xml->asXML())));
  646.         else
  647.             return 'false';
  648.     }
  649.  
  650. }
  651. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement