Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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   * Atto recordrtc library functions
  19   *
  20   * @package    atto_recordrtc
  21   * @author     Jesus Federico (jesus [at] blindsidenetworks [dt] com)
  22   * @author     Jacob Prud'homme (jacob [dt] prudhomme [at] blindsidenetworks [dt] com)
  23   * @copyright  2017 Blindside Networks Inc.
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Set params for this plugin.
  31   *
  32   * @param string $elementid
  33   * @param stdClass $options - the options for the editor, including the context.
  34   * @param stdClass $fpoptions - unused.
  35   */
  36  function atto_recordrtc_params_for_js($elementid, $options, $fpoptions) {
  37      $context = $options['context'];
  38      if (!$context) {
  39          $context = context_system::instance();
  40      }
  41  
  42      $sesskey = sesskey();
  43      $allowedtypes = get_config('atto_recordrtc', 'allowedtypes');
  44      $audiobitrate = get_config('atto_recordrtc', 'audiobitrate');
  45      $videobitrate = get_config('atto_recordrtc', 'videobitrate');
  46      $timelimit = get_config('atto_recordrtc', 'timelimit');
  47  
  48      // Update $allowedtypes to account for capabilities.
  49      $audioallowed = $allowedtypes === 'audio' || $allowedtypes === 'both';
  50      $videoallowed = $allowedtypes === 'video' || $allowedtypes === 'both';
  51      $audioallowed = $audioallowed && has_capability('atto/recordrtc:recordaudio', $context);
  52      $videoallowed = $videoallowed && has_capability('atto/recordrtc:recordvideo', $context);
  53      if ($audioallowed && $videoallowed) {
  54          $allowedtypes = 'both';
  55      } else if ($audioallowed) {
  56          $allowedtypes = 'audio';
  57      } else if ($videoallowed) {
  58          $allowedtypes = 'video';
  59      } else {
  60          $allowedtypes = '';
  61      }
  62  
  63      $maxrecsize = get_max_upload_file_size();
  64      if (!empty($options['maxbytes'])) {
  65          $maxrecsize = min($maxrecsize, $options['maxbytes']);
  66      }
  67      $audiortcicon = 'i/audiortc';
  68      $videortcicon = 'i/videortc';
  69      $params = array('contextid' => $context->id,
  70                      'sesskey' => $sesskey,
  71                      'allowedtypes' => $allowedtypes,
  72                      'audiobitrate' => $audiobitrate,
  73                      'videobitrate' => $videobitrate,
  74                      'timelimit' => $timelimit,
  75                      'audiortcicon' => $audiortcicon,
  76                      'videortcicon' => $videortcicon,
  77                      'maxrecsize' => $maxrecsize
  78                );
  79  
  80      return $params;
  81  }
  82  
  83  /**
  84   * Initialise the js strings required for this module.
  85   */
  86  function atto_recordrtc_strings_for_js() {
  87      global $PAGE;
  88  
  89      $strings = array('audiortc',
  90                       'videortc',
  91                       'nowebrtc_title',
  92                       'nowebrtc',
  93                       'gumabort_title',
  94                       'gumabort',
  95                       'gumnotallowed_title',
  96                       'gumnotallowed',
  97                       'gumnotfound_title',
  98                       'gumnotfound',
  99                       'gumnotreadable_title',
 100                       'gumnotreadable',
 101                       'gumnotsupported',
 102                       'gumnotsupported_title',
 103                       'gumoverconstrained_title',
 104                       'gumoverconstrained',
 105                       'gumsecurity_title',
 106                       'gumsecurity',
 107                       'gumtype_title',
 108                       'gumtype',
 109                       'insecurealert_title',
 110                       'insecurealert',
 111                       'startrecording',
 112                       'recordagain',
 113                       'stoprecording',
 114                       'recordingfailed',
 115                       'attachrecording',
 116                       'norecordingfound_title',
 117                       'norecordingfound',
 118                       'nearingmaxsize_title',
 119                       'nearingmaxsize',
 120                       'uploadprogress',
 121                       'uploadfailed',
 122                       'uploadfailed404',
 123                       'uploadaborted'
 124                 );
 125  
 126      $PAGE->requires->strings_for_js($strings, 'atto_recordrtc');
 127  }
 128  
 129  /**
 130   * Map icons for font-awesome themes.
 131   */
 132  function atto_recordrtc_get_fontawesome_icon_map() {
 133      return [
 134          'atto_recordrtc:i/audiortc' => 'fa-microphone',
 135          'atto_recordrtc:i/videortc' => 'fa-video-camera'
 136      ];
 137  }