Merge branch 'MDL-68436' of https://github.com/timhunt/moodle
[moodle.git] / lib / editor / atto / plugins / recordrtc / yui / build / moodle-atto_recordrtc-recording / moodle-atto_recordrtc-recording-min.js
1 YUI.add("moodle-atto_recordrtc-recording",function(r,t){var l,a,e;M.atto_recordrtc=M.atto_recordrtc||{},l=M.atto_recordrtc.commonmodule,a=M.atto_recordrtc.abstractmodule,M.atto_recordrtc.commonmodule={editorScope:null,alertWarning:null,alertDanger:null,player:null,playerDOM:null,startStopBtn:null,uploadBtn:null,countdownSeconds:null,countdownTicker:null,recType:null,stream:null,mediaRecorder:null,chunks:null,blobSize:null,maxUploadSize:null,capture_user_media:function(t,e,o){window.navigator.mediaDevices.getUserMedia(t).then(e)["catch"](o)},handle_data_available:function(t){l.chunks.push(t.data),l.blobSize+=t.data.size,l.blobSize>=l.maxUploadSize&&(window.localStorage.getItem("alerted")?window.localStorage.removeItem("alerted"):(window.localStorage.setItem("alerted","true"),l.startStopBtn.simulate("click"),a.show_alert("nearingmaxsize")),l.chunks.pop())},handle_stop:function(){var t=new window.Blob(l.chunks,{type:l.mediaRecorder.mimeType});l.player.set("srcObject",null),l.player.set("src",window.URL.createObjectURL(t)),l.player.set("muted",!1),l.player.set("controls",!0),l.player.ancestor().ancestor().removeClass("hide"),l.uploadBtn.ancestor().ancestor().removeClass("hide"),l.uploadBtn.set("textContent",M.util.get_string("attachrecording","atto_recordrtc")),l.uploadBtn.set("disabled",!1),l.editorScope.getDialogue().centered(),l.uploadBtn.on("click",function(){0===l.chunks.length?a.show_alert("norecordingfound"):(l.uploadBtn.set("disabled",!0),l.upload_to_server(l.recType,function(t,e){"ended"===t?(l.uploadBtn.set("disabled",!1),l.insert_annotation(l.recType,e)):"upload-failed"===t?(l.uploadBtn.set("disabled",!1),l.uploadBtn.set("textContent",M.util.get_string("uploadfailed","atto_recordrtc")+" "+e)):"upload-failed-404"===t?(l.uploadBtn.set("disabled",!1),l.uploadBtn.set("textContent",M.util.get_string("uploadfailed404","atto_recordrtc"))):"upload-aborted"===t?(l.uploadBtn.set("disabled",!1),l.uploadBtn.set("textContent",M.util.get_string("uploadaborted","atto_recordrtc")+" "+e)):l.uploadBtn.set("textContent",t)}))})},start_recording:function(t,e){var o,r=a.select_rec_options(t);l.mediaRecorder=new window.MediaRecorder(e,r),l.mediaRecorder.ondataavailable=l.handle_data_available,l.mediaRecorder.onstop=l.handle_stop,l.mediaRecorder.start(1e3),l.player.set("muted",!0),l.countdownSeconds=l.editorScope.get("timelimit"),l.countdownSeconds++,o=M.util.get_string("stoprecording","atto_recordrtc"),o+=' (<span id="minutes"></span>:<span id="seconds"></span>)',l.startStopBtn.setHTML(o),l.set_time(),l.countdownTicker=window.setInterval(l.set_time,1e3),l.startStopBtn.set("disabled",!1)},stop_recording:function(t){var e,o;for(l.mediaRecorder.stop(),e=t.getTracks(),o=0;o<e.length;o++)e[o].stop()},upload_to_server:function(c,i){var s=new window.XMLHttpRequest;s.open("GET",l.player.get("src"),!0),s.responseType="blob",s.onload=function(){var t,e,o,r,n,a,d;if(200===s.status){for(t=this.response,e=(1e3*Math.random()).toString().replace(".",""),e+="audio"===c?"-audio.ogg":"-video.webm",o=new window.FormData,r=l.editorScope.get("host").get("filepickeroptions").link,n=window.Object.keys(r.repositories),o.append("repo_upload_file",t,e),o.append("itemid",r.itemid),a=0;a<n.length;a++)if("upload"===r.repositories[n[a]].type){o.append("repo_id",r.repositories[n[a]].id);break}o.append("env",r.env),o.append("sesskey",M.cfg.sesskey),o.append("client_id",r.client_id),o.append("savepath","/"),o.append("ctx_id",r.context.id),d=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",l.make_xmlhttprequest(d,o,function(t,e){"upload-ended"===t?i("ended",window.JSON.parse(e).url):i(t)})}},s.send()},make_xmlhttprequest:function(t,e,o){var r=new window.XMLHttpRequest;r.onreadystatechange=function(){4===r.readyState&&200===r.status?o("upload-ended",r.responseText):404===r.status&&o("upload-failed-404")},r.upload.onprogress=function(t){o(Math.round(t.loaded/t.total*100)+"% "+M.util.get_string("uploadprogress","atto_recordrtc"))},r.upload.onerror=function(t){o("upload-failed",t)},r.upload.onabort=function(t){o("upload-aborted",t)},r.open("POST",t),r.send(e)},pad:function(t){var e=t+"";return e.length<2?"0"+e:e},set_time:function(){l.countdownSeconds--,l.startStopBtn.one("span#seconds").set("textContent",l.pad(l.countdownSeconds%60)),l.startStopBtn.one("span#minutes").set("textContent",l.pad(window.parseInt(l.countdownSeconds/60,10))),0===l.countdownSeconds&&l.startStopBtn.simulate("click")},create_annotation:function(t,e){var o="";return o="audio"==t?"<audio controls='true'>":"<video controls='true'>",o+="<source src='"+e+"'>"+e,o+="audio"==t?"</audio>":"</video>"},insert_annotation:function(t,e){var o=l.create_annotation(t,e);o?l.editorScope.setLink(l.editorScope,o):l.uploadBtn.set("textContent",M.util.get_string("attachrecording","atto_recordrtc"))}},M.atto_recordrtc=M.atto_recordrtc||{},l=M.atto_recordrtc.commonmodule,a=M.atto_recordrtc.abstractmodule,M.atto_recordrtc.compatcheckmodule={check_has_gum:function(){navigator.mediaDevices&&window.MediaRecorder||a.show_alert("nowebrtc",function(){l.editorScope.closeDialogue(l.editorScope)})},check_secure:function(){"https:"===window.location.protocol||-1!==window.location.host.indexOf("localhost")||l.alertDanger.ancestor().ancestor().removeClass("hide")}},M.atto_recordrtc=M.atto_recordrtc||{},l=M.atto_recordrtc.commonmodule,a=M.atto_recordrtc.abstractmodule,M.atto_recordrtc.abstractmodule={show_alert:function(e,o){r.use("moodle-core-notification-alert",function(){var t=new M.core.alert({title:M.util.get_string(e+"_title","atto_recordrtc"),message:M.util.get_string(e,"atto_recordrtc")});o&&t.after("complete",o)})},handle_gum_errors:function(t,e){var o=M.util.get_string("recordingfailed","atto_recordrtc"),r=function(){e.onMediaStopped(o)},n="gum"+t.name.replace("Error","").toLowerCase();"gumsecurity"!==n?a.show_alert(n,r):a.show_alert(n,function(){l.editorScope.closeDialogue(l.editorScope)})},select_rec_options:function(t){var e,o,r;return o="audio"===t?(e=[
2 "audio/webm;codecs=opus","audio/ogg;codecs=opus"],{audioBitsPerSecond:window.parseInt(l.editorScope.get("audiobitrate"))}):(e=["video/webm;codecs=vp9,opus","video/webm;codecs=h264,opus","video/webm;codecs=vp8,opus"],{audioBitsPerSecond:window.parseInt(l.editorScope.get("audiobitrate")),videoBitsPerSecond:window.parseInt(l.editorScope.get("videobitrate"))}),0!==(r=e.filter(function(t){return window.MediaRecorder.isTypeSupported(t)})).length&&(o.mimeType=r[0]),o}},M.atto_recordrtc=M.atto_recordrtc||{},l=M.atto_recordrtc.commonmodule,a=M.atto_recordrtc.abstractmodule,e=M.atto_recordrtc.compatcheckmodule,M.atto_recordrtc.audiomodule={init:function(t){l.editorScope=t,l.alertWarning=r.one("div#alert-warning"),l.alertDanger=r.one("div#alert-danger"),l.player=r.one("audio#player"),l.playerDOM=document.querySelector("audio#player"),l.startStopBtn=r.one("button#start-stop"),l.uploadBtn=r.one("button#upload"),l.recType="audio",l.maxUploadSize=t.get("maxrecsize"),e.check_has_gum(),e.check_secure(),l.startStopBtn.on("click",function(){if(l.startStopBtn.set("disabled",!0),l.startStopBtn.get("textContent")===M.util.get_string("startrecording","atto_recordrtc")||l.startStopBtn.get("textContent")===M.util.get_string("recordagain","atto_recordrtc")||l.startStopBtn.get("textContent")===M.util.get_string("recordingfailed","atto_recordrtc")){l.player.ancestor().ancestor().addClass("hide"),l.uploadBtn.ancestor().ancestor().addClass("hide"),l.startStopBtn.replaceClass("btn-outline-danger","btn-danger"),l.chunks=[],l.blobSize=0,l.uploadBtn.detach("click");var e={onMediaCaptured:function(t){l.stream=t,l.start_recording(l.recType,l.stream)},onMediaStopped:function(t){l.startStopBtn.set("textContent",t),l.startStopBtn.set("disabled",!1),l.startStopBtn.replaceClass("btn-danger","btn-outline-danger")},onMediaCapturingFailed:function(t){a.handle_gum_errors(t,e)}};M.atto_recordrtc.audiomodule.capture_audio(e)}else window.clearInterval(l.countdownTicker),window.setTimeout(function(){l.startStopBtn.set("disabled",!1)},1e3),l.stop_recording(l.stream),l.startStopBtn.set("textContent",M.util.get_string("recordagain","atto_recordrtc")),l.startStopBtn.replaceClass("btn-danger","btn-outline-danger");l.editorScope.getDialogue().centered()})},capture_audio:function(e){l.capture_user_media({audio:!0},function(t){l.playerDOM.srcObject=t,e.onMediaCaptured(t)},function(t){e.onMediaCapturingFailed(t)})}},M.atto_recordrtc=M.atto_recordrtc||{},l=M.atto_recordrtc.commonmodule,a=M.atto_recordrtc.abstractmodule,e=M.atto_recordrtc.compatcheckmodule,M.atto_recordrtc.videomodule={init:function(t){l.editorScope=t,l.alertWarning=r.one("div#alert-warning"),l.alertDanger=r.one("div#alert-danger"),l.player=r.one("video#player"),l.playerDOM=document.querySelector("video#player"),l.startStopBtn=r.one("button#start-stop"),l.uploadBtn=r.one("button#upload"),l.recType="video",l.maxUploadSize=t.get("maxrecsize"),e.check_has_gum(),e.check_secure(),l.startStopBtn.on("click",function(){if(l.startStopBtn.set("disabled",!0),l.startStopBtn.get("textContent")===M.util.get_string("startrecording","atto_recordrtc")||l.startStopBtn.get("textContent")===M.util.get_string("recordagain","atto_recordrtc")||l.startStopBtn.get("textContent")===M.util.get_string("recordingfailed","atto_recordrtc")){l.uploadBtn.ancestor().ancestor().addClass("hide"),l.startStopBtn.replaceClass("btn-outline-danger","btn-danger"),l.chunks=[],l.blobSize=0,l.uploadBtn.detach("click");var e={onMediaCaptured:function(t){l.stream=t,l.start_recording(l.recType,l.stream)},onMediaStopped:function(t){l.startStopBtn.set("textContent",t),l.startStopBtn.set("disabled",!1),l.startStopBtn.replaceClass("btn-danger","btn-outline-danger")},onMediaCapturingFailed:function(t){a.handle_gum_errors(t,e)}};l.player.ancestor().ancestor().removeClass("hide"),l.player.set("controls",!1),M.atto_recordrtc.videomodule.capture_audio_video(e)}else window.clearInterval(l.countdownTicker),window.setTimeout(function(){l.startStopBtn.set("disabled",!1)},1e3),l.stop_recording(l.stream),l.startStopBtn.set("textContent",M.util.get_string("recordagain","atto_recordrtc")),l.startStopBtn.replaceClass("btn-danger","btn-outline-danger");l.editorScope.getDialogue().centered()})},capture_audio_video:function(e){l.capture_user_media({audio:!0,video:{width:{ideal:640},height:{ideal:480}}},function(t){l.playerDOM.srcObject=t,l.playerDOM.play(),e.onMediaCaptured(t)},function(t){e.onMediaCapturingFailed(t)})}}},"@VERSION@",{requires:["moodle-atto_recordrtc-button"]});