Gitlab CSE Unil

Commit c7ba9644 authored by M. Chardon's avatar M. Chardon
Browse files

gestion messages d'erreurs webrtc/micro

parent 30cde180
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(),this.initDisplay()}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||!window.MediaRecorder)return void alert("nowebrtc");if(!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)}),c.mediaRecorder&&"inactive"!==c.mediaRecorder.state&&c.mediaRecorder.stop(),window.stream&&window.stream.getTracks().forEach(function(a){"ended"!==a.readyState&&a.stop()});var h=null;navigator.mediaDevices.enumerateDevices().then(function(b){function e(a){window.console.log("Got stream, time diff :",Date.now()-l),d(a)}function f(a){m++;var b={audio:{deviceId:{exact:a}}};navigator.mediaDevices.getUserMedia(b).then(e)["catch"](g)}function g(b){i&&m<i.length?f(i[m]):(alert("microphone no available"),window.console.log("GUM failed with error, time diff: ",Date.now()-l),window.console.error("navigator.getUserMedia error:",b.name+": "+b.message),a(c.errorMsgElement).html("navigator.getUserMedia error:"+b.toString()))}var i=[];window.console.log(b);for(var j=0;j!==b.length;++j){var k=b[j];"audioinput"===k.kind&&(h=k.deviceId,window.console.log(h),i.push(h))}if(!h)return void alert("not available microphone");var l=Date.now(),m=0;navigator.mediaDevices.getUserMedia({audio:!0}).then(e)["catch"](g)})},c.prototype.initDisplay=function(){a.fn.justtext=function(){return a(this).clone().children().remove().end().text()},a(".audiofilepicker .form-filetypes-descriptions > ul").each(function(){var b=a(this).children("li");if(b&&!(b.length<2)){var c=a("<li></li>"),d=b[0],e=a(d).justtext();e=e.replace(/\ \((.*)\)/g,""),c.append(e);var f=a(d).children(),g="";f.each(function(){g=a(this).clone(),g.html("")}),b.each(function(){a(this).children().each(function(){g.append(a(this).text()+" ")}),a(this).remove()}),c.append(g),a(this).append(c)}})};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(),a("input[type=submit]").addClass("disabled"),a("input[type=submit]").attr("disabled","disabled"),a("input[type=submit]").prop("disabled",!0);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(),a("input[type=submit]").removeClass("disabled"),a("input[type=submit]").attr("disabled","false"),a("input[type=submit]").prop("disabled",!1);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()}else this.readyState>200&&(a("#sending"+d).hide(),a("input[type=submit]").removeClass("disabled"),a("input[type=submit]").attr("disabled","false"),a("input[type=submit]").prop("disabled",!1),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(),this.initDisplay()}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||!window.MediaRecorder)return a(".webrtcsupport").show(),void a(".record-tool").hide();if(!navigator.mediaDevices.getUserMedia)return a(".webrtcsupport").show(),a(".record-tool").hide(),void window.console.log("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)}),c.mediaRecorder&&"inactive"!==c.mediaRecorder.state&&c.mediaRecorder.stop(),window.stream&&window.stream.getTracks().forEach(function(a){"ended"!==a.readyState&&a.stop()});var h=null;navigator.mediaDevices.enumerateDevices().then(function(b){function e(a){window.console.log("Got stream, time diff :",Date.now()-l),d(a)}function f(a){m++;var b={audio:{deviceId:{exact:a}}};navigator.mediaDevices.getUserMedia(b).then(e)["catch"](g)}function g(b){i&&m<i.length?f(i[m]):(a(".microphone").show(),a(".record-tool").hide(),window.console.log("GUM failed with error, time diff: ",Date.now()-l),window.console.error("navigator.getUserMedia error:",b.name+": "+b.message),a(c.errorMsgElement).html("navigator.getUserMedia error:"+b.toString()))}var i=[];window.console.log(b);for(var j=0;j!==b.length;++j){var k=b[j];"audioinput"===k.kind&&(h=k.deviceId,window.console.log(h),i.push(h))}if(!h)return a(".microphone").show(),void a(".record-tool").hide();var l=Date.now(),m=0;navigator.mediaDevices.getUserMedia({audio:!0}).then(e)["catch"](g)})},c.prototype.initDisplay=function(){a.fn.justtext=function(){return a(this).clone().children().remove().end().text()},a(".audiofilepicker .form-filetypes-descriptions > ul").each(function(){var b=a(this).children("li");if(b&&!(b.length<2)){var c=a("<li></li>"),d=b[0],e=a(d).justtext();e=e.replace(/\ \((.*)\)/g,""),c.append(e);var f=a(d).children(),g="";f.each(function(){g=a(this).clone(),g.html("")}),b.each(function(){a(this).children().each(function(){g.append(a(this).text()+" ")}),a(this).remove()}),c.append(g),a(this).append(c)}})};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(),a("input[type=submit]").addClass("disabled"),a("input[type=submit]").attr("disabled","disabled"),a("input[type=submit]").prop("disabled",!0);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(),a("input[type=submit]").removeClass("disabled"),a("input[type=submit]").attr("disabled","false"),a("input[type=submit]").prop("disabled",!1);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()}else this.readyState>200&&(a("#sending"+d).hide(),a("input[type=submit]").removeClass("disabled"),a("input[type=submit]").attr("disabled","false"),a("input[type=submit]").prop("disabled",!1),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
......@@ -46,6 +46,7 @@ define(['jquery', 'mod_audioannotation/record'],
RecordsManager.statut = 'off';
RecordsManager.prototype.mediaSource = null;
RecordsManager.pauseTimestamp = 0;
/********************************
* CONSTRUCTOR *
********************************/
......@@ -89,7 +90,8 @@ define(['jquery', 'mod_audioannotation/record'],
// Show alert and close plugin if WebRTC is not supported.
// Older browsers might not implement mediaDevices at all
if (!(navigator.mediaDevices && window.MediaRecorder)) {
alert('nowebrtc');
$('.webrtcsupport').show();
$('.record-tool').hide();
return;
}
......@@ -136,7 +138,8 @@ define(['jquery', 'mod_audioannotation/record'],
//on verifie si on a au moins 1 micro dispo
if (!audiodeviceid) {
alert('not available microphone');
$('.microphone').show();
$('.record-tool').hide();
return;
}
......@@ -161,7 +164,8 @@ define(['jquery', 'mod_audioannotation/record'],
if (listDevices && pointeur < listDevices.length) {
tryGetUserMedia(listDevices[pointeur]);
} else {
alert('microphone no available');
$('.microphone').show();
$('.record-tool').hide();
window.console.log('GUM failed with error, time diff: ', Date.now() - now);
window.console.error('navigator.getUserMedia error:', e.name + ": " + e.message);
$(RecordsManager.errorMsgElement)
......@@ -173,7 +177,9 @@ define(['jquery', 'mod_audioannotation/record'],
navigator.mediaDevices.getUserMedia({audio: true}).then(gotStream).catch(errorStream);
});
} else {
alert('getUserMedia is not supported by your browser');
$('.webrtcsupport').show();
$('.record-tool').hide();
window.console.log('getUserMedia is not supported by your browser');
return;
}
};
......
......@@ -91,8 +91,18 @@ class assignaudio_form extends moodleform {
$mform->addElement('html', '<div class="col-md-9">');
$mform->addElement('html', '<div class="d-flex flex-row">');
$mform->addElement('html', '<div class="alert alert-danger webrtcsupport" style="display:none;">');
$mform->addElement('html', '<i class="fa fa-exclamation-triangle"></i> ');
$mform->addElement('html', get_string('message_webrtc', AUDIOANNOT_MODNAME));
$mform->addElement('html', '</div>');
$mform->addElement('html', '<div class="alert alert-warning microphone" style="display:none;">');
$mform->addElement('html', '<i class="fa fa-exclamation-circle"></i> ');
$mform->addElement('html', get_string('message_microphone', AUDIOANNOT_MODNAME));
$mform->addElement('html', '</div>');
$mform->addElement('html', '<div class="btn-group" role="group">');
$mform->addElement('html', '<div class="btn-group record-tool" role="group">');
$mform->addElement('html', '<button id="record' . $i . '" disabled="disabled" class="btn btn-record" type="button" data-statut="stop" data-toggle="tooltip" title="Enregistrement">');
$mform->addElement('html', '<span class="fa-stack">');
$mform->addElement('html', '<i class="fa fa-circle text-danger fa-stack-2x"></i>');
......
......@@ -187,6 +187,8 @@ $string['play_help'] = 'Play/Pause (shortcut: \'space\')';
$string['notify_student'] = 'Notify student';
$string['notify_teacher'] = 'Notify teachers';
$string['sendnotification'] = 'Send';
$string['message_webrtc'] = 'WEB RTC is not support on your browser. Please try with an other browser, or active web RTC support, to allow recording tools.';
$string['message_microphone'] = 'No available microphone.';
$string['audioannotation'] = 'Audio annotation';
$string['pluginadministration'] = 'Audio annotation administration';
......
......@@ -188,6 +188,8 @@ $string['play_help'] = 'Jouer/Pause (raccourci: \'espace\')';
$string['notify_student'] = 'Notifier l\'étudiant';
$string['notify_teacher'] = 'Notifier l\'équipe enseignante';
$string['sendnotification'] = 'Envoyer';
$string['message_webrtc'] = 'Web RTC n\'est pas supporté dans votre navigateur. Essayez avec un autre navigateur, ou activer la prise en charge du Web RTC pour activer les outils d\'enregistrement.';
$string['message_microphone'] = 'Pas de microphone disponible ou reconnu.';
$string['audioannotation'] = 'Audio annotation';
$string['pluginadministration'] = 'Audio annotation administration';
......
......@@ -197,4 +197,9 @@
li[data-annotation]{
cursor: pointer;
text-decoration: underline blue;
}
.webrtcsupport,
.microphone {
margin-bottom: 0 !important;
}
\ No newline at end of file
......@@ -118,7 +118,15 @@
{{#annotation.messageaudio}}{{# str }} audio_feedback_save, audioannotation {{/ str }}{{/annotation.messageaudio}}
<div id='audioPanel0' class='collapse m-t-1'>
<div class='d-flex flex-row'>
<div class="btn-group" role="group">
<div class="alert alert-danger webrtcsupport" style="display:none;">
<i class="fa fa-exclamation-triangle"></i> {{# str }} message_webrtc, audioannotation {{/ str }}
</div>
<div class="alert alert-warning microphone" style="display:none;">
<i class="fa fa-exclamation-circle"></i> {{# str }} message_microphone, audioannotation {{/ str }}
</div>
<div class="btn-group record-tool" role="group">
<button id="record0" disabled="disabled" class='btn btn-record' type="button">
<span class="fa-stack">
<i class="fa fa-circle text-danger fa-stack-2x"></i>
......
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