Gitlab CSE Unil

Commit 02808b78 authored by M. Chardon's avatar M. Chardon
Browse files

correction bug indication chargement corrigé

parent e02cefba
define(["jquery","mod_audioannotation/record"],function(a,b){function c(a){c.repo="repo"in a?a.repo:null,c.limit="limit"in a&&a.limit>0?1e3*a.limit:null,c.nbRendu="nbRendu"in a&&a.nbRendu>0?a.nbRendu:1,this.init()}c.constraints={audio:!0},c.sourceBuffer=null,c.mediaRecorder=null,c.recordedBlobs=null,c.repo=-1,c.limit=null,c.nbRendu=1,c.records=null,c.statut="off",c.prototype.mediaSource=null,c.pauseTimestamp=0,c.prototype.init=function(){c.records=[];for(var f=0;f<c.nbRendu;f++){var g=[];g.manager=this,g.limit=c.limit,g.repo=c.repo,g.indice=f,c.records[f]=new b(g)}if(a("#audioworkspace").remove(),c.mediaSource=new MediaSource,c.mediaSource.addEventListener("sourceopen",e,!1),!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)return void alert("getUserMedia() is not supported by your browser");navigator.permissions.query({name:"microphone"}).then(function(a){window.console.log(a.state),window.stream&&window.stream.getTracks().forEach(function(a){a.stop()})})["catch"](function(a){window.console.log("Got error :",a)});var h=null;navigator.mediaDevices.enumerateDevices().then(function(b){for(var e=0;e!==b.length;++e){var f=b[e];"audioinput"===f.kind?h=f.deviceId:window.console.log("Found another kind of device: ",f)}if(window.console.log(h),!h)return void alert("not available microphone");var g={audio:{deviceId:{exact:h}}},i=Date.now();navigator.mediaDevices.getUserMedia(g).then(function(a){window.console.log("Got stream, time diff :",Date.now()-i),d(a)})["catch"](function(b){alert("microphone no available"),window.console.log("GUM failed with error, time diff: ",Date.now()-i),window.console.error("navigator.getUserMedia error:",b),a(c.errorMsgElement).html("navigator.getUserMedia error:"+b.toString())})})};var d=function(b){a(".btn-record").each(function(){a(this).prop("indice")>=0&&c.records[a(this).prop("indice")].initDisplayRecordButton(!0)}),window.console.log("getUserMedia() got stream:",b),window.stream=b},e=function(){window.console.log("MediaSource opened"),c.sourceBuffer=c.mediaSource.addSourceBuffer("audio/ogg"),window.console.log("Source buffer: ",c.sourceBuffer)};c.prototype.startRecording=function(b){if("off"!==c.statut)return!1;c.statut="on",c.recordedBlobs=[],c.initTimestamp=-1,c.pauseTimestamp=0;var d=null;try{c.mediaRecorder=new MediaRecorder(window.stream,d)}catch(e){return window.console.error("Exception while creating MediaRecorder:",e),void a(this.errorMsgElement).html("Exception while creating MediaRecorder: "+JSON.stringify(e))}return window.console.log("Created MediaRecorder",c.mediaRecorder,"with options",d),c.mediaRecorder.addEventListener("stop",function(d){a("#audiotime"+b).text(""),c.timestampStop=0,window.console.log("Recorder stopped: ",d)},!1),c.mediaRecorder.addEventListener("dataavailable",function(a){f(a,b)},!1),c.mediaRecorder.start(10),window.console.log("MediaRecorder started",c.mediaRecorder),!0};var f=function(b,d){if(b.data&&b.data.size>0){c.initTimestamp<0&&(c.initTimestamp=b.timeStamp);var e=b.timeStamp-c.initTimestamp-c.pauseTimestamp,f=new Date(e);f.setHours(f.getHours()-1);var g=f.getHours()<10?"0"+f.getHours():f.getHours(),h=f.getMinutes()<10?"0"+f.getMinutes():f.getMinutes(),i=f.getSeconds()<10?"0"+f.getSeconds():f.getSeconds(),j=g+":"+h+":"+i;a("#audiotime"+d).text(j),c.limit&&e>c.limit&&(c.timestampStop&&0!==c.timestampStop||(c.timestampStop=1,c.records[d].stopRecord())),c.recordedBlobs.push(b.data)}};return c.prototype.stopRecording=function(a){c.statut="off",c.mediaRecorder.stop(),window.console.log("Recorded Blobs: ",c.recordedBlobs);var b=c.recordedBlobs;c.records[a].sendBlob(b),this.sendFile(b,a)},c.prototype.sendFile=function(b,d){a("#sending"+d).show();var e=new Blob(b),f=new window.FormData,g=(1e3*Math.random()).toString().replace(".","");f.append("repo_upload_file",e,g),f.append("itemid",g),f.append("title",g),f.append("repo_id",c.repo),f.append("env","editor"),f.append("sesskey",M.cfg.sesskey),f.append("savepath","/"),f.append("ctx_id",M.cfg.contextid);var h=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",i=new XMLHttpRequest;i.addEventListener("readystatechange",function(){if(a("#sending"+d).hide(),4===this.readyState&&200===this.status){var b=i.response,c=JSON.parse(b);a("input[name='filerecord"+d+"']").val(c.file),a("input[name='file"+d+"']").parent().parent().addClass("disabled"),a("#sendok"+d).show().fadeOut(3e3)}else this.readyState>200&&a("#sendko"+d).show()},!1),i.open("POST",h,!0),i.send(f)},c.prototype.pauseRecording=function(a){c.mediaRecorder&&(c.pauseBeginTimestamp=a.timeStamp,c.mediaRecorder.pause(),window.console.log("MediaRecorder paused",c.mediaRecorder))},c.prototype.resumeRecording=function(a){c.mediaRecorder&&(c.pauseTimestamp+=a.timeStamp-c.pauseBeginTimestamp,c.mediaRecorder.resume(),window.console.log("MediaRecorder resumed",c.mediaRecorder))},c.prototype.reset=function(){for(var a=0;a<c.records.length;a++)c.records[a].reset()},c});
\ No newline at end of file
define(["jquery","mod_audioannotation/record"],function(a,b){function c(a){c.repo="repo"in a?a.repo:null,c.limit="limit"in a&&a.limit>0?1e3*a.limit:null,c.nbRendu="nbRendu"in a&&a.nbRendu>0?a.nbRendu:1,this.init()}c.constraints={audio:!0},c.sourceBuffer=null,c.mediaRecorder=null,c.recordedBlobs=null,c.repo=-1,c.limit=null,c.nbRendu=1,c.records=null,c.statut="off",c.prototype.mediaSource=null,c.pauseTimestamp=0,c.prototype.init=function(){c.records=[];for(var f=0;f<c.nbRendu;f++){var g=[];g.manager=this,g.limit=c.limit,g.repo=c.repo,g.indice=f,c.records[f]=new b(g)}if(a("#audioworkspace").remove(),c.mediaSource=new MediaSource,c.mediaSource.addEventListener("sourceopen",e,!1),!navigator.mediaDevices||!navigator.mediaDevices.getUserMedia)return void alert("getUserMedia() is not supported by your browser");navigator.permissions.query({name:"microphone"}).then(function(a){window.console.log(a.state),window.stream&&window.stream.getTracks().forEach(function(a){a.stop()})})["catch"](function(a){window.console.log("Got error :",a)});var h=null;navigator.mediaDevices.enumerateDevices().then(function(b){for(var e=0;e!==b.length;++e){var f=b[e];"audioinput"===f.kind?h=f.deviceId:window.console.log("Found another kind of device: ",f)}if(window.console.log(h),!h)return void alert("not available microphone");var g={audio:{deviceId:{exact:h}}},i=Date.now();navigator.mediaDevices.getUserMedia(g).then(function(a){window.console.log("Got stream, time diff :",Date.now()-i),d(a)})["catch"](function(b){alert("microphone no available"),window.console.log("GUM failed with error, time diff: ",Date.now()-i),window.console.error("navigator.getUserMedia error:",b),a(c.errorMsgElement).html("navigator.getUserMedia error:"+b.toString())})})};var d=function(b){a(".btn-record").each(function(){a(this).prop("indice")>=0&&c.records[a(this).prop("indice")].initDisplayRecordButton(!0)}),window.console.log("getUserMedia() got stream:",b),window.stream=b},e=function(){window.console.log("MediaSource opened"),c.sourceBuffer=c.mediaSource.addSourceBuffer("audio/ogg"),window.console.log("Source buffer: ",c.sourceBuffer)};c.prototype.startRecording=function(b){if("off"!==c.statut)return!1;c.statut="on",c.recordedBlobs=[],c.initTimestamp=-1,c.pauseTimestamp=0;var d=null;try{c.mediaRecorder=new MediaRecorder(window.stream,d)}catch(e){return window.console.error("Exception while creating MediaRecorder:",e),void a(this.errorMsgElement).html("Exception while creating MediaRecorder: "+JSON.stringify(e))}return window.console.log("Created MediaRecorder",c.mediaRecorder,"with options",d),c.mediaRecorder.addEventListener("stop",function(d){a("#audiotime"+b).text(""),c.timestampStop=0,window.console.log("Recorder stopped: ",d)},!1),c.mediaRecorder.addEventListener("dataavailable",function(a){f(a,b)},!1),c.mediaRecorder.start(10),window.console.log("MediaRecorder started",c.mediaRecorder),!0};var f=function(b,d){if(b.data&&b.data.size>0){c.initTimestamp<0&&(c.initTimestamp=b.timeStamp);var e=b.timeStamp-c.initTimestamp-c.pauseTimestamp,f=new Date(e);f.setHours(f.getHours()-1);var g=f.getHours()<10?"0"+f.getHours():f.getHours(),h=f.getMinutes()<10?"0"+f.getMinutes():f.getMinutes(),i=f.getSeconds()<10?"0"+f.getSeconds():f.getSeconds(),j=g+":"+h+":"+i;a("#audiotime"+d).text(j),c.limit&&e>c.limit&&(c.timestampStop&&0!==c.timestampStop||(c.timestampStop=1,c.records[d].stopRecord())),c.recordedBlobs.push(b.data)}};return c.prototype.stopRecording=function(a){c.statut="off",c.mediaRecorder.stop(),window.console.log("Recorded Blobs: ",c.recordedBlobs);var b=c.recordedBlobs;c.records[a].sendBlob(b),this.sendFile(b,a)},c.prototype.sendFile=function(b,d){a("#sending"+d).show();var e=new Blob(b),f=new window.FormData,g=(1e3*Math.random()).toString().replace(".","");f.append("repo_upload_file",e,g),f.append("itemid",g),f.append("title",g),f.append("repo_id",c.repo),f.append("env","editor"),f.append("sesskey",M.cfg.sesskey),f.append("savepath","/"),f.append("ctx_id",M.cfg.contextid);var h=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",i=new XMLHttpRequest;i.addEventListener("readystatechange",function(){if(4===this.readyState&&200===this.status){a("#sending"+d).hide();var b=i.response,c=JSON.parse(b);a("input[name='filerecord"+d+"']").val(c.file),a("input[name='file"+d+"']").parent().parent().addClass("disabled"),a("#sendok"+d).show().fadeOut(3e3)}else this.readyState>200&&(a("#sending"+d).hide(),a("#sendko"+d).show())},!1),i.open("POST",h,!0),i.send(f)},c.prototype.pauseRecording=function(a){c.mediaRecorder&&(c.pauseBeginTimestamp=a.timeStamp,c.mediaRecorder.pause(),window.console.log("MediaRecorder paused",c.mediaRecorder))},c.prototype.resumeRecording=function(a){c.mediaRecorder&&(c.pauseTimestamp+=a.timeStamp-c.pauseBeginTimestamp,c.mediaRecorder.resume(),window.console.log("MediaRecorder resumed",c.mediaRecorder))},c.prototype.reset=function(){for(var a=0;a<c.records.length;a++)c.records[a].reset()},c});
\ No newline at end of file
......@@ -284,8 +284,8 @@ define(['jquery', 'mod_audioannotation/record'],
var uploadEndpoint = M.cfg.wwwroot + '/repository/repository_ajax.php?action=upload';
var xhr = new XMLHttpRequest();
xhr.addEventListener('readystatechange', function () {
$("#sending" + indice).hide();
if (this.readyState === 4 && this.status === 200) {
$("#sending" + indice).hide();
// Typical action to be performed when the document is ready:
var response = xhr.response;
var responseO = JSON.parse(response);
......@@ -293,6 +293,7 @@ define(['jquery', 'mod_audioannotation/record'],
$("input[name='file" + indice + "']").parent().parent().addClass('disabled');
$("#sendok" + indice).show().fadeOut(3000);
} else if (this.readyState > 200) {
$("#sending" + indice).hide();
$("#sendko" + indice).show();
}
}, false);
......
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