diff --git a/mod/bigbluebuttonbn/bbb_broker.php b/mod/bigbluebuttonbn/bbb_broker.php index 6d6cab0824226..dd2a09e354609 100644 --- a/mod/bigbluebuttonbn/bbb_broker.php +++ b/mod/bigbluebuttonbn/bbb_broker.php @@ -38,13 +38,11 @@ $params = $_REQUEST; -$broker = new broker(); -$error = $broker->validate_parameters($params); +$error = broker::validate_parameters($params); if (!empty($error)) { header('HTTP/1.0 400 Bad Request. ' . $error); return; } - $action = $params['action']; $instance = instance::get_from_instanceid($params['bigbluebuttonbn']); diff --git a/mod/bigbluebuttonbn/classes/broker.php b/mod/bigbluebuttonbn/classes/broker.php index 3c48634df31c9..5248d3b9d6715 100644 --- a/mod/bigbluebuttonbn/classes/broker.php +++ b/mod/bigbluebuttonbn/classes/broker.php @@ -20,6 +20,7 @@ use Firebase\JWT\JWT; use Firebase\JWT\Key; use mod_bigbluebuttonbn\local\config; +use mod_bigbluebuttonbn\extension; /** * The broker routines @@ -32,7 +33,7 @@ class broker { /** @var array List of required params */ - protected $requiredparams = [ + protected static $requiredparams = [ 'recording_ready' => [ 'bigbluebuttonbn' => 'The BigBlueButtonBN instance ID must be specified.', 'signed_parameters' => 'A JWT encoded string must be included as [signed_parameters].' @@ -48,16 +49,16 @@ class broker { * @param array $params * @return null|string */ - public function validate_parameters(array $params): ?string { + public static function validate_parameters(array $params): ?string { if (!isset($params['action']) || empty($params['action']) ) { return 'Parameter ['.$params['action'].'] was not included'; } $action = strtolower($params['action']); - if (!array_key_exists($action, $this->requiredparams)) { + if (!array_key_exists($action, self::$requiredparams)) { return "Action {$params['action']} can not be performed."; } - return $this->validate_parameters_message($params, $this->requiredparams[$action]); + return self::validate_parameters_message($params, self::$requiredparams[$action]); } /** @@ -153,15 +154,24 @@ public static function process_meeting_events(instance $instance) { // Get JSON string from the body. $jsonstr = file_get_contents('php://input'); + debugging($jsonstr, DEBUG_DEVELOPER); // Convert JSON string to a JSON object. $jsonobj = json_decode($jsonstr); $headermsg = meeting::meeting_events($instance, $jsonobj); - header($headermsg); + + // Hooks for extensions. + $extensions = extension::analytics_callback_addons_instances($instance); + foreach ($extensions as $extension) { + $extension->process_action(); + } } catch (Exception $e) { $msg = 'Caught exception: ' . $e->getMessage(); - header('HTTP/1.0 400 Bad Request. ' . $msg); + debugging($msg, DEBUG_DEVELOPER); + $headermsg = 'HTTP/1.0 400 Bad Request. ' . $msg; } + + header($headermsg); } diff --git a/mod/bigbluebuttonbn/classes/extension.php b/mod/bigbluebuttonbn/classes/extension.php index dff3546f33f2a..cd635ecead3bc 100644 --- a/mod/bigbluebuttonbn/classes/extension.php +++ b/mod/bigbluebuttonbn/classes/extension.php @@ -18,6 +18,7 @@ use cache; use cm_info; use mod_bigbluebuttonbn\local\extension\action_url_addons; +use mod_bigbluebuttonbn\local\extension\analytics_callback_addons; use mod_bigbluebuttonbn\local\extension\custom_completion_addons; use mod_bigbluebuttonbn\local\extension\mod_form_addons; use mod_bigbluebuttonbn\local\extension\mod_instance_helper; @@ -217,4 +218,23 @@ public static function delete_instance(int $id): void { $fmclass->delete_instance($id); } } + + /** + * Get all analytics_callback addons classes. + * + * @return array of analytics_callback addon classes. + */ + public static function analytics_callback_addons_classes(): array { + return self::get_classes_implementing(analytics_callback_addons::class); + } + + /** + * Get all analytics_callback addons classes instances + * + * @param instance|null $instance + * @return array of custom completion addon classes instances + */ + public static function analytics_callback_addons_instances(instance $instance): array { + return self::get_instances_implementing(analytics_callback_addons::class, [$instance]); + } } diff --git a/mod/bigbluebuttonbn/classes/local/extension/analytics_callback_addons.php b/mod/bigbluebuttonbn/classes/local/extension/analytics_callback_addons.php new file mode 100644 index 0000000000000..a441556cc47e7 --- /dev/null +++ b/mod/bigbluebuttonbn/classes/local/extension/analytics_callback_addons.php @@ -0,0 +1,49 @@ +. +namespace mod_bigbluebuttonbn\local\extension; + +use stdClass; +use Firebase\JWT\Key; +use mod_bigbluebuttonbn\broker; +use mod_bigbluebuttonbn\instance; +use mod_bigbluebuttonbn\meeting; + +/** + * A class to deal with broker addons in a subplugin + * + * @package mod_bigbluebuttonbn + * @copyright 2024 onwards, Blindside Networks Inc + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) + */ +abstract class analytics_callback_addons { + + /** + * @var instance|null $bigbluebuttonbn BigBlueButton instance if any + */ + protected $instance = null; + + /** + * Constructor + * + * @param instance|null $instance BigBlueButton instance if any + */ + public function __construct(?instance $instance = null) { + $this->instance = $instance; + } + + abstract public function process_action(); +} diff --git a/mod/bigbluebuttonbn/classes/meeting.php b/mod/bigbluebuttonbn/classes/meeting.php index 095a09d8a20c4..b65af88db022f 100644 --- a/mod/bigbluebuttonbn/classes/meeting.php +++ b/mod/bigbluebuttonbn/classes/meeting.php @@ -496,6 +496,7 @@ public static function meeting_events(instance $instance, object $data): string $meta['internalmeetingid'] = $data->{'internal_meeting_id'}; $meta['callback'] = 'meeting_events'; $meta['meetingid'] = $data->{'meeting_id'}; + $meta['data'] = $data->{'data'}; $eventcount = logger::log_event_callback($instance, $overrides, $meta); if ($eventcount === 1) {