Gitlab CSE Unil

Commit 672a27c5 authored by M. Chardon's avatar M. Chardon
Browse files

ajout limite temps enregistrement

parent 00439591
define(["jquery"],function(a){function b(a){b.repo="repo"in a?a.repo:null,this.init(),this.initTrigger()}b.mediaSource=null,b.constraints={audio:!0},b.sourceBuffer=null,b.mediaRecorder=null,b.recordedBlobs=null,b.errorMsgElement="#errorMsg",b.recordButton="#record",b.pauseRecordButton="#pauseRecord",b.playButton="#play",b.removeButton="#remove",b.recordedVideo="#recorded",b.repo=-1,b.totalSize=0;var c=function(){window.console.log("MediaSource opened"),b.sourceBuffer=b.mediaSource.addSourceBuffer("audio/ogg"),window.console.log("Source buffer: ",b.sourceBuffer)},d=function(c){a(b.recordButton).attr("disabled",!1),window.console.log("getUserMedia() got stream:",c),window.stream=c};b.prototype.init=function(){a("#audio").html(a("#audioworkspace").html()),a("#audioworkspace").remove(),a(b.recordedVideo).attr("src")&&(a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1),a("input[name='file']").parent().parent().addClass("disabled")),b.mediaSource=new MediaSource,b.mediaSource.addEventListener("sourceopen",c,!1);try{navigator.mediaDevices.getUserMedia(b.constraints).then(function(a){d(a)})}catch(e){window.console.error("navigator.getUserMedia error:",e),a(b.errorMsgElement).html("navigator.getUserMedia error:"+e.toString())}},b.prototype.reset=function(){a(b.recordButton).attr("disabled",!1),a(b.recordedVideo).attr("src")&&(a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1)),this.initTrigger()},b.prototype.initTrigger=function(){a(b.recordButton).on("click",function(){"stop"===a(b.recordButton).data("statut")?(a(b.recordedVideo).attr("src",null),h(),a(b.recordButton).data("statut","start"),a(b.pauseRecordButton).attr("disabled",!1),a(b.pauseRecordButton).data("statut","off"),a(b.pauseRecordButton).find(".fa-ban").hide()):(g(),a(b.recordButton).data("statut","stop"),a(b.recordButton).find("i").addClass("fa-microphone"),a(b.recordButton).find("i").removeClass("fa-microphone-slash"),a(b.recordButton).addClass("btn-primary"),a(b.recordButton).removeClass("btn-danger"),a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1),a(b.pauseRecordButton).attr("disabled",!0),e())}),a(b.pauseRecordButton).on("click",function(){window.console.log(a(b.pauseRecordButton).data("statut")),"off"===a(b.pauseRecordButton).data("statut")?(i(),a(b.pauseRecordButton).data("statut","on"),a(b.pauseRecordButton).find(".fa-ban").show()):(j(),a(b.pauseRecordButton).data("statut","off"),a(b.pauseRecordButton).find(".fa-ban").hide())}),a(b.playButton).on("click",function(){if(!a(b.recordedVideo).attr("src")){var c=new Blob(b.recordedBlobs);a(b.recordedVideo).show(),a(b.recordedVideo).attr("src",null),a(b.recordedVideo).attr("srcObject",null),a(b.recordedVideo).attr("src",window.URL.createObjectURL(c))}a(b.recordedVideo).attr("controls",!0),a(b.recordedVideo).attr("autoplay",!0)}),a(b.removeButton).on("click",function(){a("input[name='filerecord']").val(-1),a("input[name='file']").parent().parent().removeClass("disabled"),a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordedVideo).hide(),a(b.recordedVideo).attr("src",null),a(b.recordedVideo).attr("srcObject",null)})};var e=function(){var c=new Blob(b.recordedBlobs),d=new window.FormData,e=(1e3*Math.random()).toString().replace(".","");d.append("repo_upload_file",c,e),d.append("itemid",e),d.append("title",e),d.append("repo_id",b.repo),d.append("env","editor"),d.append("sesskey",M.cfg.sesskey),d.append("savepath","/"),d.append("ctx_id",M.cfg.contextid);var f=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",g=new XMLHttpRequest;g.onreadystatechange=function(){if(4===this.readyState&&200===this.status){var b=g.response,c=JSON.parse(b);a("input[name='filerecord']").val(c.file),a("input[name='file']").parent().parent().addClass("disabled"),a("#sendok").show().fadeOut(3e3)}else this.readyState>200&&a("#sendko").show()},g.open("POST",f,!0),g.send(d)},f=function(a){a.data&&a.data.size>0&&b.recordedBlobs.push(a.data)},g=function(){b.mediaRecorder.stop(),window.console.log("Recorded Blobs: ",b.recordedBlobs)},h=function(){b.recordedBlobs=[];var c=null;try{b.mediaRecorder=new MediaRecorder(window.stream,c)}catch(d){return window.console.error("Exception while creating MediaRecorder:",d),void a(b.errorMsgElement).html("Exception while creating MediaRecorder: "+JSON.stringify(d))}window.console.log("Created MediaRecorder",b.mediaRecorder,"with options",c),a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordButton).find("i").removeClass("fa-microphone"),a(b.recordButton).find("i").addClass("fa-microphone-slash"),a(b.recordButton).removeClass("btn-primary"),a(b.recordButton).addClass("btn-danger"),b.mediaRecorder.onstop=function(a){window.console.log("Recorder stopped: ",a)},b.mediaRecorder.ondataavailable=f,b.mediaRecorder.start(10),window.console.log("MediaRecorder started",b.mediaRecorder)},i=function(){b.mediaRecorder&&(b.mediaRecorder.pause(),window.console.log("MediaRecorder paused",b.mediaRecorder))},j=function(){b.mediaRecorder&&(a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordButton).find("i").removeClass("fa-microphone"),a(b.recordButton).find("i").addClass("fa-microphone-slash"),a(b.recordButton).removeClass("btn-primary"),a(b.recordButton).addClass("btn-danger"),b.mediaRecorder.resume(),window.console.log("MediaRecorder resumed",b.mediaRecorder))};return b});
\ No newline at end of file
define(["jquery"],function(a){function b(a){b.repo="repo"in a?a.repo:null,b.limit="limit"in a&&a.limit>0?1e3*a.limit:null,this.init(),this.initTrigger()}b.mediaSource=null,b.constraints={audio:!0},b.sourceBuffer=null,b.mediaRecorder=null,b.recordedBlobs=null,b.errorMsgElement="#errorMsg",b.recordButton="#record",b.pauseRecordButton="#pauseRecord",b.playButton="#play",b.removeButton="#remove",b.recordedVideo="#recorded",b.repo=-1,b.initTimestamp=-1,b.timestampStop=0,b.limit=null;var c=function(){window.console.log("MediaSource opened"),b.sourceBuffer=b.mediaSource.addSourceBuffer("audio/ogg"),window.console.log("Source buffer: ",b.sourceBuffer)},d=function(c){a(b.recordButton).attr("disabled",!1),window.console.log("getUserMedia() got stream:",c),window.stream=c};b.prototype.init=function(){a("#audio").html(a("#audioworkspace").html()),a("#audioworkspace").remove(),a(b.recordedVideo).attr("src")&&(a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1),a("input[name='file']").parent().parent().addClass("disabled")),b.mediaSource=new MediaSource,b.mediaSource.addEventListener("sourceopen",c,!1);try{navigator.mediaDevices.getUserMedia(b.constraints).then(function(a){d(a)})}catch(e){window.console.error("navigator.getUserMedia error:",e),a(b.errorMsgElement).html("navigator.getUserMedia error:"+e.toString())}},b.prototype.reset=function(){a(b.recordButton).attr("disabled",!1),a(b.recordedVideo).attr("src")&&(a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1)),this.initTrigger()},b.prototype.initTrigger=function(){a(b.recordButton).on("click",function(){"stop"===a(b.recordButton).data("statut")?(a(b.recordedVideo).attr("src",null),h(),a(b.recordButton).data("statut","start"),a(b.pauseRecordButton).attr("disabled",!1),a(b.pauseRecordButton).data("statut","off"),a(b.pauseRecordButton).find(".fa-ban").hide()):(g(),a(b.recordButton).data("statut","stop"),a(b.recordButton).find("i").addClass("fa-microphone"),a(b.recordButton).find("i").removeClass("fa-microphone-slash"),a(b.recordButton).addClass("btn-primary"),a(b.recordButton).removeClass("btn-danger"),a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1),a(b.pauseRecordButton).attr("disabled",!0),e())}),a(b.pauseRecordButton).on("click",function(){window.console.log(a(b.pauseRecordButton).data("statut")),"off"===a(b.pauseRecordButton).data("statut")?(i(),a(b.pauseRecordButton).data("statut","on"),a(b.pauseRecordButton).find(".fa-ban").show()):(j(),a(b.pauseRecordButton).data("statut","off"),a(b.pauseRecordButton).find(".fa-ban").hide())}),a(b.playButton).on("click",function(){if(!a(b.recordedVideo).attr("src")){var c=new Blob(b.recordedBlobs);a(b.recordedVideo).show(),a(b.recordedVideo).attr("src",null),a(b.recordedVideo).attr("srcObject",null),a(b.recordedVideo).attr("src",window.URL.createObjectURL(c))}a(b.recordedVideo).attr("controls",!0),a(b.recordedVideo).attr("autoplay",!0)}),a(b.removeButton).on("click",function(){a("input[name='filerecord']").val(-1),a("input[name='file']").parent().parent().removeClass("disabled"),a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordedVideo).hide(),a(b.recordedVideo).attr("src",null),a(b.recordedVideo).attr("srcObject",null)})};var e=function(){var c=new Blob(b.recordedBlobs),d=new window.FormData,e=(1e3*Math.random()).toString().replace(".","");d.append("repo_upload_file",c,e),d.append("itemid",e),d.append("title",e),d.append("repo_id",b.repo),d.append("env","editor"),d.append("sesskey",M.cfg.sesskey),d.append("savepath","/"),d.append("ctx_id",M.cfg.contextid);var f=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",g=new XMLHttpRequest;g.onreadystatechange=function(){if(4===this.readyState&&200===this.status){var b=g.response,c=JSON.parse(b);a("input[name='filerecord']").val(c.file),a("input[name='file']").parent().parent().addClass("disabled"),a("#sendok").show().fadeOut(3e3)}else this.readyState>200&&a("#sendko").show()},g.open("POST",f,!0),g.send(d)},f=function(c){if(c.data&&c.data.size>0){b.initTimestamp<0&&(b.initTimestamp=c.timeStamp);var d=c.timeStamp-b.initTimestamp,e=new Date(d);e.setHours(e.getHours()-1);var f=e.getHours()<10?"0"+e.getHours():e.getHours(),g=e.getMinutes()<10?"0"+e.getMinutes():e.getMinutes(),h=e.getSeconds()<10?"0"+e.getSeconds():e.getSeconds(),i=f+":"+g+":"+h;a("#audiotime").text(i),b.limit&&d>b.limit&&0===b.timestampStop&&(b.timestampStop=1,a(b.recordButton).click()),b.recordedBlobs.push(c.data)}},g=function(){b.mediaRecorder.stop(),window.console.log("Recorded Blobs: ",b.recordedBlobs)},h=function(){b.recordedBlobs=[],b.initTimestamp=-1;var c=null;try{b.mediaRecorder=new MediaRecorder(window.stream,c)}catch(d){return window.console.error("Exception while creating MediaRecorder:",d),void a(b.errorMsgElement).html("Exception while creating MediaRecorder: "+JSON.stringify(d))}window.console.log("Created MediaRecorder",b.mediaRecorder,"with options",c),a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordButton).find("i").removeClass("fa-microphone"),a(b.recordButton).find("i").addClass("fa-microphone-slash"),a(b.recordButton).removeClass("btn-primary"),a(b.recordButton).addClass("btn-danger"),b.mediaRecorder.onstop=function(c){a("#audiotime").text(""),b.timestampStop=0,window.console.log("Recorder stopped: ",c)},b.mediaRecorder.ondataavailable=f,b.mediaRecorder.start(10),window.console.log("MediaRecorder started",b.mediaRecorder)},i=function(){b.mediaRecorder&&(b.mediaRecorder.pause(),window.console.log("MediaRecorder paused",b.mediaRecorder))},j=function(){b.mediaRecorder&&(a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordButton).find("i").removeClass("fa-microphone"),a(b.recordButton).find("i").addClass("fa-microphone-slash"),a(b.recordButton).removeClass("btn-primary"),a(b.recordButton).addClass("btn-danger"),b.mediaRecorder.resume(),window.console.log("MediaRecorder resumed",b.mediaRecorder))};return b});
\ No newline at end of file
......@@ -50,7 +50,9 @@ define(['jquery'],
Record.repo = -1;
Record.totalSize = 0;
Record.initTimestamp = -1;
Record.timestampStop = 0;
Record.limit = null;
/********************************
* CONSTRUCTOR *
......@@ -66,6 +68,7 @@ define(['jquery'],
function Record(data) {
//get data
Record.repo = 'repo' in data ? data['repo'] : null;
Record.limit = 'limit' in data && data['limit'] > 0 ? data['limit'] * 1000 : null;
//initialize
this.init();
this.initTrigger();
......@@ -241,6 +244,26 @@ define(['jquery'],
*/
var handleDataAvailable = function (event) {
if (event.data && event.data.size > 0) {
if (Record.initTimestamp < 0) {
Record.initTimestamp = event.timeStamp;
}
var realTimestamp = event.timeStamp - Record.initTimestamp;
var d = new Date(realTimestamp);
d.setHours(d.getHours() - 1);
var hours = (d.getHours() < 10) ? "0" + d.getHours() : d.getHours();
var minutes = (d.getMinutes() < 10) ? "0" + d.getMinutes() : d.getMinutes();
var secondes = (d.getSeconds() < 10) ? "0" + d.getSeconds() : d.getSeconds();
var formattedTime = hours + ":" + minutes + ":" + secondes;
$("#audiotime").text(formattedTime);
if (Record.limit && realTimestamp > Record.limit) {
//window.console.log("depassement");
if (Record.timestampStop === 0) {
//window.console.log("arret demandé");
Record.timestampStop = 1;
$(Record.recordButton).click();
}
}
//window.console.log(event.data);
Record.recordedBlobs.push(event.data);
}
};
......@@ -258,6 +281,7 @@ define(['jquery'],
*/
var startRecording = function () {
Record.recordedBlobs = [];
Record.initTimestamp = -1;
var options = null;
try {
Record.mediaRecorder = new MediaRecorder(window.stream, options);
......@@ -275,6 +299,8 @@ define(['jquery'],
$(Record.recordButton).removeClass('btn-primary');
$(Record.recordButton).addClass('btn-danger');
Record.mediaRecorder.onstop = function (event) {
$("#audiotime").text("");
Record.timestampStop = 0;
window.console.log('Recorder stopped: ', event);
};
Record.mediaRecorder.ondataavailable = handleDataAvailable;
......
......@@ -50,7 +50,7 @@ class backup_audioannotation_activity_structure_step extends backup_activity_str
$audioannotation = new backup_nested_element('audioannotation', array('id'), array(
'course', 'name', 'intro', 'introformat', 'timecreated', 'timemodified', 'grade',
'duedate', 'allowsubmissionsfromdate', 'cutoffdate', 'access', 'accessannotstartdate',
'accessannotenddate', 'dragdrop', 'filelimit', 'displaypause', 'recordagain'));
'accessannotenddate', 'dragdrop', 'filelimit', 'displaypause', 'recordagain', 'recordlimit'));
// The assignement table
$assignement = new backup_nested_element('assignement', array('id'), array(
......
......@@ -24,6 +24,7 @@
<FIELD NAME="filelimit" TYPE="int" LENGTH="11" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT=""/>
<FIELD NAME="displaypause" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" COMMENT=""/>
<FIELD NAME="recordagain" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" COMMENT=""/>
<FIELD NAME="recordlimit" TYPE="int" LENGTH="4" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT=""/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......
......@@ -52,6 +52,7 @@ $string['fieldsetremise'] = 'Job delivery settings';
$string['dragdrop'] = 'Allow deposit by drag and drop';
$string['settingdisplaypause'] = 'Display pause button of recorder';
$string['settingrecordagain'] = 'Student can record a new time';
$string['settingrecordlimit'] = 'Limit the size of the recording to (in seconds)';
$string['filelimit'] = 'Size limit of the file(s) to deposit';
$string['fieldsetannot'] = 'Annotation settings';
$string['settingaccess'] = 'Student has access to annotations';
......
......@@ -51,6 +51,7 @@ $string['settingcutoffdate_help'] = 'date limite aide';
$string['fieldsetremise'] = 'Réglages de la remise des travaux';
$string['settingdisplaypause'] = 'Afficher le bouton pause de l\'enregistreur';
$string['settingrecordagain'] = 'L\'étudiant peut se réenregistrer';
$string['settingrecordlimit'] = 'Limiter la taille de l\'enregistrement à (en secondes)';
$string['dragdrop'] = 'Autoriser le dépôt par drag and drop';
$string['filelimit'] = 'Taille limite du/des fichier(s) à déposer';
$string['fieldsetannot'] = 'Réglages de l\'annotation des travaux';
......
......@@ -99,10 +99,14 @@ class mod_audioannotation_mod_form extends moodleform_mod {
$mform->addElement('selectyesno', 'displaypause', $name);
$name = get_string('settingrecordagain', AUDIOANNOT_MODNAME);
$mform->addElement('selectyesno', 'recordagain', $name);
$mform->setDefault('recordagain',1);
$mform->setDefault('recordagain', 1);
$name = get_string('settingrecordlimit', AUDIOANNOT_MODNAME);
$mform->addElement('text', 'recordlimit', $name);
$mform->setType('recordlimit', PARAM_INT);
$mform->setDefault('recordlimit', null);
$name = get_string('dragdrop', AUDIOANNOT_MODNAME);
$mform->addElement('selectyesno', 'dragdrop', $name);
$mform->setDefault('dragdrop',1);
$mform->setDefault('dragdrop', 1);
$name = get_string('filelimit', AUDIOANNOT_MODNAME);
$selectoptions = array(
'1000' => '1 Mo',
......
......@@ -99,6 +99,12 @@
<button id="sendko" disabled="disabled" class='btn btn-danger' type="button" style="display: none;">{{# str }} error_sendfile, audioannotation {{/ str }}</button>
</div>
<div class='m-l-3'>
{{#audioannotation.recordlimit}}
<div class="alert alert-info">
<strong>Info!</strong> New records are limited to {{audioannotation.recordlimit}}sec.
</div>
{{/audioannotation.recordlimit}}
<div id="audiotime"></div>
<audio id="recorded" {{#audio}}src="{{audio}}"{{/audio}}></audio>
</div>
</div>
......@@ -113,7 +119,8 @@
require(['mod_audioannotation/record'], function(Record) {
$(document).ready( function() {
var repoid = {{repoid}};
var record = new Record({'repo' : repoid});
var limit = {{audioannotation.recordlimit}};
var record = new Record({'repo' : repoid, 'limit' : limit});
});
});
{{/ js }}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment