Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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.
  13  //
  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/>.
  16  
  17  /**
  18   * Mobile output class for bigbluebuttonbn
  19   *
  20   * @package    mod_bigbluebuttonbn
  21   * @copyright  2018 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   */
  25  namespace mod_bigbluebuttonbn\output;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use mod_bigbluebuttonbn\instance;
  30  use mod_bigbluebuttonbn\local\exceptions\bigbluebutton_exception;
  31  use mod_bigbluebuttonbn\local\exceptions\meeting_join_exception;
  32  use mod_bigbluebuttonbn\local\exceptions\server_not_available_exception;
  33  use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
  34  use mod_bigbluebuttonbn\logger;
  35  use mod_bigbluebuttonbn\meeting;
  36  
  37  global $CFG;
  38  require_once($CFG->dirroot . '/lib/grouplib.php');
  39  
  40  /**
  41   * Mobile output class for bigbluebuttonbn
  42   *
  43   * @package    mod_bigbluebuttonbn
  44   * @copyright  2018 onwards, Blindside Networks Inc
  45   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  46   * @author     Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
  47   */
  48  class mobile {
  49  
  50      /**
  51       * Returns the bigbluebuttonbn course view for the mobile app.
  52       *
  53       * @param mixed $args
  54       * @return array HTML, javascript and other data.
  55       */
  56      public static function mobile_course_view($args): array {
  57          global $OUTPUT;
  58  
  59          $args = (object) $args;
  60          $versionname = $args->appversioncode >= 3950 ? 'latest' : 'ionic3';
  61  
  62          $instance = instance::get_from_cmid($args->cmid);
  63          if (!$instance) {
  64              return self::mobile_print_error(get_string('view_error_url_missing_parameters', 'bigbluebuttonbn'));
  65          }
  66  
  67          $cm = $instance->get_cm();
  68          $course = $instance->get_course();
  69  
  70          // Check activity status.
  71          if ($instance->before_start_time()) {
  72              $message = get_string('view_message_conference_not_started', 'bigbluebuttonbn');
  73  
  74              $notstarted = [
  75                  'starts_at' => '',
  76                  'ends_at' => '',
  77              ];
  78              if (!empty($instance->get_instance_var('openingtime'))) {
  79                  $notstarted['starts_at'] = sprintf(
  80                      '%s: %s',
  81                      get_string('mod_form_field_openingtime', 'bigbluebuttonbn'),
  82                      userdate($instance->get_instance_var('openingtime'))
  83                  );
  84              }
  85  
  86              if (!empty($instance->get_instance_var('closingtime'))) {
  87                  $notstarted['ends_at'] = sprintf(
  88                      '%s: %s',
  89                      get_string('mod_form_field_closingtime', 'bigbluebuttonbn'),
  90                      userdate($instance->get_instance_var('closingtime'))
  91                  );
  92              }
  93  
  94              return self::mobile_print_notification($instance, $message, $notstarted);
  95          }
  96  
  97          if ($instance->has_ended()) {
  98              $message = get_string('view_message_conference_has_ended', 'bigbluebuttonbn');
  99              return self::mobile_print_notification($instance, $message);
 100          }
 101  
 102          // Check if the BBB server is working.
 103          $serverversion = bigbluebutton_proxy::get_server_version();
 104          if ($serverversion === null) {
 105              return self::mobile_print_error(bigbluebutton_proxy::get_server_not_available_message($instance));
 106          }
 107  
 108          // Mark viewed by user (if required).
 109          $completion = new \completion_info($course);
 110          $completion->set_module_viewed($cm);
 111  
 112          // Validate if the user is in a role allowed to join.
 113          if (!$instance->can_join()) {
 114              return self::mobile_print_error(get_string('view_nojoin', 'bigbluebuttonbn'));
 115          }
 116  
 117          // Note: This logic should match bbb_view.php.
 118  
 119          // Logic of bbb_view for join to session.
 120          if ($instance->user_must_wait_to_join()) {
 121              // If user is not administrator nor moderator (user is student) and waiting is required.
 122              return self::mobile_print_notification(
 123                  $instance,
 124                  get_string('view_message_conference_wait_for_moderator', 'bigbluebuttonbn')
 125              );
 126          }
 127  
 128          // See if the BBB session is already in progress.
 129          $urltojoin = '';
 130          try {
 131              $urltojoin = meeting::join_meeting($instance);
 132          } catch (meeting_join_exception $e) {
 133              return self::mobile_print_notification($instance, $e->getMessage());
 134          } catch (server_not_available_exception $e) {
 135              return self::mobile_print_error(bigbluebutton_proxy::get_server_not_available_message($instance));
 136          }
 137  
 138          // Check groups access and show message.
 139          $msjgroup = [];
 140          $groupmode = groups_get_activity_groupmode($instance->get_cm());
 141          if ($groupmode != NOGROUPS) {
 142              $msjgroup['message'] = get_string('view_mobile_message_groups_not_supported', 'bigbluebuttonbn');
 143          }
 144  
 145          $data = [
 146              'bigbluebuttonbn' => $instance->get_instance_data(),
 147              'msjgroup' => $msjgroup,
 148              'urltojoin' => $urltojoin,
 149              'cmid' => $cm->id,
 150              'courseid' => $course->id,
 151          ];
 152  
 153          // We want to show a notification when user excedded 45 seconds without click button.
 154          $jstimecreatedmeeting = 'setTimeout(function(){
 155          document.getElementById("bigbluebuttonbn-mobile-notifications").style.display = "block";
 156          document.getElementById("bigbluebuttonbn-mobile-join").disabled = true;
 157          document.getElementById("bigbluebuttonbn-mobile-meetingready").style.display = "none";
 158          }, 45000);';
 159  
 160          return [
 161              'templates' => [
 162                  [
 163                      'id' => 'main',
 164                      'html' => $OUTPUT->render_from_template("mod_bigbluebuttonbn/mobile_view_page_$versionname", $data),
 165                  ],
 166              ],
 167              'javascript' => $jstimecreatedmeeting,
 168              'otherdata' => '',
 169              'files' => '',
 170          ];
 171      }
 172  
 173      /**
 174       * Returns the view for errors.
 175       *
 176       * @param string $error Error to display.
 177       * @return array HTML, javascript and otherdata
 178       */
 179      protected static function mobile_print_error($error): array {
 180          global $OUTPUT;
 181  
 182          return [
 183              'templates' => [
 184                  [
 185                      'id' => 'main',
 186                      'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_error', [
 187                          'error' => $error,
 188                      ]),
 189                  ],
 190              ],
 191              'javascript' => '',
 192              'otherdata' => '',
 193              'files' => '',
 194          ];
 195      }
 196  
 197      /**
 198       * Returns the view for messages.
 199       *
 200       * @param instance $instance
 201       * @param string $message Message to display.
 202       * @param array $notstarted Extra messages for not started session.
 203       * @return array HTML, javascript and otherdata
 204       */
 205      protected static function mobile_print_notification(instance $instance, $message, $notstarted = []): array {
 206          global $OUTPUT, $CFG;
 207  
 208          $data = [
 209              'bigbluebuttonbn' => $instance->get_instance_data(),
 210              'cmid' => $instance->get_cm_id(),
 211              'message' => $message,
 212              'not_started' => $notstarted,
 213          ];
 214  
 215          return [
 216              'templates' => [
 217                  [
 218                      'id' => 'main',
 219                      'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_notification', $data),
 220                  ],
 221              ],
 222              'javascript' => file_get_contents($CFG->dirroot . '/mod/bigbluebuttonbn/mobileapp/mobile.notification.js'),
 223              'otherdata' => '',
 224              'files' => ''
 225          ];
 226      }
 227  }