Commit 50c9cdc9 by George Jiglau

Initial commit

parents
bbb-api-php
===========
A PHP interface for the BigBlueButton API
Usage
-----
For a list of accepted parameters see the
[BigBlueButton Wiki](https://code.google.com/p/bigbluebutton/wiki/API).
<?php
$bbb = new BigBlueButton(BASE_URL, SECRET_SALT);
// Create a meeting
$meeting = $bbb->create(array(
'name' => 'Test meeting',
'meetingID' => 'test'
));
// Get the join URL for a meeting
$joinURL = $bbb->getJoinURL(array(
'fullName' => 'Smith Johnson',
'meetingID' => 'test',
'password' => $meeting->attendeePW
));
// After the meeting is done, end it
$bbb->end(array(
'meetingID' => $meeting->meetingID,
'password' => $meeting->moderatorPW
));
<?php
class BigBlueButton {
private $_bbbServerBaseURL;
private $_securitySalt;
private $_requestTimeout;
function __construct($baseURL, $securitySalt, $timeout=10) {
$this->_bbbServerBaseURL = $baseURL;
$this->_securitySalt = $securitySalt;
$this->_requestTimeout = $timeout;
}
private function _getURL($method, $methodParams) {
/*
* Generate an URL for calling the method with the specified parameters
*/
$url = $this->_bbbServerBaseURL . 'api/' . $method;
// Sanitize parameters
array_walk($methodParams, function(&$item) {
$item = (string)$item;
});
$params = http_build_query($methodParams);
$checksum = sha1($method . $params . $this->_securitySalt);
if (empty($params)) {
return $url . '?checksum=' . $checksum;
}
return $url . '?' . $params . '&checksum=' . $checksum;
}
private function _makeRequest($url) {
/*
* Make a request to the provided URL and return the response body
*/
if (!extension_loaded('curl')) {
throw new Exception('The BigBlueButton API requires cURL');
}
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->_requestTimeout);
$data = curl_exec( $ch );
curl_close( $ch );
return $data;
}
private function _sXmlToObj($sxml) {
if (!$sxml->children()) {
return (string)$sxml;
}
$obj = new stdClass();
foreach($sxml->children() as $k => $v){
$obj->{$k} = $this->_sXmlToObj($v);
}
return $obj;
}
private function _callMethod($method, $methodParams) {
/*
* Call the specified method and return the response as an XML element
*/
$url = $this->_getURL($method, $methodParams);
$response = $this->_makeRequest($url);
if (!$response) {
return false;
}
$response = $this->_sXmlToObj(new SimpleXMLElement($response));
if (!isset($response->returncode)) {
return false;
}
return $response;
}
private function _checkParams($paramSpec, $params) {
// Check for missing required parameters
foreach ($paramSpec as $param => $req) {
if (!$req) {
continue;
}
if (!isset($params[$param]) || !$params[$param]) {
throw new Exception(sprintf('Parameter "%s" missing or empty',
$param));
}
}
// Check for extra parameters
foreach ($params as $param => $val) {
if (!isset($paramSpec[$param])) {
trigger_error(sprintf('Extra parameter "%s" in BBB API call',
$param), E_USER_NOTICE);
}
}
}
public function create($params) {
$paramSpec = array(
'name' => false, 'meetingID' => true, 'attendeePW' => false,
'moderatorPW' => false, 'welcome' => false, 'dialNumber' => false,
'voiceBridge' => false, 'webVoice' => false, 'logoutURL' => false,
'record' => false, 'duration' => false, 'meta' => false
);
$this->_checkParams($paramSpec, $params);
return $this->_callMethod('create', $params);
}
public function getJoinURL($params) {
$paramSpec = array(
'fullName' => true, 'meetingID' => true, 'password' => true,
'createTime' => false, 'userID' => false, 'webVoiceConf' => false,
'configToken' => false
);
$this->_checkParams($paramSpec, $params);
return $this->_getURL('join', $params);
}
public function end($params) {
$paramSpec = array(
'meetingID' => true,
'password' => true
);
$this->_checkParams($paramSpec, $params);
return $this->_callMethod('end', $params);
}
public function isMeetingRunning($params) {
$paramSpec = array(
'meetingID' => true
);
$this->_checkParams($paramSpec, $params);
return $this->_callMethod('isMeetingRunning', $params);
}
public function getMeetings() {
return $this->_callMethod('getMeetings', array());
}
public function getMeetingInfo($params) {
$paramSpec = array(
'meetingID' => true,
'password' => true
);
$this->_checkParams($paramSpec, $params);
return $this->_callMethod('getMeetingInfo', $params);
}
public function getRecordings($params) {
$paramSpec = array(
'meetingID' => false
);
$this->_checkParams($paramSpec, $params);
return $this->_callMethod('getRecordings', $params);
}
public function publishRecordings($params) {
$paramSpec = array(
'recordID' => true,
'publish' => true
);
$this->_checkParams($paramSpec, $params);
return $this->_callMethod('publishRecordings', $params);
}
public function deleteRecordings($params) {
$paramSpec = array(
'recordID' => true
);
$this->_checkParams($paramSpec, $params);
return $this->_callMethod('deleteRecordings', $params);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment