This commit is contained in:
Andrew Nicols 2018-11-05 09:36:09 +08:00
commit 5aed9a4e26
8 changed files with 90 additions and 6 deletions

View File

@ -0,0 +1,44 @@
<?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/>.
/**
* Atto text editor recordrtc capabilities.
*
* @package atto_recordrtc
* @copyright 2018 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = [
// Capability to record audio using this plugin.
'atto/recordrtc:recordaudio' => [
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => [
'user' => CAP_ALLOW,
],
],
// Capability to record video using this plugin.
'atto/recordrtc:recordvideo' => [
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => [
'user' => CAP_ALLOW,
],
],
];

View File

@ -25,7 +25,7 @@
*/
$string['allowedtypes'] = 'Allowed types';
$string['allowedtypes_desc'] = 'Which recording buttons should appear in Atto';
$string['allowedtypes_desc'] = 'Which recording buttons should appear in Atto. In addition to this setting, there are also capabilities which can control access to the buttons to particular users in particular contexts.';
$string['attachrecording'] = 'Attach recording';
$string['audioandvideo'] = 'Audio and video';
$string['audiobitrate'] = 'Audio bitrate';
@ -61,6 +61,8 @@ $string['pluginname'] = 'RecordRTC';
$string['privacy:metadata'] = 'The RecordRTC plugin does not store any personal data.';
$string['recordagain'] = 'Record again';
$string['recordingfailed'] = 'Recording failed, try again';
$string['recordrtc:recordaudio'] = 'Record audio directly into the text editor';
$string['recordrtc:recordvideo'] = 'Record video directly into the text editor';
$string['settings'] = 'RecordRTC settings';
$string['startrecording'] = 'Start recording';
$string['stoprecording'] = 'Stop recording';

View File

@ -40,11 +40,28 @@ function atto_recordrtc_params_for_js($elementid, $options, $fpoptions) {
if (!$context) {
$context = context_system::instance();
}
$sesskey = sesskey();
$allowedtypes = get_config('atto_recordrtc', 'allowedtypes');
$audiobitrate = get_config('atto_recordrtc', 'audiobitrate');
$videobitrate = get_config('atto_recordrtc', 'videobitrate');
$timelimit = get_config('atto_recordrtc', 'timelimit');
// Update $allowedtypes to account for capabilities.
$audioallowed = $allowedtypes === 'audio' || $allowedtypes === 'both';
$videoallowed = $allowedtypes === 'video' || $allowedtypes === 'both';
$audioallowed = $audioallowed && has_capability('atto/recordrtc:recordaudio', $context);
$videoallowed = $videoallowed && has_capability('atto/recordrtc:recordvideo', $context);
if ($audioallowed && $videoallowed) {
$allowedtypes = 'both';
} else if ($audioallowed) {
$allowedtypes = 'audio';
} else if ($videoallowed) {
$allowedtypes = 'video';
} else {
$allowedtypes = '';
}
$maxrecsize = ini_get('upload_max_filesize');
$audiortcicon = 'i/audiortc';
$videortcicon = 'i/videortc';

View File

@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2018051400;
$plugin->version = 2018102900;
$plugin->requires = 2018050800;
$plugin->component = 'atto_recordrtc';
$plugin->maturity = MATURITY_STABLE;

View File

@ -97,12 +97,19 @@ Y.namespace('M.atto_recordrtc').Button = Y.Base.create('button', Y.M.editor_atto
initializer: function() {
if (this.get('host').canShowFilepicker('media')) {
// Add audio and/or video buttons depending on the settings.
var allowedtypes = this.get('allowedtypes');
var allowedtypes = this.get('allowedtypes'),
buttonadded = false;
if (allowedtypes === 'both' || allowedtypes === 'audio') {
this._addButton('audio', this._audio);
buttonadded = true;
}
if (allowedtypes === 'both' || allowedtypes === 'video') {
this._addButton('video', this._video);
buttonadded = true;
}
if (!buttonadded) {
// Plugin not available here.
return;
}
// Initialize the dialogue box.

View File

@ -1 +1 @@
YUI.add("moodle-atto_recordrtc-button",function(e,t){var n="atto_recordrtc",r='<div class="{{PLUGINNAME}} container-fluid"><div class="{{bs_row}} hide"><div class="{{bs_col}}12"><div id="alert-danger" class="alert {{bs_al_dang}}"><strong>{{insecurealert_title}}</strong> {{insecurealert}}</div></div></div><div class="{{bs_row}} hide">{{#if isAudio}}<div class="{{bs_col}}1"></div><div class="{{bs_col}}10"><audio id="player"></audio></div><div class="{{bs_col}}1"></div>{{else}}<div class="{{bs_col}}12"><video id="player"></video></div>{{/if}}</div><div class="{{bs_row}}"><div class="{{bs_col}}1"></div><div class="{{bs_col}}10"><button id="start-stop" class="{{bs_ss_btn}}">{{startrecording}}</button></div><div class="{{bs_col}}1"></div></div><div class="{{bs_row}} hide"><div class="{{bs_col}}3"></div><div class="{{bs_col}}6"><button id="upload" class="btn btn-primary btn-block">{{attachrecording}}</button></div><div class="{{bs_col}}3"></div></div></div>';e.namespace("M.atto_recordrtc").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_lang:"en",initializer:function(){if(this.get("host").canShowFilepicker("media")){var e=this.get("allowedtypes");(e==="both"||e==="audio")&&this._addButton("audio",this._audio),(e==="both"||e==="video")&&this._addButton("video",this._video);var t=this.getDialogue({width:1e3,focusAfterHide:null});t.after("visibleChange",function(){var e=!t.get("visible"),n=M.atto_recordrtc.commonmodule;e&&(window.clearInterval(n.countdownTicker),n.mediaRecorder&&n.mediaRecorder.state!=="inactive"&&n.mediaRecorder.stop(),n.stream&&n.stream.getTracks().forEach(function(e){e.readyState!=="ended"&&e.stop()}))}),t.on("click",function(){this.centered()}),window.require(["core/adapter"],function(e){window.adapter=e})}},_addButton:function(e,t){this.addButton({buttonName:e,icon:this.get(e+"rtcicon"),iconComponent:n,callback:t,title:e+"rtc",tags:e+"rtc",tagMatchRequiresAll:!1})},_audio:function(){var e=this.getDialogue();e.set("headerContent",M.util.get_string("audiortc","atto_recordrtc")),e.set("bodyContent",this._createContent("audio")),e.show(),M.atto_recordrtc.audiomodule.init(this)},_video:function(){var e=this.getDialogue();e.set("headerContent",M.util.get_string("videortc","atto_recordrtc")),e.set("bodyContent",this._createContent("video")),e.show(),M.atto_recordrtc.videomodule.init(this)},_createContent:function(t){var i=t==="audio",s="row",o="col-xs-",u="alert-danger",a="btn btn-lg btn-outline-danger btn-block",f=e.Handlebars.compile(r)({PLUGINNAME:n,isAudio:i,bs_row:s,bs_col:o,bs_al_dang:u,bs_ss_btn:a,insecurealert_title:M.util.get_string("insecurealert_title","atto_recordrtc"),insecurealert:M.util.get_string("insecurealert","atto_recordrtc"),startrecording:M.util.get_string("startrecording","atto_recordrtc"),attachrecording:M.util.get_string("attachrecording","atto_recordrtc")});return f},closeDialogue:function(e){e.getDialogue().hide(),e.editor.focus()},setLink:function(e,t){e.getDialogue().hide(),e.editor.focus(),e.get("host").insertContentAtFocusPoint(t),e.markUpdated()}},{ATTRS:{contextid:{value:null},sesskey:{value:null},allowedtypes:{value:null},audiobitrate:{value:null},videobitrate:{value:null},timelimit:{value:null},audiortcicon:{value:null},videortcicon:{value:null},maxrecsize:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin","moodle-atto_recordrtc-recording"]});
YUI.add("moodle-atto_recordrtc-button",function(e,t){var n="atto_recordrtc",r='<div class="{{PLUGINNAME}} container-fluid"><div class="{{bs_row}} hide"><div class="{{bs_col}}12"><div id="alert-danger" class="alert {{bs_al_dang}}"><strong>{{insecurealert_title}}</strong> {{insecurealert}}</div></div></div><div class="{{bs_row}} hide">{{#if isAudio}}<div class="{{bs_col}}1"></div><div class="{{bs_col}}10"><audio id="player"></audio></div><div class="{{bs_col}}1"></div>{{else}}<div class="{{bs_col}}12"><video id="player"></video></div>{{/if}}</div><div class="{{bs_row}}"><div class="{{bs_col}}1"></div><div class="{{bs_col}}10"><button id="start-stop" class="{{bs_ss_btn}}">{{startrecording}}</button></div><div class="{{bs_col}}1"></div></div><div class="{{bs_row}} hide"><div class="{{bs_col}}3"></div><div class="{{bs_col}}6"><button id="upload" class="btn btn-primary btn-block">{{attachrecording}}</button></div><div class="{{bs_col}}3"></div></div></div>';e.namespace("M.atto_recordrtc").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_lang:"en",initializer:function(){if(this.get("host").canShowFilepicker("media")){var e=this.get("allowedtypes"),t=!1;if(e==="both"||e==="audio")this._addButton("audio",this._audio),t=!0;if(e==="both"||e==="video")this._addButton("video",this._video),t=!0;if(!t)return;var n=this.getDialogue({width:1e3,focusAfterHide:null});n.after("visibleChange",function(){var e=!n.get("visible"),t=M.atto_recordrtc.commonmodule;e&&(window.clearInterval(t.countdownTicker),t.mediaRecorder&&t.mediaRecorder.state!=="inactive"&&t.mediaRecorder.stop(),t.stream&&t.stream.getTracks().forEach(function(e){e.readyState!=="ended"&&e.stop()}))}),n.on("click",function(){this.centered()}),window.require(["core/adapter"],function(e){window.adapter=e})}},_addButton:function(e,t){this.addButton({buttonName:e,icon:this.get(e+"rtcicon"),iconComponent:n,callback:t,title:e+"rtc",tags:e+"rtc",tagMatchRequiresAll:!1})},_audio:function(){var e=this.getDialogue();e.set("headerContent",M.util.get_string("audiortc","atto_recordrtc")),e.set("bodyContent",this._createContent("audio")),e.show(),M.atto_recordrtc.audiomodule.init(this)},_video:function(){var e=this.getDialogue();e.set("headerContent",M.util.get_string("videortc","atto_recordrtc")),e.set("bodyContent",this._createContent("video")),e.show(),M.atto_recordrtc.videomodule.init(this)},_createContent:function(t){var i=t==="audio",s="row",o="col-xs-",u="alert-danger",a="btn btn-lg btn-outline-danger btn-block",f=e.Handlebars.compile(r)({PLUGINNAME:n,isAudio:i,bs_row:s,bs_col:o,bs_al_dang:u,bs_ss_btn:a,insecurealert_title:M.util.get_string("insecurealert_title","atto_recordrtc"),insecurealert:M.util.get_string("insecurealert","atto_recordrtc"),startrecording:M.util.get_string("startrecording","atto_recordrtc"),attachrecording:M.util.get_string("attachrecording","atto_recordrtc")});return f},closeDialogue:function(e){e.getDialogue().hide(),e.editor.focus()},setLink:function(e,t){e.getDialogue().hide(),e.editor.focus(),e.get("host").insertContentAtFocusPoint(t),e.markUpdated()}},{ATTRS:{contextid:{value:null},sesskey:{value:null},allowedtypes:{value:null},audiobitrate:{value:null},videobitrate:{value:null},timelimit:{value:null},audiortcicon:{value:null},videortcicon:{value:null},maxrecsize:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin","moodle-atto_recordrtc-recording"]});

View File

@ -97,12 +97,19 @@ Y.namespace('M.atto_recordrtc').Button = Y.Base.create('button', Y.M.editor_atto
initializer: function() {
if (this.get('host').canShowFilepicker('media')) {
// Add audio and/or video buttons depending on the settings.
var allowedtypes = this.get('allowedtypes');
var allowedtypes = this.get('allowedtypes'),
buttonadded = false;
if (allowedtypes === 'both' || allowedtypes === 'audio') {
this._addButton('audio', this._audio);
buttonadded = true;
}
if (allowedtypes === 'both' || allowedtypes === 'video') {
this._addButton('video', this._video);
buttonadded = true;
}
if (!buttonadded) {
// Plugin not available here.
return;
}
// Initialize the dialogue box.

View File

@ -95,12 +95,19 @@ Y.namespace('M.atto_recordrtc').Button = Y.Base.create('button', Y.M.editor_atto
initializer: function() {
if (this.get('host').canShowFilepicker('media')) {
// Add audio and/or video buttons depending on the settings.
var allowedtypes = this.get('allowedtypes');
var allowedtypes = this.get('allowedtypes'),
buttonadded = false;
if (allowedtypes === 'both' || allowedtypes === 'audio') {
this._addButton('audio', this._audio);
buttonadded = true;
}
if (allowedtypes === 'both' || allowedtypes === 'video') {
this._addButton('video', this._video);
buttonadded = true;
}
if (!buttonadded) {
// Plugin not available here.
return;
}
// Initialize the dialogue box.