Skip to content

Commit

Permalink
add hooks for extensing analytics callbacks through extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jfederico committed Aug 22, 2024
1 parent e0a9cf2 commit 42f6a54
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 9 deletions.
4 changes: 1 addition & 3 deletions mod/bigbluebuttonbn/bbb_broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
22 changes: 16 additions & 6 deletions mod/bigbluebuttonbn/classes/broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use mod_bigbluebuttonbn\local\config;
use mod_bigbluebuttonbn\extension;

/**
* The broker routines
Expand All @@ -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].'
Expand All @@ -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]);
}

/**
Expand Down Expand Up @@ -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);
}


Expand Down
20 changes: 20 additions & 0 deletions mod/bigbluebuttonbn/classes/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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();
}
1 change: 1 addition & 0 deletions mod/bigbluebuttonbn/classes/meeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 42f6a54

Please sign in to comment.