Comments (4)
Good feedback! Your right that it's still in it's early days. We want BigBlueButton to have the best possible API for PHP.
from bigbluebutton-api-php.
Thank you for your feedback @goldsky.
As @ffdixon said this API is still a baby and we want it to grow with a lot of good care.
Here you are talking about two things:
- Converting object to array for API responses.
- Store properties in array property instead of using object properties.
I agree the way you described is the fastest way to implement features. However, this API is developed with the following approaches in mind:
- The API would have a logic associated to it.
- Data should be passed to functions (class methods here) safely.
- The code need to be used easily by a junior developer, he can understand it. It also need to be used fast by a senior developer, he doesn't need to dig in the BBB API documentation or this API source code to check what array keys he should add.
- Code must easy to maintain, fully tested and fully covered.
Using arrays is the way most PHP developers are used to, but developers implementing BBB for their customers are coming from different backgrounds. We need to keep this as much understandable and easy to use as possible without forcing a developer to read the API documentation.
from bigbluebutton-api-php.
he doesn't need to dig in the BBB API documentation or this API source code to check what array keys he should add.
I think we have different opinion on this.
If the API has different wordings to the parameters, then it makes people reading the documentation twice, eg on create
:
- the BBB's parameter:
name
- this API:
setMeetingName
while I'm proposing
$param->set('use_the_same_bbb_parameter_here', $value);
which makes less confusion, not even to mention about the difference parameters of name
and meetingName
wordings.
I understand your opinion, though, but on this topic, I just want to target the Parameters
classes, which give a XML object response, which I don't think have any benefit for bringing entire XML's methods into the response while what user needs are only the key=>value
pairs output.
Or, for making this optional, how about adding some kind of fromArray($params)
and toArray()
methods?
Example on CreateMeetingParameters
namespace BigBlueButton\Parameters;
/**
* Class CreateMeetingParameters.
*/
class CreateMeetingParameters extends BaseParameters
{
/**
* @var array
*/
private $meetingId;
/**
* @var string
*/
private $meetingName;
/////////////////////////////
// ... other properties here
/////////////////////////////
/**
* @var string
*/
private $query = array();
/**
* @var array
*/
private $meta = array();
/**
* CreateMeetingParameters constructor.
*
* @param $meetingId
* @param $meetingName
*/
public function __construct($meetingId, $meetingName)
{
$this->meetingId = $meetingId;
$this->meetingName = $meetingName;
}
/////////////////////////////
// ... other methods here
/////////////////////////////
public function fromArray($params)
{
foreach ($params as $k => $v) {
$this->query[$k] = $v;
}
}
public function toArray()
{
return $this->query;
}
/**
* @param string $key
*
* @return mixed
*/
public function get($key)
{
return $this->query[$key];
}
/**
* @param string $key
* @param mixed $val
*
* @return CreateMeetingParameters
*/
public function set($key, $val = '')
{
$this->query[$key] = $val;
return $this;
}
/**
* @return string
*/
public function getMeta($key)
{
return $this->meta[$key];
}
/**
* @param string $key
* @param string $value
*
* @return CreateMeetingParameters
*/
public function setMeta($key, $value)
{
$key = preg_replace('/^meta_/', '', $key);
$this->meta[$key] = $value;
return $this;
}
}
Example on Meeting
namespace BigBlueButton\Core;
/**
* Class Meeting
* @package BigBlueButton\Core
*/
class Meeting
{
/**
* @var string
*/
private $meetingId;
/**
* @var string
*/
private $meetingName;
/////////////////////////////
// ... other properties here
/////////////////////////////
/**
* @var bool
*/
private $hasUserJoined;
/**
* @var $xml \SimpleXMLElement
*/
private $rawXML;
/**
* Meeting constructor.
* @param $xml \SimpleXMLElement
*/
public function __construct($xml)
{
// ... adding this
$this->rawXML = $xml;
$this->meetingId = $xml->meetingID->__toString();
$this->meetingName = $xml->meetingName->__toString();
$this->creationTime = doubleval($xml->createTime);
$this->creationDate = $xml->createDate->__toString();
$this->voiceBridge = intval($xml->voiceBridge);
$this->dialNumber = $xml->dialNumber->__toString();
$this->attendeePassword = $xml->attendeePW->__toString();
$this->moderatorPassword = $xml->moderatorPW->__toString();
$this->hasBeenForciblyEnded = $xml->hasBeenForciblyEnded->__toString() == 'true';
$this->isRunning = $xml->running->__toString() == 'true';
$this->participantCount = intval($xml->participantCount);
$this->listenerCount = intval($xml->listenerCount);
$this->voiceParticipantCount = intval($xml->voiceParticipantCount);
$this->videoCount = intval($xml->videoCount);
$this->duration = intval($xml->duration);
$this->hasUserJoined = $xml->hasUserJoined->__toString() == 'true';
}
/////////////////////////////
// ... other methods here
/////////////////////////////
public function toArray()
{
return json_decode(json_encode($this->rawXML), true);
}
}
from bigbluebutton-api-php.
FYI, I'm building a MODX CMS integration and recreating my own API heavily inspired by this API, but based on my purpose.
So for example to create a meeting,
- I only need to pass over the form's fields as an array
- to an Ajax processor
- which calls
createMeeting($params, array $meta = array(), $postFields = '')
method in the add-on's class file (which does the validation as well), - which then calls
createMeeting(array $params, array $meta = array(), $postFields = '')
API with all required parameters and metas in one shot. - which returns an array for the response
The createMeeting method is this short:
public function createMeeting($params, array $meta = array(), $postFields = '')
{
if (!isset($params['meetingID']) || empty($params['meetingID'])) {
$params['meetingID'] = uniqid();
}
if (!isset($params['name']) || empty($params['name'])) {
$params['name'] = 'BBBx-' . $params['meetingID'];
}
$meta = array_merge($meta, array(
'origin' => 'MODX',
'origin-url' => MODX_SITE_URL,
'origin-name' => $this->modx->getOption('site_name'),
'origin-extra' => 'bbbx',
'origin-extra-version' => $this->config['version'],
'origin-extra-author' => 'goldsky <[email protected]>',
));
$response = $this->server->createMeeting($params, $meta, $postFields);
if (empty($response) || (isset($response['returncode']) && $response['returncode'] == 'FAILED')) {
$err = 'Unable to connect to server: ' . $response['message'];
$this->setError($err);
$this->modx->log(modX::LOG_LEVEL_ERROR, $err, '', __METHOD__, __FILE__, __LINE__);
return;
}
return $response;
}
which previously was this long
public function createMeeting($options, $xml = '')
{
if (!isset($options['meetingID']) || empty($options['meetingID'])) {
$meetingID = uniqid();
} else {
$meetingID = $options['meetingID'];
}
unset($options['meetingID']);
if (!isset($options['name']) || empty($options['name'])) {
$meetingName = 'BBBx-' . $meetingID;
} else {
$meetingName = $options['meetingName'];
}
unset($options['meetingName']);
$params = new \BigBlueButton\Parameters\CreateMeetingParameters($meetingID, $meetingName);
foreach ($options as $k => $v) {
if (is_string($v)) {
$v = trim($v);
}
if (empty($v)) {
continue;
}
switch ($k) {
case 'attendeePW':
$params->setAttendeePassword($v);
break;
case 'moderatorPW':
$params->setModeratorPassword($v);
break;
case 'welcome':
$params->setWelcomeMessage($v);
break;
case 'dialNumber':
$params->setDialNumber($v);
break;
case 'voiceBridge':
$params->setVoiceBridge($v);
break;
case 'webVoice':
$params->setWebVoice($v);
break;
case 'maxParticipants':
$params->setMaxParticipants((int) $v);
break;
case 'logoutURL':
$params->setLogoutUrl($v);
break;
case 'record':
$params->setRecord((boolean) $v);
break;
case 'duration':
$params->setDuration((int) $v);
break;
case 'meta':
$meta = array_map('trim', explode(',', $v));
foreach ($meta as $val) {
list($x, $y) = explode('=', $val);
$params->setMeta($x, $y);
}
break;
case 'moderatorOnlyMessage':
$params->setModeratorOnlyMessage($v);
break;
case 'autoStartRecording':
$params->setAutoStartRecording((boolean) $v);
break;
case 'allowStartStopRecording':
$params->setAllowStartStopRecording((boolean) $v);
break;
default:
break;
}
}
$params->setMeta('origin', 'MODX');
$params->setMeta('origin-url', MODX_SITE_URL);
$params->setMeta('origin-name', $this->modx->getOption('site_name'));
$params->setMeta('origin-extra', 'bbbx');
$params->setMeta('origin-extra-version', $this->config['version']);
$params->setMeta('origin-extra-author', 'goldsky <[email protected]>');
$response = $this->bbb->createMeeting($params, $xml);
$result = $response->getRawXml();
if (empty($result) || !isset($result->returncode) || $result->returncode == 'FAILED') {
$err = 'Creating meeting was failed.';
$this->setError($err);
$this->modx->log(modX::LOG_LEVEL_ERROR, $err);
return;
}
$meeting = json_decode(json_encode($result), true);
unset($meeting['returncode']);
return $meeting;
}
The switch-case is really a tedious job.
from bigbluebutton-api-php.
Related Issues (20)
- [3.0/2.2][DEPRECATION] use lockSettingsDisableNotes instead of lockSettingsDisableNote' HOT 8
- GetApiVersion Always return 2.2 version HOT 3
- Add "preUploadedPresentation" and "preUploadedPresentationName" to create
- Add "redirectErrorUrl" to Create API
- Add an enum for the available "userdata"
- Transform code to php81
- Upgrate to phpunit version 10
- Replace Enum dependency by native php enums
- Create new documentation with mdbook
- Find and create a provider to host mdbook
- Create automation [GitHub/new commits for docs] to [mdBook provider]
- Introduce CaptainHook (automated checks prior commit)
- Introduce Document-class
- Make all mandatory attributes of an API-request also mandatory (not nullable!) in the constructor of the Parameter-classes
- Explain in the docs contribution guidelines and the library objectives
- Create release/change log for v3.0
- Request to BigBlueButton 2.7 server to retrieve recordings results in an error with api-php 2.3.0, works with 2.2.0 HOT 7
- Check existence/validity of all URL in the document fixtures.
- Fatal error: Uncaught RuntimeException: Unhandled curl error: Could not resolve host: api in /home/eventicovh/public_html/aladicosmeticos2024/func/vendor/bigbluebutton/bigbluebutton-api-php/src/BigBlueButton.php:487 Stack t
- EventID filter doesn't run
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bigbluebutton-api-php.