Merge branch 'MDL-80871-main' of https://github.com/andrewnicols/moodle
[moodle.git] / mod / bigbluebuttonbn / bbb_broker.php
blob6d6cab0824226c70ee44f7863992d08f5dba25ed
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Intermediator for handling requests from the BigBlueButton server.
20 * @package mod_bigbluebuttonbn
21 * @copyright 2010 onwards, Blindside Networks Inc
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
24 * @author Darko Miletic (darko.miletic [at] gmail [dt] com)
27 // We should not have any require login or MOODLE_INTERNAL Check in this file.
28 // phpcs:disable moodle.Files.MoodleInternal.MoodleInternalGlobalState,moodle.Files.RequireLogin.Missing
29 require(__DIR__ . '/../../config.php');
31 use Firebase\JWT\Key;
32 use mod_bigbluebuttonbn\broker;
33 use mod_bigbluebuttonbn\instance;
34 use mod_bigbluebuttonbn\local\config;
35 use mod_bigbluebuttonbn\meeting;
37 global $PAGE, $USER, $CFG, $SESSION, $DB;
39 $params = $_REQUEST;
41 $broker = new broker();
42 $error = $broker->validate_parameters($params);
43 if (!empty($error)) {
44 header('HTTP/1.0 400 Bad Request. ' . $error);
45 return;
48 $action = $params['action'];
50 $instance = instance::get_from_instanceid($params['bigbluebuttonbn']);
51 if (empty($instance)) {
52 header('HTTP/1.0 410 Gone. The activity may have been deleted');
53 return;
56 $PAGE->set_context($instance->get_context());
58 try {
59 switch (strtolower($action)) {
60 case 'recording_ready':
61 broker::process_recording_ready($instance, $params);
62 return;
63 case 'meeting_events':
64 // When meeting_events callback is implemented by BigBlueButton, Moodle receives a POST request
65 // which is processed in the function using super globals.
66 broker::process_meeting_events($instance);
67 return;
69 header("HTTP/1.0 400 Bad request. The action '{$action}' does not exist");
70 } catch (Exception $e) {
71 header('HTTP/1.0 500 Internal Server Error. ' . $e->getMessage());