Rapport-Mobileapp/dist/assets/web-CKoccc5W.js

2 lines
12 KiB
JavaScript

import{g as ue,W as ce}from"./index-DfDxGoFI.js";var oe={};function de(y){return y&&y.__esModule?y:{default:y}}var he=de,V={exports:{}},Z;function le(){return Z||(Z=1,function(y){var i=function(s){var l=Object.prototype,u=l.hasOwnProperty,h=Object.defineProperty||function(r,e,t){r[e]=t.value},c,f=typeof Symbol=="function"?Symbol:{},d=f.iterator||"@@iterator",b=f.asyncIterator||"@@asyncIterator",p=f.toStringTag||"@@toStringTag";function v(r,e,t){return Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),r[e]}try{v({},"")}catch{v=function(e,t,o){return e[t]=o}}function I(r,e,t,o){var n=e&&e.prototype instanceof k?e:k,a=Object.create(n.prototype),g=new j(o||[]);return h(a,"_invoke",{value:ae(r,t,g)}),a}s.wrap=I;function N(r,e,t){try{return{type:"normal",arg:r.call(e,t)}}catch(o){return{type:"throw",arg:o}}}var Q="suspendedStart",ie="suspendedYield",z="executing",G="completed",E={};function k(){}function A(){}function P(){}var F={};v(F,d,function(){return this});var q=Object.getPrototypeOf,C=q&&q(q(B([])));C&&C!==l&&u.call(C,d)&&(F=C);var _=P.prototype=k.prototype=Object.create(F);A.prototype=P,h(_,"constructor",{value:P,configurable:!0}),h(P,"constructor",{value:A,configurable:!0}),A.displayName=v(P,p,"GeneratorFunction");function X(r){["next","throw","return"].forEach(function(e){v(r,e,function(t){return this._invoke(e,t)})})}s.isGeneratorFunction=function(r){var e=typeof r=="function"&&r.constructor;return e?e===A||(e.displayName||e.name)==="GeneratorFunction":!1},s.mark=function(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,P):(r.__proto__=P,v(r,p,"GeneratorFunction")),r.prototype=Object.create(_),r},s.awrap=function(r){return{__await:r}};function M(r,e){function t(a,g,m,w){var R=N(r[a],r,g);if(R.type==="throw")w(R.arg);else{var Y=R.arg,L=Y.value;return L&&typeof L=="object"&&u.call(L,"__await")?e.resolve(L.__await).then(function(T){t("next",T,m,w)},function(T){t("throw",T,m,w)}):e.resolve(L).then(function(T){Y.value=T,m(Y)},function(T){return t("throw",T,m,w)})}}var o;function n(a,g){function m(){return new e(function(w,R){t(a,g,w,R)})}return o=o?o.then(m,m):m()}h(this,"_invoke",{value:n})}X(M.prototype),v(M.prototype,b,function(){return this}),s.AsyncIterator=M,s.async=function(r,e,t,o,n){n===void 0&&(n=Promise);var a=new M(I(r,e,t,o),n);return s.isGeneratorFunction(e)?a:a.next().then(function(g){return g.done?g.value:a.next()})};function ae(r,e,t){var o=Q;return function(a,g){if(o===z)throw new Error("Generator is already running");if(o===G){if(a==="throw")throw g;return K()}for(t.method=a,t.arg=g;;){var m=t.delegate;if(m){var w=J(m,t);if(w){if(w===E)continue;return w}}if(t.method==="next")t.sent=t._sent=t.arg;else if(t.method==="throw"){if(o===Q)throw o=G,t.arg;t.dispatchException(t.arg)}else t.method==="return"&&t.abrupt("return",t.arg);o=z;var R=N(r,e,t);if(R.type==="normal"){if(o=t.done?G:ie,R.arg===E)continue;return{value:R.arg,done:t.done}}else R.type==="throw"&&(o=G,t.method="throw",t.arg=R.arg)}}}function J(r,e){var t=e.method,o=r.iterator[t];if(o===c)return e.delegate=null,t==="throw"&&r.iterator.return&&(e.method="return",e.arg=c,J(r,e),e.method==="throw")||t!=="return"&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+t+"' method")),E;var n=N(o,r.iterator,e.arg);if(n.type==="throw")return e.method="throw",e.arg=n.arg,e.delegate=null,E;var a=n.arg;if(!a)return e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,E;if(a.done)e[r.resultName]=a.value,e.next=r.nextLoc,e.method!=="return"&&(e.method="next",e.arg=c);else return a;return e.delegate=null,E}X(_),v(_,p,"Generator"),v(_,d,function(){return this}),v(_,"toString",function(){return"[object Generator]"});function se(r){var e={tryLoc:r[0]};1 in r&&(e.catchLoc=r[1]),2 in r&&(e.finallyLoc=r[2],e.afterLoc=r[3]),this.tryEntries.push(e)}function U(r){var e=r.completion||{};e.type="normal",delete e.arg,r.completion=e}function j(r){this.tryEntries=[{tryLoc:"root"}],r.forEach(se,this),this.reset(!0)}s.keys=function(r){var e=Object(r),t=[];for(var o in e)t.push(o);return t.reverse(),function n(){for(;t.length;){var a=t.pop();if(a in e)return n.value=a,n.done=!1,n}return n.done=!0,n}};function B(r){if(r){var e=r[d];if(e)return e.call(r);if(typeof r.next=="function")return r;if(!isNaN(r.length)){var t=-1,o=function n(){for(;++t<r.length;)if(u.call(r,t))return n.value=r[t],n.done=!1,n;return n.value=c,n.done=!0,n};return o.next=o}}return{next:K}}s.values=B;function K(){return{value:c,done:!0}}return j.prototype={constructor:j,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(U),!r)for(var e in this)e.charAt(0)==="t"&&u.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=c)},stop:function(){this.done=!0;var r=this.tryEntries[0],e=r.completion;if(e.type==="throw")throw e.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function t(w,R){return a.type="throw",a.arg=r,e.next=w,R&&(e.method="next",e.arg=c),!!R}for(var o=this.tryEntries.length-1;o>=0;--o){var n=this.tryEntries[o],a=n.completion;if(n.tryLoc==="root")return t("end");if(n.tryLoc<=this.prev){var g=u.call(n,"catchLoc"),m=u.call(n,"finallyLoc");if(g&&m){if(this.prev<n.catchLoc)return t(n.catchLoc,!0);if(this.prev<n.finallyLoc)return t(n.finallyLoc)}else if(g){if(this.prev<n.catchLoc)return t(n.catchLoc,!0)}else if(m){if(this.prev<n.finallyLoc)return t(n.finallyLoc)}else throw new Error("try statement without catch or finally")}}},abrupt:function(r,e){for(var t=this.tryEntries.length-1;t>=0;--t){var o=this.tryEntries[t];if(o.tryLoc<=this.prev&&u.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var n=o;break}}n&&(r==="break"||r==="continue")&&n.tryLoc<=e&&e<=n.finallyLoc&&(n=null);var a=n?n.completion:{};return a.type=r,a.arg=e,n?(this.method="next",this.next=n.finallyLoc,E):this.complete(a)},complete:function(r,e){if(r.type==="throw")throw r.arg;return r.type==="break"||r.type==="continue"?this.next=r.arg:r.type==="return"?(this.rval=this.arg=r.arg,this.method="return",this.next="end"):r.type==="normal"&&e&&(this.next=e),E},finish:function(r){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.finallyLoc===r)return this.complete(t.completion,t.afterLoc),U(t),E}},catch:function(r){for(var e=this.tryEntries.length-1;e>=0;--e){var t=this.tryEntries[e];if(t.tryLoc===r){var o=t.completion;if(o.type==="throw"){var n=o.arg;U(t)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,t){return this.delegate={iterator:B(r),resultName:e,nextLoc:t},this.method==="next"&&(this.arg=c),E}},s}(y.exports);try{regeneratorRuntime=i}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=i:Function("r","regeneratorRuntime = r")(i)}}(V)),V.exports}var W,x;function fe(){return x||(x=1,W=le()),W}var H,ee;function pe(){if(ee)return H;ee=1;function y(s,l,u,h,c,f,d){try{var b=s[f](d),p=b.value}catch(v){u(v);return}b.done?l(p):Promise.resolve(p).then(h,c)}function i(s){return function(){var l=this,u=arguments;return new Promise(function(h,c){var f=s.apply(l,u);function d(p){y(f,h,c,d,b,"next",p)}function b(p){y(f,h,c,d,b,"throw",p)}d(void 0)})}}return H=i,H}(function(y){var i=he;Object.defineProperty(y,"__esModule",{value:!0}),y.default=u;var s=i(fe()),l=i(pe());function u(c){return h.apply(this,arguments)}function h(){return(h=(0,l.default)(s.default.mark(function c(f){var d,b;return s.default.wrap(function(p){for(;;)switch(p.prev=p.next){case 0:return d=document.createElement("video"),b=new Promise(function(v,I){d.addEventListener("loadedmetadata",function(){d.duration===1/0?(d.currentTime=Number.MAX_SAFE_INTEGER,d.ontimeupdate=function(){d.ontimeupdate=null,v(d.duration),d.currentTime=0}):v(d.duration)}),d.onerror=function(N){return I(N.target.error)}}),d.src=typeof f=="string"||f instanceof String?f:window.URL.createObjectURL(f),p.abrupt("return",b);case 4:case"end":return p.stop()}},c)}))).apply(this,arguments)}})(oe);const ve=ue(oe),O=()=>({value:!0}),D=()=>({value:!1}),ge=()=>new Error("MISSING_PERMISSION"),me=()=>new Error("ALREADY_RECORDING"),Re=()=>new Error("DEVICE_CANNOT_VOICE_RECORD"),re=()=>new Error("FAILED_TO_RECORD"),ye=()=>new Error("EMPTY_RECORDING"),$=()=>new Error("RECORDING_HAS_NOT_STARTED"),te=()=>new Error("FAILED_TO_FETCH_RECORDING"),we=()=>new Error("COULD_NOT_QUERY_PERMISSION_STATUS"),Ee=["audio/aac","audio/webm;codecs=opus","audio/mp4","audio/webm","audio/ogg;codecs=opus"],ne=()=>new Promise(()=>{});class S{constructor(){this.mediaRecorder=null,this.chunks=[],this.pendingResult=ne()}static async canDeviceVoiceRecord(){var i;return((i=navigator==null?void 0:navigator.mediaDevices)===null||i===void 0?void 0:i.getUserMedia)==null||S.getSupportedMimeType()==null?D():O()}async startRecording(){if(this.mediaRecorder!=null)throw me();if(!(await S.canDeviceVoiceRecord()).value)throw Re();if(!(await S.hasAudioRecordingPermission().catch(()=>O())).value)throw ge();return navigator.mediaDevices.getUserMedia({audio:!0}).then(this.onSuccessfullyStartedRecording.bind(this)).catch(this.onFailedToStartRecording.bind(this))}async stopRecording(){if(this.mediaRecorder==null)throw $();try{return this.mediaRecorder.stop(),this.mediaRecorder.stream.getTracks().forEach(i=>i.stop()),this.pendingResult}catch{throw te()}finally{this.prepareInstanceForNextOperation()}}static async hasAudioRecordingPermission(){return navigator.permissions.query({name:"microphone"}).then(i=>({value:i.state==="granted"})).catch(()=>{throw we()})}static async requestAudioRecordingPermission(){return(await S.hasAudioRecordingPermission().catch(()=>D())).value?O():navigator.mediaDevices.getUserMedia({audio:!0}).then(()=>O()).catch(()=>D())}pauseRecording(){if(this.mediaRecorder==null)throw $();return this.mediaRecorder.state==="recording"?(this.mediaRecorder.pause(),Promise.resolve(O())):Promise.resolve(D())}resumeRecording(){if(this.mediaRecorder==null)throw $();return this.mediaRecorder.state==="paused"?(this.mediaRecorder.resume(),Promise.resolve(O())):Promise.resolve(D())}getCurrentStatus(){return this.mediaRecorder==null?Promise.resolve({status:"NONE"}):this.mediaRecorder.state==="recording"?Promise.resolve({status:"RECORDING"}):this.mediaRecorder.state==="paused"?Promise.resolve({status:"PAUSED"}):Promise.resolve({status:"NONE"})}static getSupportedMimeType(){if((MediaRecorder==null?void 0:MediaRecorder.isTypeSupported)==null)return null;const i=Ee.find(s=>MediaRecorder.isTypeSupported(s));return i??null}onSuccessfullyStartedRecording(i){return this.pendingResult=new Promise((s,l)=>{this.mediaRecorder=new MediaRecorder(i),this.mediaRecorder.onerror=()=>{this.prepareInstanceForNextOperation(),l(re())},this.mediaRecorder.onstop=async()=>{const u=S.getSupportedMimeType();if(u==null){this.prepareInstanceForNextOperation(),l(te());return}const h=new Blob(this.chunks,{type:u});if(h.size<=0){this.prepareInstanceForNextOperation(),l(ye());return}const c=await S.blobToBase64(h),f=await ve(h);this.prepareInstanceForNextOperation(),s({value:{recordDataBase64:c,mimeType:u,msDuration:f*1e3}})},this.mediaRecorder.ondataavailable=u=>this.chunks.push(u.data),this.mediaRecorder.start()}),O()}onFailedToStartRecording(){throw this.prepareInstanceForNextOperation(),re()}static blobToBase64(i){return new Promise(s=>{const l=new FileReader;l.onloadend=()=>{const u=String(l.result),h=u.split("base64,"),c=h.length>1?h[1]:u;s(c.trim())},l.readAsDataURL(i)})}prepareInstanceForNextOperation(){if(this.mediaRecorder!=null&&this.mediaRecorder.state==="recording")try{this.mediaRecorder.stop()}catch{}this.pendingResult=ne(),this.mediaRecorder=null,this.chunks=[]}}class be extends ce{constructor(){super(...arguments),this.voiceRecorderInstance=new S}canDeviceVoiceRecord(){return S.canDeviceVoiceRecord()}hasAudioRecordingPermission(){return S.hasAudioRecordingPermission()}requestAudioRecordingPermission(){return S.requestAudioRecordingPermission()}startRecording(){return this.voiceRecorderInstance.startRecording()}stopRecording(){return this.voiceRecorderInstance.stopRecording()}pauseRecording(){return this.voiceRecorderInstance.pauseRecording()}resumeRecording(){return this.voiceRecorderInstance.resumeRecording()}getCurrentStatus(){return this.voiceRecorderInstance.getCurrentStatus()}}export{be as VoiceRecorderWeb};