testaugnitoambientsdk2 2.1.63 → 2.1.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,3936 @@
1
- function e(e,t,n,i){return new(n||(n=Promise))(function(r,o){function s(e){try{c(i.next(e))}catch(e){o(e)}}function a(e){try{c(i.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}c((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(e){Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"wssBaseURL",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onError",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onMetaEvent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.wssBaseURL=`wss://${e.server}/ambient/v1/stream-job`}prepareWSSURL(e,t,n,i,r,o){let s=this.wssBaseURL;return s+=`?filetype=${e}`,s+=`&noteparams=${t}`,s+=`&subscriptioncode=${this._config.subscriptionCode}`,s+=`&accesskey=${this._config.accessKey}`,s+=`&usertag=${this._config.userTag}`,n&&""!==n&&(s+=`&filename=${n}`),i&&""!==i&&(s+=`&jobid=${i}`),r&&""!==r&&(s+=`&parentjobid=${r}`),void 0!==o&&(s+=`&inheritparentconfig=${o}`),s}}class n{constructor(){}static get Against(){return n.instance||(n.instance=new n),n.instance}NullOrUndefined(e,t){if(null===e)throw new TypeError(`${t} is null`);if(void 0===e)throw new TypeError(`${t} is undefined`);return e}NullOrEmpty(e,t){if(!(e=n.Against.NullOrUndefined(e,t)))throw new TypeError(`${t} is empty`);return e}}var i,r,o,s,a;!function(e){e[e.SPECIALITY=1]="SPECIALITY",e[e.VISIT_TYPE=2]="VISIT_TYPE",e[e.NOTE_TYPE=3]="NOTE_TYPE",e[e.CLINICAL_CODE=4]="CLINICAL_CODE",e[e.LANGUAGE=5]="LANGUAGE",e[e.CDIVersion=7]="CDIVersion"}(i||(i={})),function(e){e[e.SoapNote=1]="SoapNote",e[e.PatientNote=2]="PatientNote",e[e.ReferralNote=3]="ReferralNote",e[e.ConsultationSummary=4]="ConsultationSummary",e[e.CDISuggestions=102]="CDISuggestions"}(r||(r={})),function(e){e.AUTH01="AUTH01",e.AUTH02="AUTH02",e.WSAUTH01="WSAUTH01",e.WSAUTH02="WSAUTH02",e.WSAUTH03="WSAUTH03",e.WSAUTH04="WSAUTH04",e.WSJOB01="WSJOB01",e.WSJOB02="WSJOB02",e.WSJOB03="WSJOB03",e.WSJOB04="WSJOB04",e.WSJOB05="WSJOB05",e.WSACC01="WSACC01",e.WSAUD01="WSAUD01",e.SDK01="SDK01",e.SDK02="SDK02",e.SDK03="SDK03",e.SDK04="SDK04",e.SDK05="SDK05",e.SDK06="SDK06",e.SDK07="SDK07",e.SDK08="SDK08",e.SDK12="SDK12",e.SDK13="SDK13",e.SDK14="SDK14",e.SDK15="SDK15",e.ERRUNKNOWN="ERRUNKNOWN"}(o||(o={}));class c extends Error{constructor(e,t){super(e),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.code=t,this.name="HttpCodedError",Object.setPrototypeOf(this,c.prototype)}}!function(e){e.Detailed="Detailed",e.Concise="Concise"}(s||(s={})),function(e){e.DashFormat="Dash-format",e.Paragraph="Paragraph"}(a||(a={}));class u{makePostRequest(t,n){return e(this,void 0,void 0,function*(){try{const i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!i.ok){const t=yield i.text();var e=JSON.parse(t);throw new c(e.message,e.code.toString())}return yield i.json()}catch(e){throw e}})}makePatchRequest(t,n){return e(this,void 0,void 0,function*(){try{const i=yield fetch(t,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!i.ok){const t=yield i.text();var e=JSON.parse(t);throw new c(e.message,i.status.toString())}return yield i.json()}catch(e){throw e instanceof c?e:new c("500",e.message||"Unexpected error")}})}}class l extends u{constructor(e){super(),Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_baseUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._baseUrl=`https://${e.server}/ambient/v1`}getURL(e){return`${this._baseUrl}${e}`}GetNoteParams(){return e(this,void 0,void 0,function*(){const e=this.getURL("/note-params"),t={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag};return yield this.makePostRequest(e,t)})}ListJobs(t,i,r){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Page Size");const e=this.getURL("/list-jobs"),o={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,PageSize:t,PageID:i,Collapse:r};return yield this.makePostRequest(e,o)})}FetchJob(t){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/fetch-job"),i={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t};return yield this.makePostRequest(e,i)})}SendFinalNote(t,i){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id"),n.Against.NullOrEmpty(i,"Note Data");const e=this.getURL("/send-final-note"),r={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,SoapData:i};return yield this.makePostRequest(e,r)})}DeleteNotes(t,i){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/delete-job"),r={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobIDs:t,DeleteParent:i};return yield this.makePostRequest(e,r)})}RenameNoteTitle(t,i){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id"),n.Against.NullOrEmpty(i,"Job Name");const e=this.getURL("/rename-job"),r={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,JobName:i};return yield this.makePostRequest(e,r)})}DownloadNotePDF(t,i,r,o,s,a){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/download-pdf");var c=s;c&&""!=c||(c='{"PatientName":"","PatientID":"","Age":"","Gender":"","ReceivingDoctor":"","DoctorName":"","DoctorDesignation":"","DoctorEmail":""}');const u={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,NoteType:i,Language:null!=o?o:"English",SpecialityID:r,Regenerate:null!=a&&a,PersonnelInfo:c};return yield this.makePostRequest(e,u)})}EndJob(t){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/end-job"),i={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t};return yield this.makePostRequest(e,i)})}UpdatePatientContext(t,i,r){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id"),n.Against.NullOrEmpty(i,"Patient Context");const e=this.getURL("/patient-context"),o={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,NewContext:i,Replace:r};return yield this.makePostRequest(e,o)})}GenerateSuggestions(t,i,r,o,s,a){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id");var e=this.getURL("/cdi");a&&2===a&&(e=this.getURL("/cdi").replace("/v1","/v2"));const c={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,Regenerate:i,SoapData:r,PatientContext:o,Codes:s};return yield this.makePostRequest(e,c)})}ModifyGeneratedNote(t,i,r){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/modify-note"),o={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,NoteType:i,NewNote:null!=r?r:""};return yield this.makePostRequest(e,o)})}FetchTranscription(t){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/fetch-transcript"),i={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t};return yield this.makePostRequest(e,i)})}SendFeedback(t,i,r,o){return e(this,void 0,void 0,function*(){n.Against.NullOrEmpty(t,"Job Id"),n.Against.NullOrUndefined(i,"Rating");const e=this.getURL("/feedback").replace("/v1","/v2"),s={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,Rating:i,FeedBack:null!=r?r:"",Type:null!=o?o:""};return yield this.makePostRequest(e,s)})}}class d{static log(e,t){const n=null!=t?t:this.defaultTag;console.log(`${n}:`,e)}static error(e,t){const n=null!=t?t:this.defaultTag;console.error(`${n}:`,e)}}function h(){h=function(){return t};var e,t={},n=Object.prototype,i=n.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},s=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function l(e,t,n,i){var o=t&&t.prototype instanceof m?t:m,s=Object.create(o.prototype),a=new O(i||[]);return r(s,"_invoke",{value:w(e,n,a)}),s}function d(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var f="suspendedStart",p="suspendedYield",g="executing",v="completed",b={};function m(){}function y(){}function S(){}var C={};u(C,s,function(){return this});var k=Object.getPrototypeOf,E=k&&k(k(_([])));E&&E!==n&&i.call(E,s)&&(C=E);var I=S.prototype=m.prototype=Object.create(C);function A(e){["next","throw","return"].forEach(function(t){u(e,t,function(e){return this._invoke(t,e)})})}function R(e,t){function n(r,o,s,a){var c=d(e[r],e,o);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==typeof l&&i.call(l,"__await")?t.resolve(l.__await).then(function(e){n("next",e,s,a)},function(e){n("throw",e,s,a)}):t.resolve(l).then(function(e){u.value=e,s(u)},function(e){return n("throw",e,s,a)})}a(c.arg)}var o;r(this,"_invoke",{value:function(e,i){function r(){return new t(function(t,r){n(e,i,t,r)})}return o=o?o.then(r,r):r()}})}function w(t,n,i){var r=f;return function(o,s){if(r===g)throw Error("Generator is already running");if(r===v){if("throw"===o)throw s;return{value:e,done:!0}}for(i.method=o,i.arg=s;;){var a=i.delegate;if(a){var c=P(a,i);if(c){if(c===b)continue;return c}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(r===f)throw r=v,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);r=g;var u=d(t,n,i);if("normal"===u.type){if(r=i.done?v:p,u.arg===b)continue;return{value:u.arg,done:i.done}}"throw"===u.type&&(r=v,i.method="throw",i.arg=u.arg)}}}function P(t,n){var i=n.method,r=t.iterator[i];if(r===e)return n.delegate=null,"throw"===i&&t.iterator.return&&(n.method="return",n.arg=e,P(t,n),"throw"===n.method)||"return"!==i&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+i+"' method")),b;var o=d(r,t.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,b;var s=o.arg;return s?s.done?(n[t.resultName]=s.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,b):s:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,b)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function D(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function _(t){if(t||""===t){var n=t[s];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function n(){for(;++r<t.length;)if(i.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=e,n.done=!0,n};return o.next=o}}throw new TypeError(typeof t+" is not iterable")}return y.prototype=S,r(I,"constructor",{value:S,configurable:!0}),r(S,"constructor",{value:y,configurable:!0}),y.displayName=u(S,c,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,S):(e.__proto__=S,u(e,c,"GeneratorFunction")),e.prototype=Object.create(I),e},t.awrap=function(e){return{__await:e}},A(R.prototype),u(R.prototype,a,function(){return this}),t.AsyncIterator=R,t.async=function(e,n,i,r,o){void 0===o&&(o=Promise);var s=new R(l(e,n,i,r),o);return t.isGeneratorFunction(n)?s:s.next().then(function(e){return e.done?e.value:s.next()})},A(I),u(I,c,"Generator"),u(I,s,function(){return this}),u(I,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),n=[];for(var i in t)n.push(i);return n.reverse(),function e(){for(;n.length;){var i=n.pop();if(i in t)return e.value=i,e.done=!1,e}return e.done=!0,e}},t.values=_,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(D),!t)for(var n in this)"t"===n.charAt(0)&&i.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function r(i,r){return a.type="throw",a.arg=t,n.next=i,r&&(n.method="next",n.arg=e),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var s=this.tryEntries[o],a=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var c=i.call(s,"catchLoc"),u=i.call(s,"finallyLoc");if(c&&u){if(this.prev<s.catchLoc)return r(s.catchLoc,!0);if(this.prev<s.finallyLoc)return r(s.finallyLoc)}else if(c){if(this.prev<s.catchLoc)return r(s.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return r(s.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,b):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),b},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),D(n),b}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var i=n.completion;if("throw"===i.type){var r=i.arg;D(n)}return r}}throw Error("illegal catch attempt")},delegateYield:function(t,n,i){return this.delegate={iterator:_(t),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=e),b}},t}function f(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function p(e,t,n,i,r,o,s){try{var a=e[o](s),c=a.value}catch(e){return void n(e)}a.done?t(c):Promise.resolve(c).then(i,r)}function g(e){return function(){var t=this,n=arguments;return new Promise(function(i,r){var o=e.apply(t,n);function s(e){p(o,i,r,s,a,"next",e)}function a(e){p(o,i,r,s,a,"throw",e)}s(void 0)})}}function v(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function b(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,f(i.key),i)}}function m(e,t,n){return t&&b(e.prototype,t),n&&b(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function S(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,o=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw o}}}}Object.defineProperty(d,"defaultTag",{enumerable:!0,configurable:!0,writable:!0,value:"AugnitoAmbientSDK"});var C="DONE",k="PAUSESOCKET",E="RESUMESOCKET",I="INTENT_START_STREAM",A="CLOSE",R=m(function e(t,n,i,r,o,s,a,c,u,l,d,h,f){v(this,e),this.worker,this.onFinalResultCallback=o,this.onErrorCallback=a,this.onPartialResultCallback=s,this.onSessionEventCallback=c,this.onOtherResultsCallback=u,this.onSpeechResponseCallback=l,this.onJobStatusCallback=d,this.packetSeqId=0,this.audioDuration=0,this.shouldSendAudioDataSequence=r,this.heavyOp,this.idleLoop,this.lastSent,this.enableLogs=t,this.eosMessage=n||"EOS",this.socketTimeoutInterval=i||1e4,this.bufferSizeInterval=h,this.switchToRegularSpeech=f},[{key:"Start",value:function(e,t,n){var i=this;this.audioDuration=e;var r="\n (() => {\n (".concat(w.toString(),")(").concat(JSON.stringify(C),", ").concat(JSON.stringify(this.eosMessage),", ").concat(JSON.stringify(A),", ").concat(JSON.stringify(1e4),", ").concat(JSON.stringify(this.socketTimeoutInterval),", ").concat(JSON.stringify(12e4),", ").concat(JSON.stringify(1e3),", ").concat(JSON.stringify(100),", ").concat(JSON.stringify(1e4),", ").concat(JSON.stringify(t),", ").concat(JSON.stringify(this.enableLogs),", ").concat(JSON.stringify(this.shouldSendAudioDataSequence),",").concat(JSON.stringify(k),", ").concat(JSON.stringify(E),", ").concat(JSON.stringify(I),", ").concat(JSON.stringify(this.switchToRegularSpeech),", ").concat(JSON.stringify(n),", ").concat(JSON.stringify(this.heavyOp),");\n })();\n");this.worker=new Worker(URL.createObjectURL(new Blob([r],{type:"application/javascript"}))),this.worker.onmessage=function(e){i.enableLogs&&console.log("Augnito [MAIN]: "+JSON.stringify(e.data));var t=e.data;"final"==t.type?i.onFinalResultCallback(t.data):"partial"==t.type?i.onPartialResultCallback(t.data):"meta"==t.type?i.onSessionEventCallback(t.data):"error"==t.type?i.onErrorCallback(t.data):"other"==t.type?i.onOtherResultsCallback(t.data):"jobstatus"==t.type?i.onJobStatusCallback(t.data.status):"speechResponse"==t.type&&i.onSpeechResponseCallback(t.data)}}},{key:"createAudioPacketHeader",value:function(e){this.audioDuration>0&&(this.packetSeqId=Math.ceil(this.audioDuration/this.bufferSizeInterval)+2,this.audioDuration=0),this.packetSeqId++;for(var t=new ArrayBuffer(16),n=new DataView(t),i=0;i<4;i++)n.setUint8(i,"@BSR".charCodeAt(i));return n.setBigInt64(4,BigInt(this.packetSeqId),!1),n.setUint8(12,e?1:0),t}},{key:"appendAudioData",value:function(e,t){var n=e.byteLength+t.byteLength,i=new ArrayBuffer(n),r=new Uint8Array(i);return r.set(new Uint8Array(e),0),r.set(new Uint8Array(t),e.byteLength),i}},{key:"Send",value:function(e){var t;if(this.lastSent=+new Date,e===A)null===(t=this.worker)||void 0===t||t.postMessage(A);else if(e===C)if(this.shouldSendAudioDataSequence){var n,i=this.createAudioPacketHeader(!0);null===(n=this.worker)||void 0===n||n.postMessage(i)}else{var r;null===(r=this.worker)||void 0===r||r.postMessage(C)}else if(e==k){var o;null===(o=this.worker)||void 0===o||o.postMessage(k)}else if(e==E){var s;null===(s=this.worker)||void 0===s||s.postMessage(E)}else if(e==I){var a;null===(a=this.worker)||void 0===a||a.postMessage(I)}else if(e===this.eosMessage){var c;this.shouldSendAudioDataSequence||null===(c=this.worker)||void 0===c||c.postMessage(e)}else{var u,l=[];this.shouldSendAudioDataSequence?(i=this.createAudioPacketHeader(!1),l=this.appendAudioData(i,e)):l=e,void 0!==l&&(null===(u=this.worker)||void 0===u||u.postMessage(l,[l]))}}},{key:"HeavyOp",set:function(e){this.heavyOp=e}}]);function w(e,t,n,i,r,o,s,a,c,u,l,d,h,f,p,g,v,b){var m,y,S,C,k,E,I,A,R,w=[],P=[],T=!1,D=[],O=!1,_=!1,x=!1,N="",U=v;function L(){m=+new Date,(E=""!=N?new WebSocket(u+"&jobid="+N):new WebSocket(u)).onopen=function(e){l&&console.log("Augnito: WebSocket connection established - "+JSON.stringify(e)),D.length>0&&(_=!0)},E.onmessage=function(e){l&&console.log("Augnito: Message from server - "+JSON.stringify(e.data)),S=+new Date,function(e){try{if("PING"===e.data)C=+new Date,self.postMessage({type:"ping",data:e.data});else{var t=JSON.parse(e.data);if(l&&console.log("Augnito [WORKER]: "+JSON.stringify(t)),"meta"==t.Type){t.JobID&&(N=t.JobID,console.log("Augnito JobID:",N)),self.postMessage({type:"meta",data:e.data});var n=JSON.parse(e.data);x=!(!n.Event||"INVALID_AUTH_CREDENTIALS"!==n.Event.Type)}else if(t.Result&&t.Result.Final){var i=JSON.stringify(t.Result);b&&(i=b(JSON.stringify(t.Result)),console.log(i)),self.postMessage({type:"final",data:i})}else t.Result&&!t.Result.Final?self.postMessage({type:"partial",data:t.Result.Transcript}):"ACK"==t.Type?(D=D.filter(function(e){return e.packetNumber>t.Index}),"RECEIVED_EOS"===t.Data.toUpperCase()&&(O=!0,clearInterval(R)),self.postMessage({type:"other",data:e.data})):"ERROR"==t.Type?("Timeout exceeded"==t.Data&&(O=!0,K()),self.postMessage({type:"error",data:e.data})):"STATUS"==t.Type?self.postMessage({type:"jobstatus",data:{status:e.data}}):self.postMessage({type:"speechResponse",data:e.data})}}catch(e){self.postMessage({type:"error",data:"invalid response"})}}(e)},E.onerror=function(e){console.error("WebSocket error: ",e),self.postMessage({type:"error",data:JSON.stringify(e)})},E.onclose=function(e){l&&console.log("Augnito: WebSocket connection closed - "+JSON.stringify(e)),K()},y=+new Date,S=y,C=+new Date}function M(e){if(E&&E.readyState===WebSocket.OPEN){E.send(e);var n=+new Date;return y<=S&&(S=n-1),y=n,!0}return e===t?(l&&console.warn("Gulping ".concat(t," as socket seems already closed...")),K(),!0):(+new Date-m>i&&!x&&L(),!1)}function J(e){w.push(e)}function K(){O&&(console.log("Augnito: Cleaning up worker resources..."),clearInterval(I),clearInterval(A),clearInterval(R),w=[],D=[],self.close())}L(),I=setInterval(function(){if(_){for(var e=0;e<D.length;e++){if(!M(D[e].packetData))break}_=!1}else for(;w.length>0;){var t=w.shift();if(!M(t)){w.unshift(t);break}if(d){if(!(t instanceof ArrayBuffer))continue;var n=new DataView(t),i={packetNumber:Number(n.getBigInt64(4)),packetData:t};D.push(i)}}},a),A=setInterval(function(){if(E&&E.readyState===WebSocket.OPEN){var e=+new Date;(g?y>S&&e-S>r:e-C>r)&&(l&&console.error("No data received since more than ".concat(r/1e3," secs, closing time...")),E.close())}},s),R=setInterval(function(){if(E&&E.readyState===WebSocket.OPEN){var e=+new Date;y&&e-y>o&&(l&&console.warn("No data sent since more than ".concat(o/1e3," secs, closing time...")),E.close())}},c),self.onmessage=function(i){if(i.data===n)N="",O=!0,x=!0,E.close();else if(i.data===e)J(t),N="",l&&console.log("Augnito: Worker received DONE, time to terminate..."),O=!0;else if(i.data===h)U=!0;else if(i.data===p)T=!0;else if(i.data===f){if(k instanceof ArrayBuffer&&J(k),P.length>0)for(var r=0;r<P.length;r++)J(P[r]);P=[],T=!1,U=!1,k=[]}else U&&!T?k=i.data:U&&T?P.push(i.data):J(i.data)}}var P,T,D,O,_,x,N,U,L,M,J=m(function e(t,n,i,r,o,s,a,c,u,l,d,h,f,p,g,b,m,y,S,C,k,E,I,A,w,P){v(this,e),this.audioContext,this.audioStream,this.executor=new R(n,s,a,c,m,y,S,k,E,I,w,r,h),this.executor.HeavyOp=b,this.source,this.processorNode,this.isPaused=!1,this.isStreaming=!1,this.audioData=[],this.isDebug=i,this.enableLogs=n,this.onStateChanged=C,this.onIntensity=A,this.onError=S,this.bufferSizeInterval=r,this.pausedBufferInterval=null!=o?o:1,this.shouldReadIntensity=d,this.closeSocketWithoutEOS=!1,this.shouldPreIntialiseRecorder=null!=l&&l,this.echoCancellation=f,this.noiseSuppression=p,this.autoGainControl=g,this.micNeedsRecovery=!1,this.trackEndedHandler=null,this.isRecovering=!1,this._micReadyFired=!1,this.currentWsUrl="",this.currentDuration=0,this.deviceChangeHandler=null,this.onMicReady=P,this.shouldPreIntialiseRecorder&&this.InitialiseMediaStream(u,t)},[{key:"InitialiseMediaStream",value:(M=g(h().mark(function e(t,n){var i=this;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.currentDuration=t,this.currentWsUrl=n,e.next=4,this.createMediaStreamSourceNode();case 4:if(this.source){e.next=7;break}return console.error("Error: unable to create source node"),e.abrupt("return",!1);case 7:return e.next=9,this.createProcessorNode();case 9:if(this.processorNode){e.next=12;break}return console.error("Error: unable to create processor node"),e.abrupt("return",!1);case 12:this.source.connect(this.processorNode).connect(this.audioContext.destination),this.log("AudioContext Sample Rate: "+this.audioContext.sampleRate),""!==n&&this.executor.Start(t,n,this.shouldPreIntialiseRecorder),this.deviceChangeHandler||(this.deviceChangeHandler=g(h().mark(function e(){var t,n,r,o,s,a,c;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if((s=null===(t=i.audioStream)||void 0===t||null===(n=t.getAudioTracks)||void 0===n?void 0:n.call(t)[0])&&"ended"!==s.readyState){e.next=7;break}return i.micNeedsRecovery=!0,e.next=6,i.recoverAudioGraph();case 6:return e.abrupt("return");case 7:return a=null!==(r=null===(o=s.getSettings)||void 0===o||null===(o=o.call(s))||void 0===o?void 0:o.deviceId)&&void 0!==r?r:s.label,e.next=10,K(a);case 10:if(e.sent){e.next=21;break}return i.micNeedsRecovery=!0,e.next=15,W(a,i.enableLogs);case 15:return c=e.sent,i._preferredDeviceId=c||null,e.next=19,i.recoverAudioGraph();case 19:e.next=21;break;case 21:case"end":return e.stop()}},e)})),navigator.mediaDevices.addEventListener("devicechange",this.deviceChangeHandler));case 16:case"end":return e.stop()}},e,this)})),function(e,t){return M.apply(this,arguments)})},{key:"StartStream",value:(L=g(h().mark(function e(t,n){var i,r;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.log("New stream started..."),this.shouldPreIntialiseRecorder&&this.source){e.next=6;break}return e.next=4,this.InitialiseMediaStream(t,n,!1);case 4:e.next=7;break;case 6:this.shouldPreIntialiseRecorder&&this.executor.Send(E);case 7:if(!this.IsMicrophoneMuted){e.next=15;break}if(!this.audioContext||"running"!=this.audioContext.state){e.next=11;break}return e.next=11,this.audioContext.suspend();case 11:return null===(i=this.audioStream)||void 0===i||null===(r=i.getTracks)||void 0===r||null===(r=r.call(i))||void 0===r||r.forEach(function(e){try{e.stop()}catch(e){}}),this.executor.Send(A),this.onError(JSON.stringify({Type:"ERROR",Data:"Microphone is muted."})),e.abrupt("return",!1);case 15:return this.onStateChanged(!0),this.isStreaming=!0,e.abrupt("return",!0);case 18:case"end":return e.stop()}},e,this)})),function(e,t){return L.apply(this,arguments)})},{key:"createBufferedSourceNode",value:(U=g(h().mark(function e(){var t;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.loadAudio();case 2:if(t=e.sent){e.next=6;break}return console.error("Error: unable to create audio buffer"),e.abrupt("return");case 6:this.source=this.audioContext.createBufferSource(),this.source.buffer=t,this.source.loop=!0,this.source.start();case 10:case"end":return e.stop()}},e,this)})),function(){return U.apply(this,arguments)})},{key:"createMediaStreamSourceNode",value:(N=g(h().mark(function e(){var t,n,i,r=this;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t={channelCount:1,noiseSuppression:void 0!==this.noiseSuppression&&this.noiseSuppression},void 0!==this.echoCancellation&&(t.echoCancellation=this.echoCancellation,t.googEchoCancellation=this.echoCancellation),void 0!==this.noiseSuppression&&(t.googNoiseSuppression=this.noiseSuppression),void 0!==this.autoGainControl&&(t.autoGainControl=this.autoGainControl,t.googAutoGainControl=this.autoGainControl),this._preferredDeviceId&&(t.deviceId={exact:this._preferredDeviceId}),e.next=8,navigator.mediaDevices.getUserMedia({audio:t});case 8:this.audioStream=e.sent,this.audioContext&&"closed"!==this.audioContext.state||(this.audioContext=new AudioContext),this.source=this.audioContext.createMediaStreamSource(this.audioStream),n=this.audioStream.getAudioTracks()[0],this.trackEndedHandler&&(this.trackEndedHandler=null),this.trackEndedHandler=g(h().mark(function e(){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r.micNeedsRecovery=!0,r.onError(JSON.stringify({Type:"ERROR",Data:"Audio track ended. Possibly the mic was unplugged."})),!r.isStreaming||r.isPaused){e.next=5;break}return e.next=5,r.recoverAudioGraph();case 5:case"end":return e.stop()}},e)})),n.addEventListener("ended",this.trackEndedHandler),e.next=22;break;case 17:e.prev=17,e.t0=e.catch(0),i="","NotAllowedError"==e.t0.name?i="Mic permission denied":"NotFoundError"===e.t0.name?i="No suitable media device found":"NotReadableError"===e.t0.name&&(i="Microphone is being used by another application"),this.onError(JSON.stringify({Type:"ERROR",Data:i}));case 22:case"end":return e.stop()}},e,this,[[0,17]])})),function(){return N.apply(this,arguments)})},{key:"loadAudio",value:(x=g(h().mark(function e(){var t,n,i;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,fetch("./radiology_speed_test.wav");case 3:return t=e.sent,e.next=6,t.arrayBuffer();case 6:return n=e.sent,e.next=9,this.audioContext.decodeAudioData(n);case 9:return i=e.sent,e.abrupt("return",i);case 13:return e.prev=13,e.t0=e.catch(0),console.error("Unable to fetch the audio file. Error: ".concat(e.t0.message)),e.abrupt("return",null);case 17:case"end":return e.stop()}},e,this,[[0,13]])})),function(){return x.apply(this,arguments)})},{key:"createProcessorNode",value:(_=g(h().mark(function e(){var t,n=this;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.audioContext.audioWorklet.addModule("data:application/javascript,".concat(encodeURIComponent('class MyAudioWorkletProcessor extends AudioWorkletProcessor {\n constructor() {\n super();\n this.accumulator = [];\n this.pauseSocketStreaming = false;\n this.sampleVal = 0;\n this.sampleSize = 0;\n this.intensityFrameCount = 0;\n this.reset();\n this.isProcessing = true;\n // message received from main-thread\n this.port.onmessage = (e) => {\n console.log("Augnito: Worklet received event - ", e.data);\n if (this.sampleSize > 0) {\n this.accumulator.push(this.sampleVal / this.sampleSize);\n }\n \n if (e.data == "PAUSE" || e.data == "STOP" || e.data == "PAUSESOCKET") {\n // append silence to get last word ASR.\n const silenceSize = 16000 * 2;\n for (let i = 0; i < silenceSize; i++) {\n this.accumulator.push(0.0003 * 0x7fff); // Push low-level noise instead of absolute silence to help ASR finalise\n }\n }\n this.send();\n this.reset();\n if (e.data == "STOP") {\n // message sent to main-thread\n this.port.postMessage({type:"DONE", value:"DONE"});\n this.isProcessing = false;\n \n }\n if(e.data == "PAUSESOCKET"){\n this.pauseSocketStreaming = true;\n this.port.postMessage("PAUSESOCKET");\n } else if(e.data == "RESUMESOCKET"){\n this.pauseSocketStreaming = false;\n } \n };\n }\n\n static get parameterDescriptors() {\n return [\n {\n name: "sampleRate",\n defaultValue: 16000,\n minValue: 16000,\n maxValue: 6 * 16000,\n },\n {\n name: "bufferSizeInterval",\n defaultValue: 1,\n minValue: 1,\n maxValue: 100,\n },\n {\n name: "pausedBufferInterval",\n defaultValue: 1,\n minValue: 0,\n maxValue: 100,\n },\n {\n name: "shouldReadIntensity",\n defaultValue: false,\n minValue: 0,\n maxValue: 1,\n },\n ];\n }\n\n // 128 frames\n process(inputList, outputList, params) {\n const input = inputList[0];\n if (input && input.length && input[0].length) {\n const channelData = input[0];\n const output = outputList[0];\n const inputSampleRate = params.sampleRate[0];\n const sampleRatio = inputSampleRate / 16000\n const bufferSizeInterval = params["bufferSizeInterval"][0];\n const pausedBufferInterval = params["pausedBufferInterval"][0];\n const shouldReadIntensity = params["shouldReadIntensity"][0];\n\n let sumSquares = 0; // For intensity\n let sampleCount = 0;\n\n // console.log("BufferSizeInterval", bufferSizeInterval);\n // Jackpot\n input[0].forEach((float32Element, index) => {\n const int16Element = Math.min(1, Math.max(-1, float32Element)) * 0x7fff;\n this.sampleVal += int16Element;\n this.sampleSize += 1;\n // Accumulate for intensity (RMS)\n sumSquares += float32Element * float32Element;\n sampleCount++;\n \n\n if (this.sampleSize >= sampleRatio) {\n const fraction = this.sampleSize - sampleRatio \n this.sampleVal -= fraction * int16Element;\n\n this.accumulator.push(this.sampleVal / sampleRatio);\n \n this.sampleVal = fraction * int16Element;\n this.sampleSize = fraction;\n }\n\n // Comment this when streaming microphone audio\n // output[0][index] = float32Element;\n });\n if(this.pauseSocketStreaming){\n if (this.accumulator.length >= 125 * 128 * pausedBufferInterval) {\n this.send();\n }\n } else{\n if (this.accumulator.length >= 125 * 128 * bufferSizeInterval) {\n this.send();\n }\n }\n if(shouldReadIntensity){\n \n // Throttled intensity post\n this.intensityFrameCount = (this.intensityFrameCount || 0) + 1;\n if (this.intensityFrameCount >= 15 && sampleCount > 0) {\n const rms = Math.sqrt(sumSquares / sampleCount);\n const normalized = Math.min(1, rms); // [0–1] scale\n this.port.postMessage({ type: \'intensity\', value: normalized });\n this.intensityFrameCount = 0;\n }\n }\n }\n return this.isProcessing;\n }\n\n send() {\n if (this.accumulator.length == 0) return;\n const audioData = new Int16Array(this.accumulator);\n // message sent to main-thread - transferrable\n this.port.postMessage({ type: \'audioData\', value: audioData.buffer }, [audioData.buffer]);\n this.accumulator = [];\n }\n\n reset() {\n this.sampleVal = 0;\n this.sampleSize = 0;\n }\n}\n\nregisterProcessor("worklet-processor", MyAudioWorkletProcessor);')));case 3:this.processorNode=new AudioWorkletNode(this.audioContext,"worklet-processor"),this.processorNode.parameters.get("sampleRate").setValueAtTime(this.audioContext.sampleRate,this.audioContext.currentTime),this.processorNode.parameters.get("bufferSizeInterval").setValueAtTime(this.bufferSizeInterval,this.audioContext.currentTime),this.processorNode.parameters.get("pausedBufferInterval").setValueAtTime(this.pausedBufferInterval,this.audioContext.currentTime),this.processorNode.parameters.get("shouldReadIntensity").setValueAtTime(null!==(t=this.shouldReadIntensity)&&void 0!==t&&t,this.audioContext.currentTime),this.processorNode.port.onmessage=function(e){var t=e.data,i=t.type,r=t.value;if(i==C)n.log("Worklet processing done, clearing resources..."),n.isDebug&&n.saveAudio(),n.cleanup();else if(e.data==k)n.executor.Send(k);else{var o;"intensity"===i?null===(o=n.onIntensity)||void 0===o||o.call(n,r):"audioData"===i&&n.isDebug&&new Int16Array(r).forEach(function(e){n.audioData.length<=288e5&&n.audioData.push(e)})}n.executor&&(n.closeSocketWithoutEOS?(n.executor.Send(A),n.closeSocketWithoutEOS=!1):"intensity"!==i&&n.executor.Send(r))},e.next=18;break;case 15:e.prev=15,e.t0=e.catch(0),console.error("Error: Unable to create worklet node: ",e.t0);case 18:case"end":return e.stop()}},e,this,[[0,15]])})),function(){return _.apply(this,arguments)})},{key:"PauseStream",value:(O=g(h().mark(function e(){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("running"!=this.audioContext.state){e.next=9;break}if(this.shouldPreIntialiseRecorder){e.next=8;break}return e.next=4,this.audioContext.suspend();case 4:this.log("Stream paused..."),this.processorNode.port.postMessage("PAUSE"),e.next=9;break;case 8:this.processorNode.port.postMessage(k);case 9:this.onStateChanged(!1),this.isPaused=!0,this.isStreaming=!1;case 12:case"end":return e.stop()}},e,this)})),function(){return O.apply(this,arguments)})},{key:"ResumeStream",value:(D=g(h().mark(function e(){var t,n,i;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if((i=null===(t=this.audioStream)||void 0===t||null===(n=t.getAudioTracks)||void 0===n?void 0:n.call(t)[0])&&"ended"!==i.readyState&&!this.micNeedsRecovery){e.next=5;break}return e.next=5,this.recoverAudioGraph();case 5:if(!this.IsMicrophoneMuted){e.next=11;break}if(!this.audioContext||"running"!==this.audioContext.state){e.next=9;break}return e.next=9,this.audioContext.suspend();case 9:return this.onError(JSON.stringify({Type:"ERROR",Data:"Microphone is muted."})),e.abrupt("return");case 11:if(!this.shouldPreIntialiseRecorder){e.next=16;break}this.processorNode.port.postMessage(E),this.executor.Send(E),e.next=20;break;case 16:if("suspended"!==this.audioContext.state){e.next=19;break}return e.next=19,this.audioContext.resume();case 19:this.log("Stream resumed...");case 20:this.onStateChanged(!0),this.isPaused=!1,this.isStreaming=!0;case 23:case"end":return e.stop()}},e,this)})),function(){return D.apply(this,arguments)})},{key:"IsPaused",get:function(){return this.isPaused}},{key:"IsStreaming",get:function(){return this.isStreaming}},{key:"IsMicrophoneMuted",get:function(){var e,t,n=null===(e=this.audioStream)||void 0===e||null===(t=e.getAudioTracks)||void 0===t?void 0:t.call(e)[0];return!n||n.muted||"ended"===n.readyState}},{key:"StopStream",value:(T=g(h().mark(function e(t){var n,i,r,o,s,a,c,u;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("suspended"===(null===(n=this.audioContext)||void 0===n?void 0:n.state)){e.next=4;break}return e.next=3,null===(c=this.audioContext)||void 0===c?void 0:c.suspend();case 3:this.onStateChanged(!1);case 4:this.log("Stream stopped..."),this.isStreaming=!1,this.isPaused=!1,this.closeSocketWithoutEOS=!t,this.deviceChangeHandler&&(navigator.mediaDevices.removeEventListener("devicechange",this.deviceChangeHandler),this.deviceChangeHandler=null),(u=null===(i=this.audioStream)||void 0===i||null===(r=i.getAudioTracks)||void 0===r?void 0:r.call(i)[0])&&this.trackEndedHandler&&u.removeEventListener("ended",this.trackEndedHandler),this.trackEndedHandler=null,null===(o=this.audioStream)||void 0===o||null===(s=o.getTracks)||void 0===s||null===(s=s.call(o))||void 0===s||s.forEach(function(e){try{e.stop()}catch(e){}}),null===(a=this.processorNode)||void 0===a||null===(a=a.port)||void 0===a||a.postMessage("STOP");case 14:case"end":return e.stop()}},e,this)})),function(e){return T.apply(this,arguments)})},{key:"recoverAudioGraph",value:(P=g(h().mark(function e(){var t,n,i,r=this;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isRecovering){e.next=2;break}return e.abrupt("return");case 2:this.isRecovering=!0,e.prev=3,null===(t=this.audioStream)||void 0===t||null===(t=t.getTracks())||void 0===t||t.forEach(function(e){try{e.stop()}catch(e){}});try{null===(n=this.source)||void 0===n||n.disconnect()}catch(e){}try{null===(i=this.processorNode)||void 0===i||i.disconnect()}catch(e){}return e.next=9,this.createMediaStreamSourceNode();case 9:if(this.source){e.next=11;break}throw new Error("Failed to recreate source");case 11:if(this.audioContext&&"closed"!==this.audioContext.state||(this.audioContext=new AudioContext),"suspended"!==this.audioContext.state){e.next=15;break}return e.next=15,this.audioContext.resume();case 15:return e.next=17,this.createProcessorNode();case 17:if(this.source.connect(this.processorNode).connect(this.audioContext.destination),this.isStreaming&&!this.isPaused){e.next=22;break}if("running"!==this.audioContext.state){e.next=22;break}return e.next=22,this.audioContext.suspend();case 22:this.micNeedsRecovery=!1,this.isPaused&&!this.IsMicrophoneMuted&&this.onMicReady&&!this._micReadyFired&&(this._micReadyFired=!0,setTimeout(function(){r._micReadyFired=!1},300),this.onMicReady()),e.next=29;break;case 26:e.prev=26,e.t0=e.catch(3),console.error("Recovery failed",e.t0);case 29:return e.prev=29,this.isRecovering=!1,e.finish(29);case 32:case"end":return e.stop()}},e,this,[[3,26,29,32]])})),function(){return P.apply(this,arguments)})},{key:"IntentStartStream",value:function(){this.executor.Send("INTENT_START_STREAM")}},{key:"cleanup",value:function(){var e;null===(e=this.audioStream)||void 0===e||null===(e=e.getTracks())||void 0===e||e.forEach(function(e){try{e.stop()}catch(e){}}),this.source.disconnect(),this.processorNode.disconnect(),this.processorNode.port.close(),this.audioContext.close(),this.audioData=[]}},{key:"saveAudio",value:function(){var e=this.encodeWAV(),t=URL.createObjectURL(new Blob([e],{type:"audio/wav"}));this.log("Download Recording: ".concat(t))}},{key:"getBlob",value:function(){var e=this.encodeWAV();return new Blob([e],{type:"audio/wav"})}},{key:"encodeWAV",value:function(){var e=new DataView(new ArrayBuffer(2*this.audioData.length));this.audioData.forEach(function(t,n){e.setInt16(2*n,t,!0)});var t=e.buffer.byteLength,n=44+t,i=new DataView(new ArrayBuffer(n));i.setUint32(0,1380533830,!1),i.setUint32(4,n-8,!0),i.setUint32(8,1463899717,!1),i.setUint32(12,1718449184,!1),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,1,!0),i.setUint32(24,16e3,!0),i.setUint32(28,32e3,!0),i.setUint16(32,2,!0),i.setUint16(34,16,!0),i.setUint32(36,1684108385,!1),i.setUint32(40,t,!0);for(var r=0;r<t;r++)i.setInt8(44+r,e.getInt8(r));return i}},{key:"log",value:function(e){if(this.enableLogs){var t="".concat((new Date).toLocaleTimeString()," Augnito: ").concat(e);console.log(t+"\n")}}}]);function K(e){return j.apply(this,arguments)}function j(){return j=g(h().mark(function e(t){var n,i,r,o,s,a,c,u,l,d=arguments;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=d.length>1&&void 0!==d[1]?d[1]:350,i=d.length>2&&void 0!==d[2]?d[2]:.01,r=null,o=null,e.prev=4,e.next=7,navigator.mediaDevices.getUserMedia({audio:{deviceId:{exact:t},channelCount:1}});case 7:return r=e.sent,o=new AudioContext,s=o.createMediaStreamSource(r),(a=o.createAnalyser()).fftSize=256,s.connect(a),c=a.frequencyBinCount,u=new Float32Array(c),e.next=17,new Promise(function(e){var t=0,r=performance.now();requestAnimationFrame(function o(){a.getFloatTimeDomainData(u);for(var s=0,l=0;l<c;l++)s+=u[l]*u[l];var d=Math.sqrt(s/c);d>t&&(t=d),performance.now()-r<n?requestAnimationFrame(o):e(t>i)})});case 17:return e.abrupt("return",e.sent);case 20:return e.prev=20,e.t0=e.catch(4),e.abrupt("return",!1);case 23:return e.prev=23,null===(l=r)||void 0===l||l.getTracks().forEach(function(e){return e.stop()}),o&&"closed"!==o.state&&o.close().catch(function(){}),e.finish(23);case 27:case"end":return e.stop()}},e,null,[[4,20,23,27]])})),j.apply(this,arguments)}function W(e){return G.apply(this,arguments)}function G(){return(G=g(h().mark(function e(t){var n,i,r,o,s;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=1,e.next=4,navigator.mediaDevices.enumerateDevices();case 4:n=e.sent,e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(1),e.abrupt("return",null);case 10:i=n.filter(function(e){return"audioinput"===e.kind&&e.deviceId!==t}),r=S(i),e.prev=12,r.s();case 14:if((o=r.n()).done){e.next=23;break}return s=o.value,e.next=18,K(s.deviceId);case 18:if(!e.sent){e.next=21;break}return e.abrupt("return",s.deviceId);case 21:e.next=14;break;case 23:e.next=28;break;case 25:e.prev=25,e.t1=e.catch(12),r.e(e.t1);case 28:return e.prev=28,r.f(),e.finish(28);case 31:return e.abrupt("return",null);case 32:case"end":return e.stop()}},e,null,[[1,7],[12,25,28,31]])}))).apply(this,arguments)}var F=function(){function e(){var t,n,i,r,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{serverURL:"",enableLogs:!1,isDebug:!1,bufferInterval:1,pausedBufferInterval:1,EOS_Message:void 0,socketTimeoutInterval:void 0,shouldSendAudioDataSequence:!1,reconnectAudioDuration:0,shouldPreIntialiseRecorder:!1,shouldReadIntensity:!1,debounceDelay:300,switchToRegularSpeechProfile:!1,echoCancellation:void 0,noiseSuppression:void 0,autoGainControl:void 0},s=arguments.length>1?arguments[1]:void 0;if(v(this,e),e.instance)return e.instance;this.WebsocketURL=null!==(t=o.serverURL)&&void 0!==t?t:"",this.enableLogs=o.enableLogs,this.isDebug=o.isDebug,this.streamer=null,this.streamerNotStarted=!1,this.isStreamerStarting=!1,this.pendingStartStream=!1,this.heavyOp=s,this.bufferInterval=o.bufferInterval,this.pausedBufferInterval=o.pausedBufferInterval,this.eosMessage=o.EOS_Message,this.socketTimeoutInterval=o.socketTimeoutInterval,this.shouldSendAudioDataSequence=o.shouldSendAudioDataSequence,this.reconnectAudioDuration=null!==(n=o.reconnectAudioDuration)&&void 0!==n?n:0,this.shouldPreIntialiseRecorder=o.shouldPreIntialiseRecorder,this.switchToRegularSpeechProfile=null!==(i=o.switchToRegularSpeechProfile)&&void 0!==i&&i,this._echoCancellation=o.echoCancellation,this._noiseSuppression=o.noiseSuppression,this._autoGainControl=o.autoGainControl,this.shouldPreIntialiseRecorder&&(this.initialiseStreamer(),this.streamerNotStarted=!0),this.shouldReadIntensity=o.shouldReadIntensity,this.delay=null!==(r=o.debounceDelay)&&void 0!==r?r:300,this.toggleStartStopAudioStream=B(this.toggleStartStopAudioStream.bind(this),this.delay),this.togglePauseResumeAudioStream=B(this.togglePauseResumeAudioStream.bind(this),this.delay),this.needsDispose=!1,e.instance=this}return m(e,[{key:"echoCancellation",get:function(){return this._echoCancellation},set:function(e){this._echoCancellation=e,this.streamer&&(this.streamer.echoCancellation=e)}},{key:"noiseSuppression",get:function(){return this._noiseSuppression},set:function(e){this._noiseSuppression=e,this.streamer&&(this.streamer.noiseSuppression=e)}},{key:"autoGainControl",get:function(){return this._autoGainControl},set:function(e){this._autoGainControl=e,this.streamer&&(this.streamer.autoGainControl=e)}},{key:"initialiseStreamer",value:function(){this.streamer=new J(this.WebsocketURL,this.enableLogs,this.isDebug,this.bufferInterval,this.pausedBufferInterval,this.eosMessage,this.socketTimeoutInterval,this.shouldSendAudioDataSequence,this.reconnectAudioDuration,this.shouldPreIntialiseRecorder,this.shouldReadIntensity,this.switchToRegularSpeechProfile,this._echoCancellation,this._noiseSuppression,this._autoGainControl,this.heavyOp,this.onFinalResultCallback.bind(this),this.onPartialResultCallback.bind(this),this.onErrorCallback.bind(this),this.onStateChangedCallback.bind(this),this.onSessionEventCallback.bind(this),this.onOtherResultCallback.bind(this),this.onSpeechResponseCallback.bind(this),this.onIntensityCallback.bind(this),this.onJobStatusCallback.bind(this),this.onMicReadyCallback.bind(this))}},{key:"updateIntentStartStream",value:function(){var e;this.pendingStartStream=!0,null===(e=this.streamer)||void 0===e||e.IntentStartStream()}},{key:"togglePauseResumeAudioStream",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;!this.streamer||this.streamerNotStarted?(t&&(this.WebsocketURL=t),this.startAudio(e)):this.streamer.IsPaused?this.resumeAudio():this.pauseAudio()}},{key:"toggleStartStopAudioStream",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;!this.streamer||this.streamerNotStarted?(t&&(this.WebsocketURL=t),this.startAudio(e)):this.stopAudio()}},{key:"startAudio",value:(t=g(h().mark(function e(t){return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isStreamerStarting){e.next=2;break}return e.abrupt("return");case 2:return this.isStreamerStarting=!0,this.shouldPreIntialiseRecorder&&this.streamer||this.initialiseStreamer(),e.prev=4,e.next=7,this.streamer.StartStream(t,this.WebsocketURL);case 7:e.sent?(this.streamerNotStarted=!1,this.log("Stream Started...")):this.streamer=null;case 9:return e.prev=9,this.isStreamerStarting=!1,e.finish(9);case 12:case"end":return e.stop()}},e,this,[[4,,9,12]])})),function(e){return t.apply(this,arguments)})},{key:"pauseAudio",value:function(){this.streamer.PauseStream(),this.log("Stream Paused...")}},{key:"resumeAudio",value:function(){this.streamer.ResumeStream(),this.enableLogs&&this.log("Stream Resumed...")}},{key:"stopAudio",value:function(){var e,t,n=this,i=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];(null!==(e=this.streamer)&&void 0!==e&&e.IsStreaming||r)&&(null===(t=this.streamer)||void 0===t||t.StopStream(i),this.streamer=null,this.log("Stream Stopped..."),this.shouldPreIntialiseRecorder&&setTimeout(function(){n.needsDispose?n.needsDispose=!1:(n.initialiseStreamer(),n.streamerNotStarted=!0)},500))}},{key:"getBlob",value:function(){var e=this.streamer.getBlob();return this.log("Blob Sent..."),e}},{key:"log",value:function(e){if(this.enableLogs){var t="".concat((new Date).toLocaleTimeString()," Augnito: ").concat(e);this.showLogCallback(t+"\n")}}},{key:"dispose",value:function(){var t;this.needsDispose=!0,null===(t=this.streamer)||void 0===t||t.StopStream(!1),this.streamer=null,e.instance=null}},{key:"onSessionEventCallback",value:function(e){this.onSessionEvent&&this.onSessionEvent(e)}},{key:"onStateChangedCallback",value:function(e){this.onStateChanged&&this.onStateChanged(e)}},{key:"onIntensityCallback",value:function(e){this.onIntensity&&this.onIntensity(e)}},{key:"onErrorCallback",value:function(e){this.onError&&this.onError(e)}},{key:"onPartialResultCallback",value:function(e){this.onPartialResult&&this.onPartialResult(e)}},{key:"onFinalResultCallback",value:function(e){this.onFinalResult&&this.onFinalResult(e)}},{key:"onOtherResultCallback",value:function(e){this.onOtherResults&&this.onOtherResults(e)}},{key:"onSpeechResponseCallback",value:function(e){this.onSpeechResponse&&this.onSpeechResponse(e)}},{key:"onJobStatusCallback",value:function(e){this.onJobStatus&&this.onJobStatus(e)}},{key:"onMicReadyCallback",value:function(){this.onMicReady&&this.onMicReady()}},{key:"showLogCallback",value:function(e){this.showLog&&this.showLog(e)}}]);var t}();function B(e,t){var n;return function(){for(var i=this,r=arguments.length,o=new Array(r),s=0;s<r;s++)o[s]=arguments[s];n&&clearTimeout(n),n=setTimeout(function(){return e.apply(i,o)},t)}}class V extends u{constructor(e){super(),Object.defineProperty(this,"_config",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_baseUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._baseUrl=`https://${e.server}/pace/v1/sdk`}getURL(e){return`${this._baseUrl}${e}`}getNoteParams(){return e(this,void 0,void 0,function*(){const e=this.getURL("/noteparams"),t={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag};return yield this.makePostRequest(e,t)})}getSettingsConfigMaster(t){return e(this,void 0,void 0,function*(){const e=this.getURL("/configmaster"),n={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,ConfigTypeId:t};return yield this.makePostRequest(e,n)})}getOrgConfigMapping(t){return e(this,void 0,void 0,function*(){const e=this.getURL("/configmapping").replace("/v1","/v2"),n={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,ConfigTypeId:t};return yield this.makePostRequest(e,n)})}getUserConfigSettings(t){return e(this,void 0,void 0,function*(){const e=this.getURL("/userconfigmapping"),n={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,ConfigTypeId:t};return yield this.makePostRequest(e,n)})}updateUserConfig(t){return e(this,void 0,void 0,function*(){const e=this.getURL("/userconfigmapping"),n={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,UserConfigMapping:t};return yield this.makePatchRequest(e,n)})}getUserPreferences(){return e(this,void 0,void 0,function*(){const e=this.getURL("/getuserpreferences"),t={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag};return yield this.makePostRequest(e,t)})}updateUserPreference(t,n,i,r,o,s){return e(this,void 0,void 0,function*(){const e=this.getURL("/postuserpreferences"),a={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,UserPreferences:{AutomaticallyGenerateTranscript:t,PreferredTranscriptionLanguage:n,HighlightMedicalTerms:i,DisplayPatientContext:r,NoteOutputStyle:o,NoteOutputVerbosity:s}};return yield this.makePostRequest(e,a)})}}const H="Invalid user details, please check again",q="Subscription is not valid.",z="invalid request. Please make sure AccessKey, SubscriptionCode and UserTag is sent along with the request",$="Active seat is not available for user",Y="Unable to fetch account details, please try again.",Q="Unable to fetch job details, please try again.",X="Job not reconnectable",Z="Timeout exceeded",ee="Rate Limit Exceeded, Please try again in sometime!",te="Audio Signal is power very LOW, Mic might be muted",ne="Job Id is empty",ie="Page Size is undefined",re="Note Data is empty",oe="Job Name is empty",se="Patient Context is empty",ae="Mic permission denied",ce="Microphone is muted",ue="Audio track ended. Possibly the mic was unplugged",le="Internet is not available. Try again later.",de="Feedback is not enabled. Please contact administrator for more details.",he="Automatic Transcription is not enabled for the organisation",fe="Resume job is not enabled for the organisation";class pe{static isBrowserOnline(){return"undefined"!=typeof navigator&&!0===navigator.onLine}static isValidHttpUrl(e){if("string"!=typeof e||e.length>2048)return!1;try{const t=new URL(e);return("http:"===t.protocol||"https:"===t.protocol)&&(!t.username&&!t.password)}catch(e){return!1}}static hasInternetConnection(){return e(this,arguments,void 0,function*(e={url:null,timeoutMs:null}){var t=e.url||pe.DEFAULT_URL;const n=e.timeoutMs||pe.DEFAULT_TIMEOUT;if(!pe.isBrowserOnline())return!1;pe.isValidHttpUrl(t)||(t=pe.DEFAULT_URL);const i=new AbortController,r=setTimeout(()=>i.abort(),n);try{return yield fetch(t,{method:"HEAD",mode:"no-cors",cache:"no-cache",signal:i.signal}),!0}catch(e){return!1}finally{clearTimeout(r)}})}static isOnline(t){return e(this,void 0,void 0,function*(){return pe.hasInternetConnection(t)})}}Object.defineProperty(pe,"DEFAULT_URL",{enumerable:!0,configurable:!0,writable:!0,value:"https://www.google.com/favicon.ico"}),Object.defineProperty(pe,"DEFAULT_TIMEOUT",{enumerable:!0,configurable:!0,writable:!0,value:5e3});class ge{constructor(e){Object.defineProperty(this,"_logTag",{enumerable:!0,configurable:!0,writable:!0,value:"Augnito-Ambient"}),Object.defineProperty(this,"_ambientRestAPI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ambientPaceAPI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"enableLog",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shouldReadAudioIntensity",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"recorderIns",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"forceStopAudio",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_isRecording",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"echoCancellation",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"noiseSuppression",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"autoGainControl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onJobCreated",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onStateChanged",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onError",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onOtherResult",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onIntensityValue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onIdleMic",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onSoapNoteGenerated",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onTranscriptGenerated",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onCodesGenerated",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onJobStatus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onMicRecoveredAfterUnplugged",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._ambientRestAPI=new l(this.validateConfig(e)),this._ambientPaceAPI=new V(e),this.config=this.createSocketConfig(e),this.enableLog=e.enableLogs,this.shouldReadAudioIntensity=e.shouldReadAudioIntensity,this.echoCancellation=e.echoCancellation,this.noiseSuppression=e.noiseSuppression,this.autoGainControl=e.autoGainControl}initRecorder(e){var t,n,i,r,o;this.recorderIns=new F({serverURL:e,enableLogs:null!==(t=this.enableLog)&&void 0!==t&&t,isDebug:null!==(n=this.enableLog)&&void 0!==n&&n,bufferInterval:15,EOS_Message:'{"JobAction": "EOS","Status": 0,"Type": "meta"}',socketTimeoutInterval:2e4,shouldSendAudioDataSequence:!0,shouldReadIntensity:this.shouldReadAudioIntensity,echoCancellation:this.echoCancellation,noiseSuppression:this.noiseSuppression,autoGainControl:this.autoGainControl}),this.recorderIns.echoCancellation=null!==(i=this.echoCancellation)&&void 0!==i&&i,this.recorderIns.noiseSuppression=null!==(r=this.noiseSuppression)&&void 0!==r&&r,this.recorderIns.autoGainControl=null!==(o=this.autoGainControl)&&void 0!==o&&o,this.recorderIns.onError=this.onErrorCallback.bind(this),this.recorderIns.onStateChanged=this.onStateChangeCallback.bind(this),this.recorderIns.onSessionEvent=this.onSessionEventCallback.bind(this),this.recorderIns.onOtherResults=this.onOtherResultsCallback.bind(this),this.recorderIns.onIntensity=this.onIntensityCallback.bind(this),this.recorderIns.onSpeechResponse=this.onSpeechResponseCallback.bind(this),this.recorderIns.onJobStatus=this.onJobStatusEventCallback.bind(this),this.recorderIns.onMicReady=this.onMicRecoveredAfterUnpluggedCallback.bind(this)}getNoteParams(){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientPaceAPI.getNoteParams();if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}getAllNotes(t,n,i){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientRestAPI.ListJobs(t,n,null==i||i);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}getSummarizedNote(t){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientRestAPI.FetchJob(t);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}sendSummarizedNote(t,n){return e(this,void 0,void 0,function*(){try{return this._ambientRestAPI?yield this._ambientRestAPI.SendFinalNote(t,n):void d.error("SDK not initialized",this._logTag)}catch(e){this.handleException(e)}})}toggleListening(t,n,r,o,s,a,c){return e(this,void 0,void 0,function*(){var e,u;if(void 0!==a&&""!==a.trim()){var l=yield this._ambientPaceAPI.getOrgConfigMapping(i.CDIVersion);if((null==l?void 0:l.Items)&&l.Items.length>0&&l.Items[0].Settings)if(!l.Items[0].Settings.find(e=>300===e.ID))return void this.onErrorCallback(fe)}var d=(null===(e=this.config)||void 0===e?void 0:e.prepareWSSURL(t,n,r,o,a,c))||"";this.recorderIns||this.initRecorder(d),null===(u=this.recorderIns)||void 0===u||u.toggleStartStopAudioStream(s,d)})}togglePauseResumeListening(t,n,r,o,s,a,c){return e(this,void 0,void 0,function*(){var e,u;if(void 0!==a&&""!==a.trim()){var l=yield this._ambientPaceAPI.getOrgConfigMapping(i.CDIVersion);if((null==l?void 0:l.Items)&&l.Items.length>0&&l.Items[0].Settings)if(!l.Items[0].Settings.find(e=>300===e.ID))return void this.onErrorCallback(fe)}var d=(null===(e=this.config)||void 0===e?void 0:e.prepareWSSURL(t,n,r,o,a,c))||"";this.recorderIns||this.initRecorder(d),null===(u=this.recorderIns)||void 0===u||u.togglePauseResumeAudioStream(s,d)})}startListening(){var e;null===(e=this.recorderIns)||void 0===e||e.startAudio()}stopListening(){var e;null===(e=this.recorderIns)||void 0===e||e.stopAudio(!0,!0)}deleteNotes(t,n){return e(this,void 0,void 0,function*(){var e;try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var i=yield this._ambientRestAPI.DeleteNotes(t,n);if(i){if(200===i.Status)return null===(e=this.recorderIns)||void 0===e||e.stopAudio(!1,!0),i;this.onErrorCallback(i.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}renameNoteTitle(t,n){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientRestAPI.RenameNoteTitle(t,n);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}getNotePDF(t,n,i,r,o,s){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientRestAPI.DownloadNotePDF(t,n,i,r,o,s);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}endPausedJob(t){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientRestAPI.EndJob(t);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}generateCDISuggestions(t,n,r,o,s){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=1,a=yield this._ambientPaceAPI.getOrgConfigMapping(i.CDIVersion);if((null==a?void 0:a.Items)&&a.Items.length>0&&a.Items[0].Settings){var c=a.Items[0].Settings.find(e=>209===e.ID);c&&(e=Number.parseInt(c.ConfigValue))}var u=yield this._ambientRestAPI.GenerateSuggestions(t,n,r,s,o,e);if(u){if(200===u.Status)return u;this.onErrorCallback(u.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}updatePatientContext(t,n,i){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientRestAPI.UpdatePatientContext(t,n,i);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}modifyGeneratedNote(t,n,i){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientRestAPI.ModifyGeneratedNote(t,n,i);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}fetchTranscriptionForNote(t){return e(this,void 0,void 0,function*(){try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);if((yield this._ambientPaceAPI.getUserPreferences()).Items[0].AutomaticTranscriptionEnabledForOrg){var e=yield this._ambientRestAPI.FetchTranscription(t);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}else this.onErrorCallback(he)}catch(e){this.handleException(e)}})}sendFeedback(t,n,i,r){return e(this,void 0,void 0,function*(){var e,o;try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var s=yield this._ambientPaceAPI.getUserPreferences();if((null===(e=s.Items[0])||void 0===e?void 0:e.FeedbackEnabledForOrg)&&(null===(o=s.Items[0])||void 0===o?void 0:o.FeedbackEnabled)){var a=yield this._ambientRestAPI.SendFeedback(t,n,null!=i?i:"",null!=r?r:"SOAPFeedBack");if(a){if(200===a.Status)return a;this.onErrorCallback(a.ServerMessage)}else this.onErrorCallback("Unknown Error!")}else this.onErrorCallback(de)}catch(e){this.handleException(e)}})}getUserConfiguration(t){return e(this,void 0,void 0,function*(){try{if(!this._ambientPaceAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientPaceAPI.getUserConfigSettings(t);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}updateUserConfiguration(t){return e(this,void 0,void 0,function*(){try{if(!this._ambientPaceAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientPaceAPI.updateUserConfig(t);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}getUserPreferenceSettings(){return e(this,void 0,void 0,function*(){try{if(!this._ambientPaceAPI)return void d.error("SDK not initialized",this._logTag);var e=yield this._ambientPaceAPI.getUserPreferences();if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}updateUserPreferenceSettings(t){return e(this,void 0,void 0,function*(){var e,n,i,r,o,c;try{if(!this._ambientPaceAPI)return void d.error("SDK not initialized",this._logTag);var u=yield this._ambientPaceAPI.updateUserPreference(null!==(e=t.AutomaticallyGenerateTranscript)&&void 0!==e&&e,null!==(n=t.PreferredTranscriptionLanguage)&&void 0!==n?n:"English",null!==(i=t.HighlightMedicalTerms)&&void 0!==i&&i,null!==(r=t.DisplayPatientContext)&&void 0!==r&&r,null!==(o=t.NoteOutputStyle)&&void 0!==o?o:a.DashFormat,null!==(c=t.NoteOutputVerbosity)&&void 0!==c?c:s.Detailed);if(u){if(200===u.Status)return u;this.onErrorCallback(u.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}isInternetAvailable(t){return e(this,void 0,void 0,function*(){const e=yield pe.isOnline(t);return e||this.onErrorCallback(le),e})}onEventCallback(e){this.onJobCreated&&this.onJobCreated(e)}onStateChangeCallback(e){var t;if(this.forceStopAudio)return null===(t=this.recorderIns)||void 0===t||t.stopAudio(!1,!0),void(this.forceStopAudio=!1);this._isRecording=e,this.onStateChanged&&this.onStateChanged(e)}handleException(e){if(e instanceof TypeError)this.onErrorCallback(e.message);else{if(e instanceof c)throw e;d.error(e.message,this._logTag)}}onErrorCallback(e,t){var n,i,r,s,a,c,u,l,h,f,p,g,v,b,m,y,S={ErrorCode:null!=t?t:o.ERRUNKNOWN,ErrorMessage:e};try{var C=JSON.parse(e);S.ErrorMessage=C.Data,C.Data===Z?(this.stopListening(),d.error("Recording time limit exceeded",this._logTag),S.ErrorCode=o.WSJOB05):C.Data===H?(this._isRecording?null===(n=this.recorderIns)||void 0===n||n.stopAudio(!1,!0):this.forceStopAudio=!0,S.ErrorCode=o.WSAUTH03):C.Data.includes(Y)?S.ErrorCode=o.WSAUTH04:C.Data.includes(Q)?S.ErrorCode=o.WSJOB01:C.Data.includes(X)?S.ErrorCode=o.WSJOB02:C.Data.includes(ee)?S.ErrorCode=o.WSACC01:C.Data.includes(te)&&(S.ErrorCode=o.WSAUD01)}catch(e){}(null===(i=S.ErrorMessage)||void 0===i?void 0:i.includes(ne))?S.ErrorCode=o.SDK01:(null===(r=S.ErrorMessage)||void 0===r?void 0:r.includes(ie))?S.ErrorCode=o.SDK02:(null===(s=S.ErrorMessage)||void 0===s?void 0:s.includes(re))?S.ErrorCode=o.SDK03:(null===(a=S.ErrorMessage)||void 0===a?void 0:a.includes(oe))?S.ErrorCode=o.SDK04:(null===(c=S.ErrorMessage)||void 0===c?void 0:c.includes(se))?S.ErrorCode=o.SDK05:(null===(u=S.ErrorMessage)||void 0===u?void 0:u.includes(ae))?S.ErrorCode=o.SDK06:(null===(l=S.ErrorMessage)||void 0===l?void 0:l.includes(ce))?S.ErrorCode=o.SDK07:(null===(h=S.ErrorMessage)||void 0===h?void 0:h.includes(ue))?S.ErrorCode=o.SDK08:(null===(f=S.ErrorMessage)||void 0===f?void 0:f.includes(q))||(null===(p=S.ErrorMessage)||void 0===p?void 0:p.includes(z))?S.ErrorCode=o.AUTH01:(null===(g=S.ErrorMessage)||void 0===g?void 0:g.includes($))?S.ErrorCode=o.AUTH02:(null===(v=S.ErrorMessage)||void 0===v?void 0:v.includes(le))?S.ErrorCode=o.SDK12:(null===(b=S.ErrorMessage)||void 0===b?void 0:b.includes(he))?S.ErrorCode=o.SDK13:(null===(m=S.ErrorMessage)||void 0===m?void 0:m.includes(de))?S.ErrorCode=o.SDK14:(null===(y=S.ErrorMessage)||void 0===y?void 0:y.includes(fe))&&(S.ErrorCode=o.SDK15),this.onError&&this.onError(S)}onOtherResultsCallback(e){this.onOtherResult&&this.onOtherResult(e)}onIntensityCallback(e){this.onIntensityValue&&this.onIntensityValue(e)}onIdleMicCallback(){this.onIdleMic&&this.onIdleMic()}onSpeechResponseCallback(e){var t=JSON.parse(e);"note"===t.Type.toLowerCase()&&this.onSoapNoteGenerated?this.onSoapNoteGenerated(t.Data):"transcript"===t.Type.toLowerCase()&&this.onTranscriptGenerated?this.onTranscriptGenerated(t.Data):"codes"===t.Type.toLowerCase()&&this.onCodesGenerated&&this.onCodesGenerated(t.Data)}onJobStatusEventCallback(e){this.onJobStatus&&this.onJobStatus(e)}onMicRecoveredAfterUnpluggedCallback(){this.onMicRecoveredAfterUnplugged&&this.onMicRecoveredAfterUnplugged()}onSessionEventCallback(e){var t;if(!e)return;let n;try{n="string"==typeof e?JSON.parse(e):e}catch(e){return void d.error(`Error parsing session event data: ${e}`,this._logTag)}if(!n||!("Type"in n))return;if("meta"===n.Type.toLowerCase()&&(null===(t=this.config)||void 0===t?void 0:t.onMetaEvent)){if(!n.JobID)return void d.error("JobID is missing in meta event",this._logTag);this.config.onMetaEvent(n.JobID)}else"error"===n.Type.toLowerCase()&&n.Data&&this.onErrorCallback(n.Data);if("object"!=typeof n.Event||null===n.Event)return;const{Type:i,Value:r}=n.Event;i&&("SESSION_CREATED"===i&&r?d.log(`session Token ${r}`,this._logTag):"SERVICE_DOWN"===i?d.error(i,this._logTag):"NO_DICTATION_STOP_MIC"===i?(d.log("NO_DICTATION_STOP_MIC",this._logTag),this.onIdleMicCallback()):"INVALID_AUTH_CREDENTIALS"===i?d.error("INVALID_AUTH_CREDENTIALS",this._logTag):"LOW_BANDWIDTH"===i&&d.log("LOW_BANDWIDTH: Check internet connection",this._logTag))}validateConfig(e){return n.Against.NullOrEmpty(e.server,"Server"),n.Against.NullOrEmpty(e.subscriptionCode,"SubscriptionCode"),n.Against.NullOrEmpty(e.accessKey,"AccessKey"),n.Against.NullOrEmpty(e.userTag,"UserTag"),e}createSocketConfig(e){const n=new t(e);return n.onError=this.onErrorCallback.bind(this),n.onMetaEvent=this.onEventCallback.bind(this),n}}export{ge as AugnitoAmbient,o as ErrorCodes,c as HttpCodedError,a as NoteOutputStyleConfig,r as NoteTypeConfig,s as NoteVerbosityConfig,i as SettingsConfigType};
1
+ function e(e, t, i, n) {
2
+ return new (i || (i = Promise))(function (r, o) {
3
+ function s(e) {
4
+ try {
5
+ c(n.next(e));
6
+ } catch (e) {
7
+ o(e);
8
+ }
9
+ }
10
+ function a(e) {
11
+ try {
12
+ c(n.throw(e));
13
+ } catch (e) {
14
+ o(e);
15
+ }
16
+ }
17
+ function c(e) {
18
+ var t;
19
+ e.done
20
+ ? r(e.value)
21
+ : ((t = e.value),
22
+ t instanceof i
23
+ ? t
24
+ : new i(function (e) {
25
+ e(t);
26
+ })).then(s, a);
27
+ }
28
+ c((n = n.apply(e, t || [])).next());
29
+ });
30
+ }
31
+ "function" == typeof SuppressedError && SuppressedError;
32
+ class t {
33
+ constructor(e) {
34
+ Object.defineProperty(this, "_config", {
35
+ enumerable: !0,
36
+ configurable: !0,
37
+ writable: !0,
38
+ value: e,
39
+ }),
40
+ Object.defineProperty(this, "wssBaseURL", {
41
+ enumerable: !0,
42
+ configurable: !0,
43
+ writable: !0,
44
+ value: void 0,
45
+ }),
46
+ Object.defineProperty(this, "onError", {
47
+ enumerable: !0,
48
+ configurable: !0,
49
+ writable: !0,
50
+ value: void 0,
51
+ }),
52
+ Object.defineProperty(this, "onMetaEvent", {
53
+ enumerable: !0,
54
+ configurable: !0,
55
+ writable: !0,
56
+ value: void 0,
57
+ }),
58
+ (this.wssBaseURL = `wss://${e.server}/ambient/v1/stream-job`);
59
+ }
60
+ prepareWSSURL(e, t, i, n, r, o) {
61
+ let s = this.wssBaseURL;
62
+ return (
63
+ (s += `?filetype=${e}`),
64
+ (s += `&noteparams=${t}`),
65
+ (s += `&subscriptioncode=${this._config.subscriptionCode}`),
66
+ (s += `&accesskey=${this._config.accessKey}`),
67
+ (s += `&usertag=${this._config.userTag}`),
68
+ i && "" !== i && (s += `&filename=${i}`),
69
+ n && "" !== n && (s += `&jobid=${n}`),
70
+ r && "" !== r && (s += `&parentjobid=${r}`),
71
+ void 0 !== o && (s += `&inheritparentconfig=${o}`),
72
+ s
73
+ );
74
+ }
75
+ }
76
+ class i {
77
+ constructor() {}
78
+ static get Against() {
79
+ return i.instance || (i.instance = new i()), i.instance;
80
+ }
81
+ NullOrUndefined(e, t) {
82
+ if (null === e) throw new TypeError(`${t} is null`);
83
+ if (void 0 === e) throw new TypeError(`${t} is undefined`);
84
+ return e;
85
+ }
86
+ NullOrEmpty(e, t) {
87
+ if (!(e = i.Against.NullOrUndefined(e, t)))
88
+ throw new TypeError(`${t} is empty`);
89
+ return e;
90
+ }
91
+ }
92
+ var n, r, o, s, a;
93
+ !(function (e) {
94
+ (e[(e.SPECIALITY = 1)] = "SPECIALITY"),
95
+ (e[(e.VISIT_TYPE = 2)] = "VISIT_TYPE"),
96
+ (e[(e.NOTE_TYPE = 3)] = "NOTE_TYPE"),
97
+ (e[(e.CLINICAL_CODE = 4)] = "CLINICAL_CODE"),
98
+ (e[(e.LANGUAGE = 5)] = "LANGUAGE"),
99
+ (e[(e.CDIVersion = 7)] = "CDIVersion");
100
+ })(n || (n = {})),
101
+ (function (e) {
102
+ (e[(e.SoapNote = 1)] = "SoapNote"),
103
+ (e[(e.PatientNote = 2)] = "PatientNote"),
104
+ (e[(e.ReferralNote = 3)] = "ReferralNote"),
105
+ (e[(e.ConsultationSummary = 4)] = "ConsultationSummary"),
106
+ (e[(e.CDISuggestions = 102)] = "CDISuggestions");
107
+ })(r || (r = {})),
108
+ (function (e) {
109
+ (e.AUTH01 = "AUTH01"),
110
+ (e.AUTH02 = "AUTH02"),
111
+ (e.WSAUTH01 = "WSAUTH01"),
112
+ (e.WSAUTH02 = "WSAUTH02"),
113
+ (e.WSAUTH03 = "WSAUTH03"),
114
+ (e.WSAUTH04 = "WSAUTH04"),
115
+ (e.WSJOB01 = "WSJOB01"),
116
+ (e.WSJOB02 = "WSJOB02"),
117
+ (e.WSJOB03 = "WSJOB03"),
118
+ (e.WSJOB04 = "WSJOB04"),
119
+ (e.WSJOB05 = "WSJOB05"),
120
+ (e.WSACC01 = "WSACC01"),
121
+ (e.WSAUD01 = "WSAUD01"),
122
+ (e.SDK01 = "SDK01"),
123
+ (e.SDK02 = "SDK02"),
124
+ (e.SDK03 = "SDK03"),
125
+ (e.SDK04 = "SDK04"),
126
+ (e.SDK05 = "SDK05"),
127
+ (e.SDK06 = "SDK06"),
128
+ (e.SDK07 = "SDK07"),
129
+ (e.SDK08 = "SDK08"),
130
+ (e.SDK12 = "SDK12"),
131
+ (e.SDK13 = "SDK13"),
132
+ (e.SDK14 = "SDK14"),
133
+ (e.SDK15 = "SDK15"),
134
+ (e.ERRUNKNOWN = "ERRUNKNOWN");
135
+ })(o || (o = {}));
136
+ class c extends Error {
137
+ constructor(e, t) {
138
+ super(e),
139
+ Object.defineProperty(this, "code", {
140
+ enumerable: !0,
141
+ configurable: !0,
142
+ writable: !0,
143
+ value: void 0,
144
+ }),
145
+ (this.code = t),
146
+ (this.name = "HttpCodedError"),
147
+ Object.setPrototypeOf(this, c.prototype);
148
+ }
149
+ }
150
+ !(function (e) {
151
+ (e.Detailed = "Detailed"), (e.Concise = "Concise");
152
+ })(s || (s = {})),
153
+ (function (e) {
154
+ (e.DashFormat = "Dash-format"), (e.Paragraph = "Paragraph");
155
+ })(a || (a = {}));
156
+ class u {
157
+ makePostRequest(t, i) {
158
+ return e(this, void 0, void 0, function* () {
159
+ try {
160
+ const n = yield fetch(t, {
161
+ method: "POST",
162
+ headers: { "Content-Type": "application/json" },
163
+ body: JSON.stringify(i),
164
+ });
165
+ if (!n.ok) {
166
+ const t = yield n.text();
167
+ var e = JSON.parse(t);
168
+ throw new c(e.message, e.code.toString());
169
+ }
170
+ return yield n.json();
171
+ } catch (e) {
172
+ throw e;
173
+ }
174
+ });
175
+ }
176
+ makePatchRequest(t, i) {
177
+ return e(this, void 0, void 0, function* () {
178
+ try {
179
+ const n = yield fetch(t, {
180
+ method: "PATCH",
181
+ headers: { "Content-Type": "application/json" },
182
+ body: JSON.stringify(i),
183
+ });
184
+ if (!n.ok) {
185
+ const t = yield n.text();
186
+ var e = JSON.parse(t);
187
+ throw new c(e.message, n.status.toString());
188
+ }
189
+ return yield n.json();
190
+ } catch (e) {
191
+ throw e instanceof c
192
+ ? e
193
+ : new c("500", e.message || "Unexpected error");
194
+ }
195
+ });
196
+ }
197
+ }
198
+ class l extends u {
199
+ constructor(e) {
200
+ super(),
201
+ Object.defineProperty(this, "_config", {
202
+ enumerable: !0,
203
+ configurable: !0,
204
+ writable: !0,
205
+ value: e,
206
+ }),
207
+ Object.defineProperty(this, "_baseUrl", {
208
+ enumerable: !0,
209
+ configurable: !0,
210
+ writable: !0,
211
+ value: void 0,
212
+ }),
213
+ (this._baseUrl = `https://${e.server}/ambient/v1`);
214
+ }
215
+ getURL(e) {
216
+ return `${this._baseUrl}${e}`;
217
+ }
218
+ GetNoteParams() {
219
+ return e(this, void 0, void 0, function* () {
220
+ const e = this.getURL("/note-params"),
221
+ t = {
222
+ SubscriptionCode: this._config.subscriptionCode,
223
+ AccessKey: this._config.accessKey,
224
+ UserTag: this._config.userTag,
225
+ };
226
+ return yield this.makePostRequest(e, t);
227
+ });
228
+ }
229
+ ListJobs(t, n, r) {
230
+ return e(this, void 0, void 0, function* () {
231
+ i.Against.NullOrEmpty(t, "Page Size");
232
+ const e = this.getURL("/list-jobs"),
233
+ o = {
234
+ SubscriptionCode: this._config.subscriptionCode,
235
+ AccessKey: this._config.accessKey,
236
+ UserTag: this._config.userTag,
237
+ PageSize: t,
238
+ PageID: n,
239
+ Collapse: r,
240
+ };
241
+ return yield this.makePostRequest(e, o);
242
+ });
243
+ }
244
+ FetchJob(t) {
245
+ return e(this, void 0, void 0, function* () {
246
+ i.Against.NullOrEmpty(t, "Job Id");
247
+ const e = this.getURL("/fetch-job"),
248
+ n = {
249
+ SubscriptionCode: this._config.subscriptionCode,
250
+ AccessKey: this._config.accessKey,
251
+ UserTag: this._config.userTag,
252
+ JobID: t,
253
+ };
254
+ return yield this.makePostRequest(e, n);
255
+ });
256
+ }
257
+ SendFinalNote(t, n) {
258
+ return e(this, void 0, void 0, function* () {
259
+ i.Against.NullOrEmpty(t, "Job Id"), i.Against.NullOrEmpty(n, "Note Data");
260
+ const e = this.getURL("/send-final-note"),
261
+ r = {
262
+ SubscriptionCode: this._config.subscriptionCode,
263
+ AccessKey: this._config.accessKey,
264
+ UserTag: this._config.userTag,
265
+ JobID: t,
266
+ SoapData: n,
267
+ };
268
+ return yield this.makePostRequest(e, r);
269
+ });
270
+ }
271
+ DeleteNotes(t, n) {
272
+ return e(this, void 0, void 0, function* () {
273
+ i.Against.NullOrEmpty(t, "Job Id");
274
+ const e = this.getURL("/delete-job"),
275
+ r = {
276
+ SubscriptionCode: this._config.subscriptionCode,
277
+ AccessKey: this._config.accessKey,
278
+ UserTag: this._config.userTag,
279
+ JobIDs: t,
280
+ DeleteParent: n,
281
+ };
282
+ return yield this.makePostRequest(e, r);
283
+ });
284
+ }
285
+ RenameNoteTitle(t, n) {
286
+ return e(this, void 0, void 0, function* () {
287
+ i.Against.NullOrEmpty(t, "Job Id"), i.Against.NullOrEmpty(n, "Job Name");
288
+ const e = this.getURL("/rename-job"),
289
+ r = {
290
+ SubscriptionCode: this._config.subscriptionCode,
291
+ AccessKey: this._config.accessKey,
292
+ UserTag: this._config.userTag,
293
+ JobID: t,
294
+ JobName: n,
295
+ };
296
+ return yield this.makePostRequest(e, r);
297
+ });
298
+ }
299
+ DownloadNotePDF(t, n, r, o, s, a) {
300
+ return e(this, void 0, void 0, function* () {
301
+ i.Against.NullOrEmpty(t, "Job Id");
302
+ const e = this.getURL("/download-pdf");
303
+ var c = s;
304
+ (c && "" != c) ||
305
+ (c =
306
+ '{"PatientName":"","PatientID":"","Age":"","Gender":"","ReceivingDoctor":"","DoctorName":"","DoctorDesignation":"","DoctorEmail":""}');
307
+ const u = {
308
+ SubscriptionCode: this._config.subscriptionCode,
309
+ AccessKey: this._config.accessKey,
310
+ UserTag: this._config.userTag,
311
+ JobID: t,
312
+ NoteType: n,
313
+ Language: null != o ? o : "English",
314
+ SpecialityID: r,
315
+ Regenerate: null != a && a,
316
+ PersonnelInfo: c,
317
+ };
318
+ return yield this.makePostRequest(e, u);
319
+ });
320
+ }
321
+ EndJob(t) {
322
+ return e(this, void 0, void 0, function* () {
323
+ i.Against.NullOrEmpty(t, "Job Id");
324
+ const e = this.getURL("/end-job"),
325
+ n = {
326
+ SubscriptionCode: this._config.subscriptionCode,
327
+ AccessKey: this._config.accessKey,
328
+ UserTag: this._config.userTag,
329
+ JobID: t,
330
+ };
331
+ return yield this.makePostRequest(e, n);
332
+ });
333
+ }
334
+ UpdatePatientContext(t, n, r) {
335
+ return e(this, void 0, void 0, function* () {
336
+ i.Against.NullOrEmpty(t, "Job Id"),
337
+ i.Against.NullOrEmpty(n, "Patient Context");
338
+ const e = this.getURL("/patient-context"),
339
+ o = {
340
+ SubscriptionCode: this._config.subscriptionCode,
341
+ AccessKey: this._config.accessKey,
342
+ UserTag: this._config.userTag,
343
+ JobID: t,
344
+ NewContext: n,
345
+ Replace: r,
346
+ };
347
+ return yield this.makePostRequest(e, o);
348
+ });
349
+ }
350
+ GenerateSuggestions(t, n, r, o, s, a) {
351
+ return e(this, void 0, void 0, function* () {
352
+ i.Against.NullOrEmpty(t, "Job Id");
353
+ var e = this.getURL("/cdi");
354
+ a && 2 === a && (e = this.getURL("/cdi").replace("/v1", "/v2"));
355
+ const c = {
356
+ SubscriptionCode: this._config.subscriptionCode,
357
+ AccessKey: this._config.accessKey,
358
+ UserTag: this._config.userTag,
359
+ JobID: t,
360
+ Regenerate: n,
361
+ SoapData: r,
362
+ PatientContext: o,
363
+ Codes: s,
364
+ };
365
+ return yield this.makePostRequest(e, c);
366
+ });
367
+ }
368
+ ModifyGeneratedNote(t, n, r) {
369
+ return e(this, void 0, void 0, function* () {
370
+ i.Against.NullOrEmpty(t, "Job Id");
371
+ const e = this.getURL("/modify-note"),
372
+ o = {
373
+ SubscriptionCode: this._config.subscriptionCode,
374
+ AccessKey: this._config.accessKey,
375
+ UserTag: this._config.userTag,
376
+ JobID: t,
377
+ NoteType: n,
378
+ NewNote: null != r ? r : "",
379
+ };
380
+ return yield this.makePostRequest(e, o);
381
+ });
382
+ }
383
+ FetchTranscription(t) {
384
+ return e(this, void 0, void 0, function* () {
385
+ i.Against.NullOrEmpty(t, "Job Id");
386
+ const e = this.getURL("/fetch-transcript"),
387
+ n = {
388
+ SubscriptionCode: this._config.subscriptionCode,
389
+ AccessKey: this._config.accessKey,
390
+ UserTag: this._config.userTag,
391
+ JobID: t,
392
+ };
393
+ return yield this.makePostRequest(e, n);
394
+ });
395
+ }
396
+ SendFeedback(t, n, r, o) {
397
+ return e(this, void 0, void 0, function* () {
398
+ i.Against.NullOrEmpty(t, "Job Id"),
399
+ i.Against.NullOrUndefined(n, "Rating");
400
+ const e = this.getURL("/feedback").replace("/v1", "/v2"),
401
+ s = {
402
+ SubscriptionCode: this._config.subscriptionCode,
403
+ AccessKey: this._config.accessKey,
404
+ UserTag: this._config.userTag,
405
+ JobID: t,
406
+ Rating: n,
407
+ FeedBack: null != r ? r : "",
408
+ Type: null != o ? o : "",
409
+ };
410
+ return yield this.makePostRequest(e, s);
411
+ });
412
+ }
413
+ }
414
+ class d {
415
+ static log(e, t) {
416
+ const i = null != t ? t : this.defaultTag;
417
+ console.log(`${i}:`, e);
418
+ }
419
+ static error(e, t) {
420
+ const i = null != t ? t : this.defaultTag;
421
+ console.error(`${i}:`, e);
422
+ }
423
+ }
424
+ function h() {
425
+ h = function () {
426
+ return t;
427
+ };
428
+ var e,
429
+ t = {},
430
+ i = Object.prototype,
431
+ n = i.hasOwnProperty,
432
+ r =
433
+ Object.defineProperty ||
434
+ function (e, t, i) {
435
+ e[t] = i.value;
436
+ },
437
+ o = "function" == typeof Symbol ? Symbol : {},
438
+ s = o.iterator || "@@iterator",
439
+ a = o.asyncIterator || "@@asyncIterator",
440
+ c = o.toStringTag || "@@toStringTag";
441
+ function u(e, t, i) {
442
+ return (
443
+ Object.defineProperty(e, t, {
444
+ value: i,
445
+ enumerable: !0,
446
+ configurable: !0,
447
+ writable: !0,
448
+ }),
449
+ e[t]
450
+ );
451
+ }
452
+ try {
453
+ u({}, "");
454
+ } catch (e) {
455
+ u = function (e, t, i) {
456
+ return (e[t] = i);
457
+ };
458
+ }
459
+ function l(e, t, i, n) {
460
+ var o = t && t.prototype instanceof m ? t : m,
461
+ s = Object.create(o.prototype),
462
+ a = new _(n || []);
463
+ return r(s, "_invoke", { value: w(e, i, a) }), s;
464
+ }
465
+ function d(e, t, i) {
466
+ try {
467
+ return { type: "normal", arg: e.call(t, i) };
468
+ } catch (e) {
469
+ return { type: "throw", arg: e };
470
+ }
471
+ }
472
+ t.wrap = l;
473
+ var f = "suspendedStart",
474
+ p = "suspendedYield",
475
+ g = "executing",
476
+ v = "completed",
477
+ b = {};
478
+ function m() {}
479
+ function y() {}
480
+ function S() {}
481
+ var C = {};
482
+ u(C, s, function () {
483
+ return this;
484
+ });
485
+ var k = Object.getPrototypeOf,
486
+ E = k && k(k(O([])));
487
+ E && E !== i && n.call(E, s) && (C = E);
488
+ var I = (S.prototype = m.prototype = Object.create(C));
489
+ function A(e) {
490
+ ["next", "throw", "return"].forEach(function (t) {
491
+ u(e, t, function (e) {
492
+ return this._invoke(t, e);
493
+ });
494
+ });
495
+ }
496
+ function R(e, t) {
497
+ function i(r, o, s, a) {
498
+ var c = d(e[r], e, o);
499
+ if ("throw" !== c.type) {
500
+ var u = c.arg,
501
+ l = u.value;
502
+ return l && "object" == typeof l && n.call(l, "__await")
503
+ ? t.resolve(l.__await).then(
504
+ function (e) {
505
+ i("next", e, s, a);
506
+ },
507
+ function (e) {
508
+ i("throw", e, s, a);
509
+ },
510
+ )
511
+ : t.resolve(l).then(
512
+ function (e) {
513
+ (u.value = e), s(u);
514
+ },
515
+ function (e) {
516
+ return i("throw", e, s, a);
517
+ },
518
+ );
519
+ }
520
+ a(c.arg);
521
+ }
522
+ var o;
523
+ r(this, "_invoke", {
524
+ value: function (e, n) {
525
+ function r() {
526
+ return new t(function (t, r) {
527
+ i(e, n, t, r);
528
+ });
529
+ }
530
+ return (o = o ? o.then(r, r) : r());
531
+ },
532
+ });
533
+ }
534
+ function w(t, i, n) {
535
+ var r = f;
536
+ return function (o, s) {
537
+ if (r === g) throw Error("Generator is already running");
538
+ if (r === v) {
539
+ if ("throw" === o) throw s;
540
+ return { value: e, done: !0 };
541
+ }
542
+ for (n.method = o, n.arg = s; ; ) {
543
+ var a = n.delegate;
544
+ if (a) {
545
+ var c = P(a, n);
546
+ if (c) {
547
+ if (c === b) continue;
548
+ return c;
549
+ }
550
+ }
551
+ if ("next" === n.method) n.sent = n._sent = n.arg;
552
+ else if ("throw" === n.method) {
553
+ if (r === f) throw ((r = v), n.arg);
554
+ n.dispatchException(n.arg);
555
+ } else "return" === n.method && n.abrupt("return", n.arg);
556
+ r = g;
557
+ var u = d(t, i, n);
558
+ if ("normal" === u.type) {
559
+ if (((r = n.done ? v : p), u.arg === b)) continue;
560
+ return { value: u.arg, done: n.done };
561
+ }
562
+ "throw" === u.type && ((r = v), (n.method = "throw"), (n.arg = u.arg));
563
+ }
564
+ };
565
+ }
566
+ function P(t, i) {
567
+ var n = i.method,
568
+ r = t.iterator[n];
569
+ if (r === e)
570
+ return (
571
+ (i.delegate = null),
572
+ ("throw" === n &&
573
+ t.iterator.return &&
574
+ ((i.method = "return"),
575
+ (i.arg = e),
576
+ P(t, i),
577
+ "throw" === i.method)) ||
578
+ ("return" !== n &&
579
+ ((i.method = "throw"),
580
+ (i.arg = new TypeError(
581
+ "The iterator does not provide a '" + n + "' method",
582
+ )))),
583
+ b
584
+ );
585
+ var o = d(r, t.iterator, i.arg);
586
+ if ("throw" === o.type)
587
+ return (i.method = "throw"), (i.arg = o.arg), (i.delegate = null), b;
588
+ var s = o.arg;
589
+ return s
590
+ ? s.done
591
+ ? ((i[t.resultName] = s.value),
592
+ (i.next = t.nextLoc),
593
+ "return" !== i.method && ((i.method = "next"), (i.arg = e)),
594
+ (i.delegate = null),
595
+ b)
596
+ : s
597
+ : ((i.method = "throw"),
598
+ (i.arg = new TypeError("iterator result is not an object")),
599
+ (i.delegate = null),
600
+ b);
601
+ }
602
+ function D(e) {
603
+ var t = { tryLoc: e[0] };
604
+ 1 in e && (t.catchLoc = e[1]),
605
+ 2 in e && ((t.finallyLoc = e[2]), (t.afterLoc = e[3])),
606
+ this.tryEntries.push(t);
607
+ }
608
+ function T(e) {
609
+ var t = e.completion || {};
610
+ (t.type = "normal"), delete t.arg, (e.completion = t);
611
+ }
612
+ function _(e) {
613
+ (this.tryEntries = [{ tryLoc: "root" }]),
614
+ e.forEach(D, this),
615
+ this.reset(!0);
616
+ }
617
+ function O(t) {
618
+ if (t || "" === t) {
619
+ var i = t[s];
620
+ if (i) return i.call(t);
621
+ if ("function" == typeof t.next) return t;
622
+ if (!isNaN(t.length)) {
623
+ var r = -1,
624
+ o = function i() {
625
+ for (; ++r < t.length; )
626
+ if (n.call(t, r)) return (i.value = t[r]), (i.done = !1), i;
627
+ return (i.value = e), (i.done = !0), i;
628
+ };
629
+ return (o.next = o);
630
+ }
631
+ }
632
+ throw new TypeError(typeof t + " is not iterable");
633
+ }
634
+ return (
635
+ (y.prototype = S),
636
+ r(I, "constructor", { value: S, configurable: !0 }),
637
+ r(S, "constructor", { value: y, configurable: !0 }),
638
+ (y.displayName = u(S, c, "GeneratorFunction")),
639
+ (t.isGeneratorFunction = function (e) {
640
+ var t = "function" == typeof e && e.constructor;
641
+ return (
642
+ !!t && (t === y || "GeneratorFunction" === (t.displayName || t.name))
643
+ );
644
+ }),
645
+ (t.mark = function (e) {
646
+ return (
647
+ Object.setPrototypeOf
648
+ ? Object.setPrototypeOf(e, S)
649
+ : ((e.__proto__ = S), u(e, c, "GeneratorFunction")),
650
+ (e.prototype = Object.create(I)),
651
+ e
652
+ );
653
+ }),
654
+ (t.awrap = function (e) {
655
+ return { __await: e };
656
+ }),
657
+ A(R.prototype),
658
+ u(R.prototype, a, function () {
659
+ return this;
660
+ }),
661
+ (t.AsyncIterator = R),
662
+ (t.async = function (e, i, n, r, o) {
663
+ void 0 === o && (o = Promise);
664
+ var s = new R(l(e, i, n, r), o);
665
+ return t.isGeneratorFunction(i)
666
+ ? s
667
+ : s.next().then(function (e) {
668
+ return e.done ? e.value : s.next();
669
+ });
670
+ }),
671
+ A(I),
672
+ u(I, c, "Generator"),
673
+ u(I, s, function () {
674
+ return this;
675
+ }),
676
+ u(I, "toString", function () {
677
+ return "[object Generator]";
678
+ }),
679
+ (t.keys = function (e) {
680
+ var t = Object(e),
681
+ i = [];
682
+ for (var n in t) i.push(n);
683
+ return (
684
+ i.reverse(),
685
+ function e() {
686
+ for (; i.length; ) {
687
+ var n = i.pop();
688
+ if (n in t) return (e.value = n), (e.done = !1), e;
689
+ }
690
+ return (e.done = !0), e;
691
+ }
692
+ );
693
+ }),
694
+ (t.values = O),
695
+ (_.prototype = {
696
+ constructor: _,
697
+ reset: function (t) {
698
+ if (
699
+ ((this.prev = 0),
700
+ (this.next = 0),
701
+ (this.sent = this._sent = e),
702
+ (this.done = !1),
703
+ (this.delegate = null),
704
+ (this.method = "next"),
705
+ (this.arg = e),
706
+ this.tryEntries.forEach(T),
707
+ !t)
708
+ )
709
+ for (var i in this)
710
+ "t" === i.charAt(0) &&
711
+ n.call(this, i) &&
712
+ !isNaN(+i.slice(1)) &&
713
+ (this[i] = e);
714
+ },
715
+ stop: function () {
716
+ this.done = !0;
717
+ var e = this.tryEntries[0].completion;
718
+ if ("throw" === e.type) throw e.arg;
719
+ return this.rval;
720
+ },
721
+ dispatchException: function (t) {
722
+ if (this.done) throw t;
723
+ var i = this;
724
+ function r(n, r) {
725
+ return (
726
+ (a.type = "throw"),
727
+ (a.arg = t),
728
+ (i.next = n),
729
+ r && ((i.method = "next"), (i.arg = e)),
730
+ !!r
731
+ );
732
+ }
733
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
734
+ var s = this.tryEntries[o],
735
+ a = s.completion;
736
+ if ("root" === s.tryLoc) return r("end");
737
+ if (s.tryLoc <= this.prev) {
738
+ var c = n.call(s, "catchLoc"),
739
+ u = n.call(s, "finallyLoc");
740
+ if (c && u) {
741
+ if (this.prev < s.catchLoc) return r(s.catchLoc, !0);
742
+ if (this.prev < s.finallyLoc) return r(s.finallyLoc);
743
+ } else if (c) {
744
+ if (this.prev < s.catchLoc) return r(s.catchLoc, !0);
745
+ } else {
746
+ if (!u) throw Error("try statement without catch or finally");
747
+ if (this.prev < s.finallyLoc) return r(s.finallyLoc);
748
+ }
749
+ }
750
+ }
751
+ },
752
+ abrupt: function (e, t) {
753
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
754
+ var r = this.tryEntries[i];
755
+ if (
756
+ r.tryLoc <= this.prev &&
757
+ n.call(r, "finallyLoc") &&
758
+ this.prev < r.finallyLoc
759
+ ) {
760
+ var o = r;
761
+ break;
762
+ }
763
+ }
764
+ o &&
765
+ ("break" === e || "continue" === e) &&
766
+ o.tryLoc <= t &&
767
+ t <= o.finallyLoc &&
768
+ (o = null);
769
+ var s = o ? o.completion : {};
770
+ return (
771
+ (s.type = e),
772
+ (s.arg = t),
773
+ o
774
+ ? ((this.method = "next"), (this.next = o.finallyLoc), b)
775
+ : this.complete(s)
776
+ );
777
+ },
778
+ complete: function (e, t) {
779
+ if ("throw" === e.type) throw e.arg;
780
+ return (
781
+ "break" === e.type || "continue" === e.type
782
+ ? (this.next = e.arg)
783
+ : "return" === e.type
784
+ ? ((this.rval = this.arg = e.arg),
785
+ (this.method = "return"),
786
+ (this.next = "end"))
787
+ : "normal" === e.type && t && (this.next = t),
788
+ b
789
+ );
790
+ },
791
+ finish: function (e) {
792
+ for (var t = this.tryEntries.length - 1; t >= 0; --t) {
793
+ var i = this.tryEntries[t];
794
+ if (i.finallyLoc === e)
795
+ return this.complete(i.completion, i.afterLoc), T(i), b;
796
+ }
797
+ },
798
+ catch: function (e) {
799
+ for (var t = this.tryEntries.length - 1; t >= 0; --t) {
800
+ var i = this.tryEntries[t];
801
+ if (i.tryLoc === e) {
802
+ var n = i.completion;
803
+ if ("throw" === n.type) {
804
+ var r = n.arg;
805
+ T(i);
806
+ }
807
+ return r;
808
+ }
809
+ }
810
+ throw Error("illegal catch attempt");
811
+ },
812
+ delegateYield: function (t, i, n) {
813
+ return (
814
+ (this.delegate = { iterator: O(t), resultName: i, nextLoc: n }),
815
+ "next" === this.method && (this.arg = e),
816
+ b
817
+ );
818
+ },
819
+ }),
820
+ t
821
+ );
822
+ }
823
+ function f(e) {
824
+ var t = (function (e, t) {
825
+ if ("object" != typeof e || !e) return e;
826
+ var i = e[Symbol.toPrimitive];
827
+ if (void 0 !== i) {
828
+ var n = i.call(e, t || "default");
829
+ if ("object" != typeof n) return n;
830
+ throw new TypeError("@@toPrimitive must return a primitive value.");
831
+ }
832
+ return ("string" === t ? String : Number)(e);
833
+ })(e, "string");
834
+ return "symbol" == typeof t ? t : t + "";
835
+ }
836
+ function p(e, t, i, n, r, o, s) {
837
+ try {
838
+ var a = e[o](s),
839
+ c = a.value;
840
+ } catch (e) {
841
+ return void i(e);
842
+ }
843
+ a.done ? t(c) : Promise.resolve(c).then(n, r);
844
+ }
845
+ function g(e) {
846
+ return function () {
847
+ var t = this,
848
+ i = arguments;
849
+ return new Promise(function (n, r) {
850
+ var o = e.apply(t, i);
851
+ function s(e) {
852
+ p(o, n, r, s, a, "next", e);
853
+ }
854
+ function a(e) {
855
+ p(o, n, r, s, a, "throw", e);
856
+ }
857
+ s(void 0);
858
+ });
859
+ };
860
+ }
861
+ function v(e, t) {
862
+ if (!(e instanceof t))
863
+ throw new TypeError("Cannot call a class as a function");
864
+ }
865
+ function b(e, t) {
866
+ for (var i = 0; i < t.length; i++) {
867
+ var n = t[i];
868
+ (n.enumerable = n.enumerable || !1),
869
+ (n.configurable = !0),
870
+ "value" in n && (n.writable = !0),
871
+ Object.defineProperty(e, f(n.key), n);
872
+ }
873
+ }
874
+ function m(e, t, i) {
875
+ return (
876
+ t && b(e.prototype, t),
877
+ i && b(e, i),
878
+ Object.defineProperty(e, "prototype", { writable: !1 }),
879
+ e
880
+ );
881
+ }
882
+ function y(e, t) {
883
+ (null == t || t > e.length) && (t = e.length);
884
+ for (var i = 0, n = new Array(t); i < t; i++) n[i] = e[i];
885
+ return n;
886
+ }
887
+ function S(e, t) {
888
+ var i =
889
+ ("undefined" != typeof Symbol && e[Symbol.iterator]) || e["@@iterator"];
890
+ if (!i) {
891
+ if (
892
+ Array.isArray(e) ||
893
+ (i = (function (e, t) {
894
+ if (e) {
895
+ if ("string" == typeof e) return y(e, t);
896
+ var i = Object.prototype.toString.call(e).slice(8, -1);
897
+ return (
898
+ "Object" === i && e.constructor && (i = e.constructor.name),
899
+ "Map" === i || "Set" === i
900
+ ? Array.from(e)
901
+ : "Arguments" === i ||
902
+ /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)
903
+ ? y(e, t)
904
+ : void 0
905
+ );
906
+ }
907
+ })(e)) ||
908
+ (t && e && "number" == typeof e.length)
909
+ ) {
910
+ i && (e = i);
911
+ var n = 0,
912
+ r = function () {};
913
+ return {
914
+ s: r,
915
+ n: function () {
916
+ return n >= e.length ? { done: !0 } : { done: !1, value: e[n++] };
917
+ },
918
+ e: function (e) {
919
+ throw e;
920
+ },
921
+ f: r,
922
+ };
923
+ }
924
+ throw new TypeError(
925
+ "Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.",
926
+ );
927
+ }
928
+ var o,
929
+ s = !0,
930
+ a = !1;
931
+ return {
932
+ s: function () {
933
+ i = i.call(e);
934
+ },
935
+ n: function () {
936
+ var e = i.next();
937
+ return (s = e.done), e;
938
+ },
939
+ e: function (e) {
940
+ (a = !0), (o = e);
941
+ },
942
+ f: function () {
943
+ try {
944
+ s || null == i.return || i.return();
945
+ } finally {
946
+ if (a) throw o;
947
+ }
948
+ },
949
+ };
950
+ }
951
+ Object.defineProperty(d, "defaultTag", {
952
+ enumerable: !0,
953
+ configurable: !0,
954
+ writable: !0,
955
+ value: "AugnitoAmbientSDK",
956
+ });
957
+ var C = "DONE",
958
+ k = "PAUSESOCKET",
959
+ E = "RESUMESOCKET",
960
+ I = "INTENT_START_STREAM",
961
+ A = "CLOSE",
962
+ R = m(
963
+ function e(t, i, n, r, o, s, a, c, u, l, d, h, f) {
964
+ v(this, e),
965
+ this.worker,
966
+ (this.onFinalResultCallback = o),
967
+ (this.onErrorCallback = a),
968
+ (this.onPartialResultCallback = s),
969
+ (this.onSessionEventCallback = c),
970
+ (this.onOtherResultsCallback = u),
971
+ (this.onSpeechResponseCallback = l),
972
+ (this.onJobStatusCallback = d),
973
+ (this.packetSeqId = 0),
974
+ (this.audioDuration = 0),
975
+ (this.shouldSendAudioDataSequence = r),
976
+ this.heavyOp,
977
+ this.idleLoop,
978
+ this.lastSent,
979
+ (this.enableLogs = t),
980
+ (this.eosMessage = i || "EOS"),
981
+ (this.socketTimeoutInterval = n || 1e4),
982
+ (this.bufferSizeInterval = h),
983
+ (this.switchToRegularSpeech = f);
984
+ },
985
+ [
986
+ {
987
+ key: "Start",
988
+ value: function (e, t, i) {
989
+ var n = this;
990
+ this.audioDuration = e;
991
+ var r = "\n (() => {\n ("
992
+ .concat(w.toString(), ")(")
993
+ .concat(JSON.stringify(C), ", ")
994
+ .concat(JSON.stringify(this.eosMessage), ", ")
995
+ .concat(JSON.stringify(A), ", ")
996
+ .concat(JSON.stringify(1e4), ", ")
997
+ .concat(JSON.stringify(this.socketTimeoutInterval), ", ")
998
+ .concat(JSON.stringify(12e4), ", ")
999
+ .concat(JSON.stringify(1e3), ", ")
1000
+ .concat(JSON.stringify(100), ", ")
1001
+ .concat(JSON.stringify(1e4), ", ")
1002
+ .concat(JSON.stringify(t), ", ")
1003
+ .concat(JSON.stringify(this.enableLogs), ", ")
1004
+ .concat(JSON.stringify(this.shouldSendAudioDataSequence), ",")
1005
+ .concat(JSON.stringify(k), ", ")
1006
+ .concat(JSON.stringify(E), ", ")
1007
+ .concat(JSON.stringify(I), ", ")
1008
+ .concat(JSON.stringify(this.switchToRegularSpeech), ", ")
1009
+ .concat(JSON.stringify(i), ", ")
1010
+ .concat(JSON.stringify(this.heavyOp), ");\n })();\n");
1011
+ (this.worker = new Worker(
1012
+ URL.createObjectURL(
1013
+ new Blob([r], { type: "application/javascript" }),
1014
+ ),
1015
+ )),
1016
+ (this.worker.onmessage = function (e) {
1017
+ n.enableLogs &&
1018
+ console.log("Augnito [MAIN]: " + JSON.stringify(e.data));
1019
+ var t = e.data;
1020
+ "final" == t.type
1021
+ ? n.onFinalResultCallback(t.data)
1022
+ : "partial" == t.type
1023
+ ? n.onPartialResultCallback(t.data)
1024
+ : "meta" == t.type
1025
+ ? n.onSessionEventCallback(t.data)
1026
+ : "error" == t.type
1027
+ ? n.onErrorCallback(t.data)
1028
+ : "other" == t.type
1029
+ ? n.onOtherResultsCallback(t.data)
1030
+ : "jobstatus" == t.type
1031
+ ? n.onJobStatusCallback(t.data.status)
1032
+ : "speechResponse" == t.type &&
1033
+ n.onSpeechResponseCallback(t.data);
1034
+ });
1035
+ },
1036
+ },
1037
+ {
1038
+ key: "createAudioPacketHeader",
1039
+ value: function (e) {
1040
+ this.audioDuration > 0 &&
1041
+ ((this.packetSeqId =
1042
+ Math.ceil(this.audioDuration / this.bufferSizeInterval) + 2),
1043
+ (this.audioDuration = 0)),
1044
+ this.packetSeqId++;
1045
+ for (
1046
+ var t = new ArrayBuffer(16), i = new DataView(t), n = 0;
1047
+ n < 4;
1048
+ n++
1049
+ )
1050
+ i.setUint8(n, "@BSR".charCodeAt(n));
1051
+ return (
1052
+ i.setBigInt64(4, BigInt(this.packetSeqId), !1),
1053
+ i.setUint8(12, e ? 1 : 0),
1054
+ t
1055
+ );
1056
+ },
1057
+ },
1058
+ {
1059
+ key: "appendAudioData",
1060
+ value: function (e, t) {
1061
+ var i = e.byteLength + t.byteLength,
1062
+ n = new ArrayBuffer(i),
1063
+ r = new Uint8Array(n);
1064
+ return (
1065
+ r.set(new Uint8Array(e), 0),
1066
+ r.set(new Uint8Array(t), e.byteLength),
1067
+ n
1068
+ );
1069
+ },
1070
+ },
1071
+ {
1072
+ key: "Send",
1073
+ value: function (e) {
1074
+ var t;
1075
+ if (((this.lastSent = +new Date()), e === A))
1076
+ null === (t = this.worker) || void 0 === t || t.postMessage(A);
1077
+ else if (e === C)
1078
+ if (this.shouldSendAudioDataSequence) {
1079
+ var i,
1080
+ n = this.createAudioPacketHeader(!0);
1081
+ null === (i = this.worker) || void 0 === i || i.postMessage(n);
1082
+ } else {
1083
+ var r;
1084
+ null === (r = this.worker) || void 0 === r || r.postMessage(C);
1085
+ }
1086
+ else if (e == k) {
1087
+ var o;
1088
+ null === (o = this.worker) || void 0 === o || o.postMessage(k);
1089
+ } else if (e == E) {
1090
+ var s;
1091
+ null === (s = this.worker) || void 0 === s || s.postMessage(E);
1092
+ } else if (e == I) {
1093
+ var a;
1094
+ null === (a = this.worker) || void 0 === a || a.postMessage(I);
1095
+ } else if (e === this.eosMessage) {
1096
+ var c;
1097
+ this.shouldSendAudioDataSequence ||
1098
+ null === (c = this.worker) ||
1099
+ void 0 === c ||
1100
+ c.postMessage(e);
1101
+ } else {
1102
+ var u,
1103
+ l = [];
1104
+ this.shouldSendAudioDataSequence
1105
+ ? ((n = this.createAudioPacketHeader(!1)),
1106
+ (l = this.appendAudioData(n, e)))
1107
+ : (l = e),
1108
+ void 0 !== l &&
1109
+ (null === (u = this.worker) ||
1110
+ void 0 === u ||
1111
+ u.postMessage(l, [l]));
1112
+ }
1113
+ },
1114
+ },
1115
+ {
1116
+ key: "HeavyOp",
1117
+ set: function (e) {
1118
+ this.heavyOp = e;
1119
+ },
1120
+ },
1121
+ ],
1122
+ );
1123
+ function w(e, t, i, n, r, o, s, a, c, u, l, d, h, f, p, g, v, b) {
1124
+ var m,
1125
+ y,
1126
+ S,
1127
+ C,
1128
+ k,
1129
+ E,
1130
+ I,
1131
+ A,
1132
+ R,
1133
+ w = [],
1134
+ P = [],
1135
+ D = !1,
1136
+ T = [],
1137
+ _ = !1,
1138
+ O = !1,
1139
+ x = !1,
1140
+ N = "",
1141
+ U = v;
1142
+ function L() {
1143
+ (m = +new Date()),
1144
+ ((E =
1145
+ "" != N ? new WebSocket(u + "&jobid=" + N) : new WebSocket(u)).onopen =
1146
+ function (e) {
1147
+ l &&
1148
+ console.log(
1149
+ "Augnito: WebSocket connection established - " +
1150
+ JSON.stringify(e),
1151
+ ),
1152
+ T.length > 0 && (O = !0);
1153
+ }),
1154
+ (E.onmessage = function (e) {
1155
+ l &&
1156
+ console.log(
1157
+ "Augnito: Message from server - " + JSON.stringify(e.data),
1158
+ ),
1159
+ (S = +new Date()),
1160
+ (function (e) {
1161
+ try {
1162
+ if ("PING" === e.data)
1163
+ (C = +new Date()),
1164
+ self.postMessage({ type: "ping", data: e.data });
1165
+ else {
1166
+ var t = JSON.parse(e.data);
1167
+ if (
1168
+ (l && console.log("Augnito [WORKER]: " + JSON.stringify(t)),
1169
+ "meta" == t.Type)
1170
+ ) {
1171
+ t.JobID && ((N = t.JobID), console.log("Augnito JobID:", N)),
1172
+ self.postMessage({ type: "meta", data: e.data });
1173
+ var i = JSON.parse(e.data);
1174
+ x = !(
1175
+ !i.Event || "INVALID_AUTH_CREDENTIALS" !== i.Event.Type
1176
+ );
1177
+ } else if (t.Result && t.Result.Final) {
1178
+ var n = JSON.stringify(t.Result);
1179
+ b && ((n = b(JSON.stringify(t.Result))), console.log(n)),
1180
+ self.postMessage({ type: "final", data: n });
1181
+ } else
1182
+ t.Result && !t.Result.Final
1183
+ ? self.postMessage({
1184
+ type: "partial",
1185
+ data: t.Result.Transcript,
1186
+ })
1187
+ : "ACK" == t.Type
1188
+ ? ((T = T.filter(function (e) {
1189
+ return e.packetNumber > t.Index;
1190
+ })),
1191
+ "RECEIVED_EOS" === t.Data.toUpperCase() &&
1192
+ ((_ = !0), clearInterval(R)),
1193
+ self.postMessage({ type: "other", data: e.data }))
1194
+ : "ERROR" == t.Type
1195
+ ? ("Timeout exceeded" == t.Data && ((_ = !0), K()),
1196
+ self.postMessage({ type: "error", data: e.data }))
1197
+ : "STATUS" == t.Type
1198
+ ? self.postMessage({
1199
+ type: "jobstatus",
1200
+ data: { status: e.data },
1201
+ })
1202
+ : self.postMessage({
1203
+ type: "speechResponse",
1204
+ data: e.data,
1205
+ });
1206
+ }
1207
+ } catch (e) {
1208
+ self.postMessage({ type: "error", data: "invalid response" });
1209
+ }
1210
+ })(e);
1211
+ }),
1212
+ (E.onerror = function (e) {
1213
+ console.error("WebSocket error: ", e),
1214
+ self.postMessage({ type: "error", data: JSON.stringify(e) });
1215
+ }),
1216
+ (E.onclose = function (e) {
1217
+ l &&
1218
+ console.log(
1219
+ "Augnito: WebSocket connection closed - " + JSON.stringify(e),
1220
+ ),
1221
+ K();
1222
+ }),
1223
+ (y = +new Date()),
1224
+ (S = y),
1225
+ (C = +new Date());
1226
+ }
1227
+ function M(e) {
1228
+ if (E && E.readyState === WebSocket.OPEN) {
1229
+ E.send(e);
1230
+ var i = +new Date();
1231
+ return y <= S && (S = i - 1), (y = i), !0;
1232
+ }
1233
+ return e === t
1234
+ ? (l &&
1235
+ console.warn(
1236
+ "Gulping ".concat(t, " as socket seems already closed..."),
1237
+ ),
1238
+ K(),
1239
+ !0)
1240
+ : (+new Date() - m > n && !x && L(), !1);
1241
+ }
1242
+ function J(e) {
1243
+ w.push(e);
1244
+ }
1245
+ function K() {
1246
+ _ &&
1247
+ (console.log("Augnito: Cleaning up worker resources..."),
1248
+ clearInterval(I),
1249
+ clearInterval(A),
1250
+ clearInterval(R),
1251
+ (w = []),
1252
+ (T = []),
1253
+ self.close());
1254
+ }
1255
+ L(),
1256
+ (I = setInterval(function () {
1257
+ if (O) {
1258
+ for (var e = 0; e < T.length; e++) {
1259
+ if (!M(T[e].packetData)) break;
1260
+ }
1261
+ O = !1;
1262
+ } else
1263
+ for (; w.length > 0; ) {
1264
+ var t = w.shift();
1265
+ if (!M(t)) {
1266
+ w.unshift(t);
1267
+ break;
1268
+ }
1269
+ if (d) {
1270
+ if (!(t instanceof ArrayBuffer)) continue;
1271
+ var i = new DataView(t),
1272
+ n = { packetNumber: Number(i.getBigInt64(4)), packetData: t };
1273
+ T.push(n);
1274
+ }
1275
+ }
1276
+ }, a)),
1277
+ (A = setInterval(function () {
1278
+ if (E && E.readyState === WebSocket.OPEN) {
1279
+ var e = +new Date();
1280
+ (g ? y > S && e - S > r : e - C > r) &&
1281
+ (l &&
1282
+ console.error(
1283
+ "No data received since more than ".concat(
1284
+ r / 1e3,
1285
+ " secs, closing time...",
1286
+ ),
1287
+ ),
1288
+ E.close());
1289
+ }
1290
+ }, s)),
1291
+ (R = setInterval(function () {
1292
+ if (E && E.readyState === WebSocket.OPEN) {
1293
+ var e = +new Date();
1294
+ y &&
1295
+ e - y > o &&
1296
+ (l &&
1297
+ console.warn(
1298
+ "No data sent since more than ".concat(
1299
+ o / 1e3,
1300
+ " secs, closing time...",
1301
+ ),
1302
+ ),
1303
+ E.close());
1304
+ }
1305
+ }, c)),
1306
+ (self.onmessage = function (n) {
1307
+ if (n.data === i) (N = ""), (_ = !0), (x = !0), E.close();
1308
+ else if (n.data === e)
1309
+ J(t),
1310
+ (N = ""),
1311
+ l &&
1312
+ console.log("Augnito: Worker received DONE, time to terminate..."),
1313
+ (_ = !0);
1314
+ else if (n.data === h) U = !0;
1315
+ else if (n.data === p) D = !0;
1316
+ else if (n.data === f) {
1317
+ if ((k instanceof ArrayBuffer && J(k), P.length > 0))
1318
+ for (var r = 0; r < P.length; r++) J(P[r]);
1319
+ (P = []), (D = !1), (U = !1), (k = []);
1320
+ } else U && !D ? (k = n.data) : U && D ? P.push(n.data) : J(n.data);
1321
+ });
1322
+ }
1323
+ var P,
1324
+ D,
1325
+ T,
1326
+ _,
1327
+ O,
1328
+ x,
1329
+ N,
1330
+ U,
1331
+ L,
1332
+ M,
1333
+ J = m(
1334
+ function e(
1335
+ t,
1336
+ i,
1337
+ n,
1338
+ r,
1339
+ o,
1340
+ s,
1341
+ a,
1342
+ c,
1343
+ u,
1344
+ l,
1345
+ d,
1346
+ h,
1347
+ f,
1348
+ p,
1349
+ g,
1350
+ b,
1351
+ m,
1352
+ y,
1353
+ S,
1354
+ C,
1355
+ k,
1356
+ E,
1357
+ I,
1358
+ A,
1359
+ w,
1360
+ P,
1361
+ ) {
1362
+ v(this, e),
1363
+ this.audioContext,
1364
+ this.audioStream,
1365
+ (this.executor = new R(i, s, a, c, m, y, S, k, E, I, w, r, h)),
1366
+ (this.executor.HeavyOp = b),
1367
+ this.source,
1368
+ this.processorNode,
1369
+ (this.isPaused = !1),
1370
+ (this.isStreaming = !1),
1371
+ (this.audioData = []),
1372
+ (this.isDebug = n),
1373
+ (this.enableLogs = i),
1374
+ (this.onStateChanged = C),
1375
+ (this.onIntensity = A),
1376
+ (this.onError = S),
1377
+ (this.bufferSizeInterval = r),
1378
+ (this.pausedBufferInterval = null != o ? o : 1),
1379
+ (this.shouldReadIntensity = d),
1380
+ (this.closeSocketWithoutEOS = !1),
1381
+ (this.shouldPreIntialiseRecorder = null != l && l),
1382
+ (this.echoCancellation = f),
1383
+ (this.noiseSuppression = p),
1384
+ (this.autoGainControl = g),
1385
+ (this.micNeedsRecovery = !1),
1386
+ (this.trackEndedHandler = null),
1387
+ (this.isRecovering = !1),
1388
+ (this._micReadyFired = !1),
1389
+ (this.currentWsUrl = ""),
1390
+ (this.currentDuration = 0),
1391
+ (this.deviceChangeHandler = null),
1392
+ (this.onMicReady = P),
1393
+ (this._originalDeviceId = null),
1394
+ this.shouldPreIntialiseRecorder && this.InitialiseMediaStream(u, t);
1395
+ },
1396
+ [
1397
+ {
1398
+ key: "InitialiseMediaStream",
1399
+ value:
1400
+ ((M = g(
1401
+ h().mark(function e(t, i) {
1402
+ var n = this;
1403
+ return h().wrap(
1404
+ function (e) {
1405
+ for (;;)
1406
+ switch ((e.prev = e.next)) {
1407
+ case 0:
1408
+ return (
1409
+ (this.currentDuration = t),
1410
+ (this.currentWsUrl = i),
1411
+ (e.next = 4),
1412
+ this.createMediaStreamSourceNode()
1413
+ );
1414
+ case 4:
1415
+ if (this.source) {
1416
+ e.next = 7;
1417
+ break;
1418
+ }
1419
+ return (
1420
+ console.error("Error: unable to create source node"),
1421
+ e.abrupt("return", !1)
1422
+ );
1423
+ case 7:
1424
+ return (e.next = 9), this.createProcessorNode();
1425
+ case 9:
1426
+ if (this.processorNode) {
1427
+ e.next = 12;
1428
+ break;
1429
+ }
1430
+ return (
1431
+ console.error(
1432
+ "Error: unable to create processor node",
1433
+ ),
1434
+ e.abrupt("return", !1)
1435
+ );
1436
+ case 12:
1437
+ this.source
1438
+ .connect(this.processorNode)
1439
+ .connect(this.audioContext.destination),
1440
+ this.log(
1441
+ "AudioContext Sample Rate: " +
1442
+ this.audioContext.sampleRate,
1443
+ ),
1444
+ "" !== i &&
1445
+ this.executor.Start(
1446
+ t,
1447
+ i,
1448
+ this.shouldPreIntialiseRecorder,
1449
+ ),
1450
+ this.deviceChangeHandler ||
1451
+ ((this.deviceChangeHandler = g(
1452
+ h().mark(function e() {
1453
+ var t, i, r, o, s, a, c;
1454
+ return h().wrap(function (e) {
1455
+ for (;;)
1456
+ switch ((e.prev = e.next)) {
1457
+ case 0:
1458
+ if (
1459
+ (s =
1460
+ null === (t = n.audioStream) ||
1461
+ void 0 === t ||
1462
+ null === (i = t.getAudioTracks) ||
1463
+ void 0 === i
1464
+ ? void 0
1465
+ : i.call(t)[0]) &&
1466
+ "ended" !== s.readyState
1467
+ ) {
1468
+ e.next = 7;
1469
+ break;
1470
+ }
1471
+ return (
1472
+ (n.micNeedsRecovery = !0),
1473
+ (e.next = 6),
1474
+ n.recoverAudioGraph()
1475
+ );
1476
+ case 6:
1477
+ return e.abrupt("return");
1478
+ case 7:
1479
+ return (
1480
+ (a =
1481
+ null !==
1482
+ (r =
1483
+ null === (o = s.getSettings) ||
1484
+ void 0 === o ||
1485
+ null === (o = o.call(s)) ||
1486
+ void 0 === o
1487
+ ? void 0
1488
+ : o.deviceId) && void 0 !== r
1489
+ ? r
1490
+ : s.label),
1491
+ n.log(
1492
+ 'Device change detected. Probing current device: "'.concat(
1493
+ s.label,
1494
+ '"',
1495
+ ),
1496
+ ),
1497
+ (e.next = 11),
1498
+ K(a)
1499
+ );
1500
+ case 11:
1501
+ if (e.sent) {
1502
+ e.next = 23;
1503
+ break;
1504
+ }
1505
+ return (
1506
+ n.log(
1507
+ 'Current device "'.concat(
1508
+ s.label,
1509
+ '" appears silent/virtual. Searching for a real input device...',
1510
+ ),
1511
+ ),
1512
+ (n.micNeedsRecovery = !0),
1513
+ (e.next = 17),
1514
+ W(a, n.enableLogs)
1515
+ );
1516
+ case 17:
1517
+ return (
1518
+ (c = e.sent)
1519
+ ? (n._preferredDeviceId = c)
1520
+ : (n.log(
1521
+ "No active audio input device found after device change",
1522
+ ),
1523
+ (n._preferredDeviceId = null)),
1524
+ (e.next = 21),
1525
+ n.recoverAudioGraph()
1526
+ );
1527
+ case 21:
1528
+ e.next = 24;
1529
+ break;
1530
+ case 23:
1531
+ n.log(
1532
+ 'Current device "'.concat(
1533
+ s.label,
1534
+ '" is producing audio — no switch needed',
1535
+ ),
1536
+ );
1537
+ case 24:
1538
+ case "end":
1539
+ return e.stop();
1540
+ }
1541
+ }, e);
1542
+ }),
1543
+ )),
1544
+ navigator.mediaDevices.addEventListener(
1545
+ "devicechange",
1546
+ this.deviceChangeHandler,
1547
+ ));
1548
+ case 16:
1549
+ case "end":
1550
+ return e.stop();
1551
+ }
1552
+ },
1553
+ e,
1554
+ this,
1555
+ );
1556
+ }),
1557
+ )),
1558
+ function (e, t) {
1559
+ return M.apply(this, arguments);
1560
+ }),
1561
+ },
1562
+ {
1563
+ key: "StartStream",
1564
+ value:
1565
+ ((L = g(
1566
+ h().mark(function e(t, i) {
1567
+ var n, r;
1568
+ return h().wrap(
1569
+ function (e) {
1570
+ for (;;)
1571
+ switch ((e.prev = e.next)) {
1572
+ case 0:
1573
+ if (
1574
+ (this.log("New stream started..."),
1575
+ this.shouldPreIntialiseRecorder && this.source)
1576
+ ) {
1577
+ e.next = 6;
1578
+ break;
1579
+ }
1580
+ return (
1581
+ (e.next = 4), this.InitialiseMediaStream(t, i, !1)
1582
+ );
1583
+ case 4:
1584
+ e.next = 7;
1585
+ break;
1586
+ case 6:
1587
+ this.shouldPreIntialiseRecorder &&
1588
+ this.executor.Send(E);
1589
+ case 7:
1590
+ if (!this.IsMicrophoneMuted) {
1591
+ e.next = 15;
1592
+ break;
1593
+ }
1594
+ if (
1595
+ !this.audioContext ||
1596
+ "running" != this.audioContext.state
1597
+ ) {
1598
+ e.next = 11;
1599
+ break;
1600
+ }
1601
+ return (e.next = 11), this.audioContext.suspend();
1602
+ case 11:
1603
+ return (
1604
+ null === (n = this.audioStream) ||
1605
+ void 0 === n ||
1606
+ null === (r = n.getTracks) ||
1607
+ void 0 === r ||
1608
+ null === (r = r.call(n)) ||
1609
+ void 0 === r ||
1610
+ r.forEach(function (e) {
1611
+ try {
1612
+ e.stop();
1613
+ } catch (e) {}
1614
+ }),
1615
+ this.executor.Send(A),
1616
+ this.onError(
1617
+ JSON.stringify({
1618
+ Type: "ERROR",
1619
+ Data: "Microphone is muted.",
1620
+ }),
1621
+ ),
1622
+ e.abrupt("return", !1)
1623
+ );
1624
+ case 15:
1625
+ return (
1626
+ this.onStateChanged(!0),
1627
+ (this.isStreaming = !0),
1628
+ e.abrupt("return", !0)
1629
+ );
1630
+ case 18:
1631
+ case "end":
1632
+ return e.stop();
1633
+ }
1634
+ },
1635
+ e,
1636
+ this,
1637
+ );
1638
+ }),
1639
+ )),
1640
+ function (e, t) {
1641
+ return L.apply(this, arguments);
1642
+ }),
1643
+ },
1644
+ {
1645
+ key: "createBufferedSourceNode",
1646
+ value:
1647
+ ((U = g(
1648
+ h().mark(function e() {
1649
+ var t;
1650
+ return h().wrap(
1651
+ function (e) {
1652
+ for (;;)
1653
+ switch ((e.prev = e.next)) {
1654
+ case 0:
1655
+ return (e.next = 2), this.loadAudio();
1656
+ case 2:
1657
+ if ((t = e.sent)) {
1658
+ e.next = 6;
1659
+ break;
1660
+ }
1661
+ return (
1662
+ console.error("Error: unable to create audio buffer"),
1663
+ e.abrupt("return")
1664
+ );
1665
+ case 6:
1666
+ (this.source = this.audioContext.createBufferSource()),
1667
+ (this.source.buffer = t),
1668
+ (this.source.loop = !0),
1669
+ this.source.start();
1670
+ case 10:
1671
+ case "end":
1672
+ return e.stop();
1673
+ }
1674
+ },
1675
+ e,
1676
+ this,
1677
+ );
1678
+ }),
1679
+ )),
1680
+ function () {
1681
+ return U.apply(this, arguments);
1682
+ }),
1683
+ },
1684
+ {
1685
+ key: "createMediaStreamSourceNode",
1686
+ value:
1687
+ ((N = g(
1688
+ h().mark(function e() {
1689
+ var t,
1690
+ i,
1691
+ n,
1692
+ r,
1693
+ o,
1694
+ s,
1695
+ a = this;
1696
+ return h().wrap(
1697
+ function (e) {
1698
+ for (;;)
1699
+ switch ((e.prev = e.next)) {
1700
+ case 0:
1701
+ return (
1702
+ (e.prev = 0),
1703
+ (n = {
1704
+ channelCount: 1,
1705
+ noiseSuppression:
1706
+ void 0 !== this.noiseSuppression &&
1707
+ this.noiseSuppression,
1708
+ }),
1709
+ void 0 !== this.echoCancellation &&
1710
+ ((n.echoCancellation = this.echoCancellation),
1711
+ (n.googEchoCancellation = this.echoCancellation)),
1712
+ void 0 !== this.noiseSuppression &&
1713
+ (n.googNoiseSuppression = this.noiseSuppression),
1714
+ void 0 !== this.autoGainControl &&
1715
+ ((n.autoGainControl = this.autoGainControl),
1716
+ (n.googAutoGainControl = this.autoGainControl)),
1717
+ this._preferredDeviceId &&
1718
+ (n.deviceId = { exact: this._preferredDeviceId }),
1719
+ (e.next = 8),
1720
+ navigator.mediaDevices.getUserMedia({ audio: n })
1721
+ );
1722
+ case 8:
1723
+ (this.audioStream = e.sent),
1724
+ (this.audioContext &&
1725
+ "closed" !== this.audioContext.state) ||
1726
+ (this.audioContext = new AudioContext()),
1727
+ (this.source =
1728
+ this.audioContext.createMediaStreamSource(
1729
+ this.audioStream,
1730
+ )),
1731
+ (r = this.audioStream.getAudioTracks()[0]),
1732
+ (o =
1733
+ null !==
1734
+ (t =
1735
+ null === (i = r.getSettings) ||
1736
+ void 0 === i ||
1737
+ null === (i = i.call(r)) ||
1738
+ void 0 === i
1739
+ ? void 0
1740
+ : i.deviceId) && void 0 !== t
1741
+ ? t
1742
+ : r.label),
1743
+ this._originalDeviceId ||
1744
+ (this._originalDeviceId = o),
1745
+ this.trackEndedHandler &&
1746
+ (this.trackEndedHandler = null),
1747
+ (this.trackEndedHandler = g(
1748
+ h().mark(function e() {
1749
+ return h().wrap(function (e) {
1750
+ for (;;)
1751
+ switch ((e.prev = e.next)) {
1752
+ case 0:
1753
+ if (
1754
+ ((a.micNeedsRecovery = !0),
1755
+ a.onError(
1756
+ JSON.stringify({
1757
+ Type: "ERROR",
1758
+ Data: "Audio track ended. Possibly the mic was unplugged.",
1759
+ }),
1760
+ ),
1761
+ !a.isStreaming || a.isPaused)
1762
+ ) {
1763
+ e.next = 5;
1764
+ break;
1765
+ }
1766
+ return (
1767
+ (e.next = 5), a.recoverAudioGraph()
1768
+ );
1769
+ case 5:
1770
+ case "end":
1771
+ return e.stop();
1772
+ }
1773
+ }, e);
1774
+ }),
1775
+ )),
1776
+ r.addEventListener("ended", this.trackEndedHandler),
1777
+ (e.next = 24);
1778
+ break;
1779
+ case 19:
1780
+ (e.prev = 19),
1781
+ (e.t0 = e.catch(0)),
1782
+ (s = ""),
1783
+ "NotAllowedError" == e.t0.name
1784
+ ? (s = "Mic permission denied")
1785
+ : "NotFoundError" === e.t0.name
1786
+ ? (s = "No suitable media device found")
1787
+ : "NotReadableError" === e.t0.name &&
1788
+ (s =
1789
+ "Microphone is being used by another application"),
1790
+ this.onError(
1791
+ JSON.stringify({ Type: "ERROR", Data: s }),
1792
+ );
1793
+ case 24:
1794
+ case "end":
1795
+ return e.stop();
1796
+ }
1797
+ },
1798
+ e,
1799
+ this,
1800
+ [[0, 19]],
1801
+ );
1802
+ }),
1803
+ )),
1804
+ function () {
1805
+ return N.apply(this, arguments);
1806
+ }),
1807
+ },
1808
+ {
1809
+ key: "loadAudio",
1810
+ value:
1811
+ ((x = g(
1812
+ h().mark(function e() {
1813
+ var t, i, n;
1814
+ return h().wrap(
1815
+ function (e) {
1816
+ for (;;)
1817
+ switch ((e.prev = e.next)) {
1818
+ case 0:
1819
+ return (
1820
+ (e.prev = 0),
1821
+ (e.next = 3),
1822
+ fetch("./radiology_speed_test.wav")
1823
+ );
1824
+ case 3:
1825
+ return (t = e.sent), (e.next = 6), t.arrayBuffer();
1826
+ case 6:
1827
+ return (
1828
+ (i = e.sent),
1829
+ (e.next = 9),
1830
+ this.audioContext.decodeAudioData(i)
1831
+ );
1832
+ case 9:
1833
+ return (n = e.sent), e.abrupt("return", n);
1834
+ case 13:
1835
+ return (
1836
+ (e.prev = 13),
1837
+ (e.t0 = e.catch(0)),
1838
+ console.error(
1839
+ "Unable to fetch the audio file. Error: ".concat(
1840
+ e.t0.message,
1841
+ ),
1842
+ ),
1843
+ e.abrupt("return", null)
1844
+ );
1845
+ case 17:
1846
+ case "end":
1847
+ return e.stop();
1848
+ }
1849
+ },
1850
+ e,
1851
+ this,
1852
+ [[0, 13]],
1853
+ );
1854
+ }),
1855
+ )),
1856
+ function () {
1857
+ return x.apply(this, arguments);
1858
+ }),
1859
+ },
1860
+ {
1861
+ key: "createProcessorNode",
1862
+ value:
1863
+ ((O = g(
1864
+ h().mark(function e() {
1865
+ var t,
1866
+ i = this;
1867
+ return h().wrap(
1868
+ function (e) {
1869
+ for (;;)
1870
+ switch ((e.prev = e.next)) {
1871
+ case 0:
1872
+ return (
1873
+ (e.prev = 0),
1874
+ (e.next = 3),
1875
+ this.audioContext.audioWorklet.addModule(
1876
+ "data:application/javascript,".concat(
1877
+ encodeURIComponent(
1878
+ 'class MyAudioWorkletProcessor extends AudioWorkletProcessor {\n constructor() {\n super();\n this.accumulator = [];\n this.pauseSocketStreaming = false;\n this.sampleVal = 0;\n this.sampleSize = 0;\n this.intensityFrameCount = 0;\n this.reset();\n this.isProcessing = true;\n // message received from main-thread\n this.port.onmessage = (e) => {\n console.log("Augnito: Worklet received event - ", e.data);\n if (this.sampleSize > 0) {\n this.accumulator.push(this.sampleVal / this.sampleSize);\n }\n \n if (e.data == "PAUSE" || e.data == "STOP" || e.data == "PAUSESOCKET") {\n // append silence to get last word ASR.\n const silenceSize = 16000 * 2;\n for (let i = 0; i < silenceSize; i++) {\n this.accumulator.push(0.0003 * 0x7fff); // Push low-level noise instead of absolute silence to help ASR finalise\n }\n }\n this.send();\n this.reset();\n if (e.data == "STOP") {\n // message sent to main-thread\n this.port.postMessage({type:"DONE", value:"DONE"});\n this.isProcessing = false;\n \n }\n if(e.data == "PAUSESOCKET"){\n this.pauseSocketStreaming = true;\n this.port.postMessage("PAUSESOCKET");\n } else if(e.data == "RESUMESOCKET"){\n this.pauseSocketStreaming = false;\n } \n };\n }\n\n static get parameterDescriptors() {\n return [\n {\n name: "sampleRate",\n defaultValue: 16000,\n minValue: 16000,\n maxValue: 6 * 16000,\n },\n {\n name: "bufferSizeInterval",\n defaultValue: 1,\n minValue: 1,\n maxValue: 100,\n },\n {\n name: "pausedBufferInterval",\n defaultValue: 1,\n minValue: 0,\n maxValue: 100,\n },\n {\n name: "shouldReadIntensity",\n defaultValue: false,\n minValue: 0,\n maxValue: 1,\n },\n ];\n }\n\n // 128 frames\n process(inputList, outputList, params) {\n const input = inputList[0];\n if (input && input.length && input[0].length) {\n const channelData = input[0];\n const output = outputList[0];\n const inputSampleRate = params.sampleRate[0];\n const sampleRatio = inputSampleRate / 16000\n const bufferSizeInterval = params["bufferSizeInterval"][0];\n const pausedBufferInterval = params["pausedBufferInterval"][0];\n const shouldReadIntensity = params["shouldReadIntensity"][0];\n\n let sumSquares = 0; // For intensity\n let sampleCount = 0;\n\n // console.log("BufferSizeInterval", bufferSizeInterval);\n // Jackpot\n input[0].forEach((float32Element, index) => {\n const int16Element = Math.min(1, Math.max(-1, float32Element)) * 0x7fff;\n this.sampleVal += int16Element;\n this.sampleSize += 1;\n // Accumulate for intensity (RMS)\n sumSquares += float32Element * float32Element;\n sampleCount++;\n \n\n if (this.sampleSize >= sampleRatio) {\n const fraction = this.sampleSize - sampleRatio \n this.sampleVal -= fraction * int16Element;\n\n this.accumulator.push(this.sampleVal / sampleRatio);\n \n this.sampleVal = fraction * int16Element;\n this.sampleSize = fraction;\n }\n\n // Comment this when streaming microphone audio\n // output[0][index] = float32Element;\n });\n if(this.pauseSocketStreaming){\n if (this.accumulator.length >= 125 * 128 * pausedBufferInterval) {\n this.send();\n }\n } else{\n if (this.accumulator.length >= 125 * 128 * bufferSizeInterval) {\n this.send();\n }\n }\n if(shouldReadIntensity){\n \n // Throttled intensity post\n this.intensityFrameCount = (this.intensityFrameCount || 0) + 1;\n if (this.intensityFrameCount >= 15 && sampleCount > 0) {\n const rms = Math.sqrt(sumSquares / sampleCount);\n const normalized = Math.min(1, rms); // [0–1] scale\n this.port.postMessage({ type: \'intensity\', value: normalized });\n this.intensityFrameCount = 0;\n }\n }\n }\n return this.isProcessing;\n }\n\n send() {\n if (this.accumulator.length == 0) return;\n const audioData = new Int16Array(this.accumulator);\n // message sent to main-thread - transferrable\n this.port.postMessage({ type: \'audioData\', value: audioData.buffer }, [audioData.buffer]);\n this.accumulator = [];\n }\n\n reset() {\n this.sampleVal = 0;\n this.sampleSize = 0;\n }\n}\n\nregisterProcessor("worklet-processor", MyAudioWorkletProcessor);',
1879
+ ),
1880
+ ),
1881
+ )
1882
+ );
1883
+ case 3:
1884
+ (this.processorNode = new AudioWorkletNode(
1885
+ this.audioContext,
1886
+ "worklet-processor",
1887
+ )),
1888
+ this.processorNode.parameters
1889
+ .get("sampleRate")
1890
+ .setValueAtTime(
1891
+ this.audioContext.sampleRate,
1892
+ this.audioContext.currentTime,
1893
+ ),
1894
+ this.processorNode.parameters
1895
+ .get("bufferSizeInterval")
1896
+ .setValueAtTime(
1897
+ this.bufferSizeInterval,
1898
+ this.audioContext.currentTime,
1899
+ ),
1900
+ this.processorNode.parameters
1901
+ .get("pausedBufferInterval")
1902
+ .setValueAtTime(
1903
+ this.pausedBufferInterval,
1904
+ this.audioContext.currentTime,
1905
+ ),
1906
+ this.processorNode.parameters
1907
+ .get("shouldReadIntensity")
1908
+ .setValueAtTime(
1909
+ null !== (t = this.shouldReadIntensity) &&
1910
+ void 0 !== t &&
1911
+ t,
1912
+ this.audioContext.currentTime,
1913
+ ),
1914
+ (this.processorNode.port.onmessage = function (e) {
1915
+ var t = e.data,
1916
+ n = t.type,
1917
+ r = t.value;
1918
+ if (n == C)
1919
+ i.log(
1920
+ "Worklet processing done, clearing resources...",
1921
+ ),
1922
+ i.isDebug && i.saveAudio(),
1923
+ i.cleanup();
1924
+ else if (e.data == k) i.executor.Send(k);
1925
+ else {
1926
+ var o;
1927
+ "intensity" === n
1928
+ ? null === (o = i.onIntensity) ||
1929
+ void 0 === o ||
1930
+ o.call(i, r)
1931
+ : "audioData" === n &&
1932
+ i.isDebug &&
1933
+ new Int16Array(r).forEach(function (e) {
1934
+ i.audioData.length <= 288e5 &&
1935
+ i.audioData.push(e);
1936
+ });
1937
+ }
1938
+ i.executor &&
1939
+ (i.closeSocketWithoutEOS
1940
+ ? (i.executor.Send(A),
1941
+ (i.closeSocketWithoutEOS = !1))
1942
+ : "intensity" !== n && i.executor.Send(r));
1943
+ }),
1944
+ (e.next = 18);
1945
+ break;
1946
+ case 15:
1947
+ (e.prev = 15),
1948
+ (e.t0 = e.catch(0)),
1949
+ console.error(
1950
+ "Error: Unable to create worklet node: ",
1951
+ e.t0,
1952
+ );
1953
+ case 18:
1954
+ case "end":
1955
+ return e.stop();
1956
+ }
1957
+ },
1958
+ e,
1959
+ this,
1960
+ [[0, 15]],
1961
+ );
1962
+ }),
1963
+ )),
1964
+ function () {
1965
+ return O.apply(this, arguments);
1966
+ }),
1967
+ },
1968
+ {
1969
+ key: "PauseStream",
1970
+ value:
1971
+ ((_ = g(
1972
+ h().mark(function e() {
1973
+ return h().wrap(
1974
+ function (e) {
1975
+ for (;;)
1976
+ switch ((e.prev = e.next)) {
1977
+ case 0:
1978
+ if ("running" != this.audioContext.state) {
1979
+ e.next = 9;
1980
+ break;
1981
+ }
1982
+ if (this.shouldPreIntialiseRecorder) {
1983
+ e.next = 8;
1984
+ break;
1985
+ }
1986
+ return (e.next = 4), this.audioContext.suspend();
1987
+ case 4:
1988
+ this.log("Stream paused..."),
1989
+ this.processorNode.port.postMessage("PAUSE"),
1990
+ (e.next = 9);
1991
+ break;
1992
+ case 8:
1993
+ this.processorNode.port.postMessage(k);
1994
+ case 9:
1995
+ this.onStateChanged(!1),
1996
+ (this.isPaused = !0),
1997
+ (this.isStreaming = !1);
1998
+ case 12:
1999
+ case "end":
2000
+ return e.stop();
2001
+ }
2002
+ },
2003
+ e,
2004
+ this,
2005
+ );
2006
+ }),
2007
+ )),
2008
+ function () {
2009
+ return _.apply(this, arguments);
2010
+ }),
2011
+ },
2012
+ {
2013
+ key: "ResumeStream",
2014
+ value:
2015
+ ((T = g(
2016
+ h().mark(function e() {
2017
+ var t, i, n;
2018
+ return h().wrap(
2019
+ function (e) {
2020
+ for (;;)
2021
+ switch ((e.prev = e.next)) {
2022
+ case 0:
2023
+ if (
2024
+ (n =
2025
+ null === (t = this.audioStream) ||
2026
+ void 0 === t ||
2027
+ null === (i = t.getAudioTracks) ||
2028
+ void 0 === i
2029
+ ? void 0
2030
+ : i.call(t)[0]) &&
2031
+ "ended" !== n.readyState &&
2032
+ !this.micNeedsRecovery
2033
+ ) {
2034
+ e.next = 5;
2035
+ break;
2036
+ }
2037
+ return (e.next = 5), this.recoverAudioGraph();
2038
+ case 5:
2039
+ if (!this.IsMicrophoneMuted) {
2040
+ e.next = 11;
2041
+ break;
2042
+ }
2043
+ if (
2044
+ !this.audioContext ||
2045
+ "running" !== this.audioContext.state
2046
+ ) {
2047
+ e.next = 9;
2048
+ break;
2049
+ }
2050
+ return (e.next = 9), this.audioContext.suspend();
2051
+ case 9:
2052
+ return (
2053
+ this.onError(
2054
+ JSON.stringify({
2055
+ Type: "ERROR",
2056
+ Data: "Microphone is muted.",
2057
+ }),
2058
+ ),
2059
+ e.abrupt("return")
2060
+ );
2061
+ case 11:
2062
+ if (!this.shouldPreIntialiseRecorder) {
2063
+ e.next = 16;
2064
+ break;
2065
+ }
2066
+ this.processorNode.port.postMessage(E),
2067
+ this.executor.Send(E),
2068
+ (e.next = 20);
2069
+ break;
2070
+ case 16:
2071
+ if ("suspended" !== this.audioContext.state) {
2072
+ e.next = 19;
2073
+ break;
2074
+ }
2075
+ return (e.next = 19), this.audioContext.resume();
2076
+ case 19:
2077
+ this.log("Stream resumed...");
2078
+ case 20:
2079
+ this.onStateChanged(!0),
2080
+ (this.isPaused = !1),
2081
+ (this.isStreaming = !0);
2082
+ case 23:
2083
+ case "end":
2084
+ return e.stop();
2085
+ }
2086
+ },
2087
+ e,
2088
+ this,
2089
+ );
2090
+ }),
2091
+ )),
2092
+ function () {
2093
+ return T.apply(this, arguments);
2094
+ }),
2095
+ },
2096
+ {
2097
+ key: "IsPaused",
2098
+ get: function () {
2099
+ return this.isPaused;
2100
+ },
2101
+ },
2102
+ {
2103
+ key: "IsStreaming",
2104
+ get: function () {
2105
+ return this.isStreaming;
2106
+ },
2107
+ },
2108
+ {
2109
+ key: "IsMicrophoneMuted",
2110
+ get: function () {
2111
+ var e,
2112
+ t,
2113
+ i =
2114
+ null === (e = this.audioStream) ||
2115
+ void 0 === e ||
2116
+ null === (t = e.getAudioTracks) ||
2117
+ void 0 === t
2118
+ ? void 0
2119
+ : t.call(e)[0];
2120
+ return !i || i.muted || "ended" === i.readyState;
2121
+ },
2122
+ },
2123
+ {
2124
+ key: "StopStream",
2125
+ value:
2126
+ ((D = g(
2127
+ h().mark(function e(t) {
2128
+ var i, n, r, o, s, a, c, u;
2129
+ return h().wrap(
2130
+ function (e) {
2131
+ for (;;)
2132
+ switch ((e.prev = e.next)) {
2133
+ case 0:
2134
+ if (
2135
+ "suspended" ===
2136
+ (null === (i = this.audioContext) || void 0 === i
2137
+ ? void 0
2138
+ : i.state)
2139
+ ) {
2140
+ e.next = 4;
2141
+ break;
2142
+ }
2143
+ return (
2144
+ (e.next = 3),
2145
+ null === (c = this.audioContext) || void 0 === c
2146
+ ? void 0
2147
+ : c.suspend()
2148
+ );
2149
+ case 3:
2150
+ this.onStateChanged(!1);
2151
+ case 4:
2152
+ this.log("Stream stopped..."),
2153
+ (this.isStreaming = !1),
2154
+ (this.isPaused = !1),
2155
+ (this.closeSocketWithoutEOS = !t),
2156
+ this.deviceChangeHandler &&
2157
+ (navigator.mediaDevices.removeEventListener(
2158
+ "devicechange",
2159
+ this.deviceChangeHandler,
2160
+ ),
2161
+ (this.deviceChangeHandler = null)),
2162
+ (u =
2163
+ null === (n = this.audioStream) ||
2164
+ void 0 === n ||
2165
+ null === (r = n.getAudioTracks) ||
2166
+ void 0 === r
2167
+ ? void 0
2168
+ : r.call(n)[0]) &&
2169
+ this.trackEndedHandler &&
2170
+ u.removeEventListener(
2171
+ "ended",
2172
+ this.trackEndedHandler,
2173
+ ),
2174
+ (this.trackEndedHandler = null),
2175
+ null === (o = this.audioStream) ||
2176
+ void 0 === o ||
2177
+ null === (s = o.getTracks) ||
2178
+ void 0 === s ||
2179
+ null === (s = s.call(o)) ||
2180
+ void 0 === s ||
2181
+ s.forEach(function (e) {
2182
+ try {
2183
+ e.stop();
2184
+ } catch (e) {}
2185
+ }),
2186
+ null === (a = this.processorNode) ||
2187
+ void 0 === a ||
2188
+ null === (a = a.port) ||
2189
+ void 0 === a ||
2190
+ a.postMessage("STOP");
2191
+ case 14:
2192
+ case "end":
2193
+ return e.stop();
2194
+ }
2195
+ },
2196
+ e,
2197
+ this,
2198
+ );
2199
+ }),
2200
+ )),
2201
+ function (e) {
2202
+ return D.apply(this, arguments);
2203
+ }),
2204
+ },
2205
+ {
2206
+ key: "recoverAudioGraph",
2207
+ value:
2208
+ ((P = g(
2209
+ h().mark(function e() {
2210
+ var t,
2211
+ i,
2212
+ n,
2213
+ r,
2214
+ o,
2215
+ s,
2216
+ a,
2217
+ c,
2218
+ u,
2219
+ l,
2220
+ d = this;
2221
+ return h().wrap(
2222
+ function (e) {
2223
+ for (;;)
2224
+ switch ((e.prev = e.next)) {
2225
+ case 0:
2226
+ if (!this.isRecovering) {
2227
+ e.next = 2;
2228
+ break;
2229
+ }
2230
+ return e.abrupt("return");
2231
+ case 2:
2232
+ (this.isRecovering = !0),
2233
+ (e.prev = 3),
2234
+ null === (t = this.audioStream) ||
2235
+ void 0 === t ||
2236
+ null === (t = t.getTracks()) ||
2237
+ void 0 === t ||
2238
+ t.forEach(function (e) {
2239
+ try {
2240
+ e.stop();
2241
+ } catch (e) {}
2242
+ });
2243
+ try {
2244
+ null === (s = this.source) ||
2245
+ void 0 === s ||
2246
+ s.disconnect();
2247
+ } catch (e) {}
2248
+ try {
2249
+ null === (a = this.processorNode) ||
2250
+ void 0 === a ||
2251
+ a.disconnect();
2252
+ } catch (e) {}
2253
+ return (e.next = 9), this.createMediaStreamSourceNode();
2254
+ case 9:
2255
+ if (this.source) {
2256
+ e.next = 11;
2257
+ break;
2258
+ }
2259
+ throw new Error("Failed to recreate source");
2260
+ case 11:
2261
+ if (
2262
+ ((this.audioContext &&
2263
+ "closed" !== this.audioContext.state) ||
2264
+ (this.audioContext = new AudioContext()),
2265
+ "suspended" !== this.audioContext.state)
2266
+ ) {
2267
+ e.next = 15;
2268
+ break;
2269
+ }
2270
+ return (e.next = 15), this.audioContext.resume();
2271
+ case 15:
2272
+ return (e.next = 17), this.createProcessorNode();
2273
+ case 17:
2274
+ if (
2275
+ (this.source
2276
+ .connect(this.processorNode)
2277
+ .connect(this.audioContext.destination),
2278
+ this.isStreaming && !this.isPaused)
2279
+ ) {
2280
+ e.next = 22;
2281
+ break;
2282
+ }
2283
+ if ("running" !== this.audioContext.state) {
2284
+ e.next = 22;
2285
+ break;
2286
+ }
2287
+ return (e.next = 22), this.audioContext.suspend();
2288
+ case 22:
2289
+ (this.micNeedsRecovery = !1),
2290
+ (c =
2291
+ null === (i = this.audioStream) ||
2292
+ void 0 === i ||
2293
+ null === (n = i.getAudioTracks) ||
2294
+ void 0 === n
2295
+ ? void 0
2296
+ : n.call(i)[0]),
2297
+ (u =
2298
+ null !==
2299
+ (r =
2300
+ null == c ||
2301
+ null === (o = c.getSettings) ||
2302
+ void 0 === o ||
2303
+ null === (o = o.call(c)) ||
2304
+ void 0 === o
2305
+ ? void 0
2306
+ : o.deviceId) && void 0 !== r
2307
+ ? r
2308
+ : null == c
2309
+ ? void 0
2310
+ : c.label),
2311
+ (l =
2312
+ !!this._originalDeviceId &&
2313
+ u === this._originalDeviceId),
2314
+ console.log(
2315
+ "Recovered device ID: "
2316
+ .concat(u, ", Original device ID: ")
2317
+ .concat(
2318
+ this._originalDeviceId,
2319
+ ", Is original device reconnected: ",
2320
+ )
2321
+ .concat(l),
2322
+ ),
2323
+ !this.isPaused ||
2324
+ (this.IsMicrophoneMuted && !l) ||
2325
+ (this.onMicReady &&
2326
+ !this._micReadyFired &&
2327
+ ((this._micReadyFired = !0),
2328
+ setTimeout(function () {
2329
+ d._micReadyFired = !1;
2330
+ }, 300),
2331
+ this.onMicReady())),
2332
+ this.log("Audio graph recovery completed"),
2333
+ (e.next = 34);
2334
+ break;
2335
+ case 31:
2336
+ (e.prev = 31),
2337
+ (e.t0 = e.catch(3)),
2338
+ console.error("Recovery failed", e.t0);
2339
+ case 34:
2340
+ return (
2341
+ (e.prev = 34), (this.isRecovering = !1), e.finish(34)
2342
+ );
2343
+ case 37:
2344
+ case "end":
2345
+ return e.stop();
2346
+ }
2347
+ },
2348
+ e,
2349
+ this,
2350
+ [[3, 31, 34, 37]],
2351
+ );
2352
+ }),
2353
+ )),
2354
+ function () {
2355
+ return P.apply(this, arguments);
2356
+ }),
2357
+ },
2358
+ {
2359
+ key: "IntentStartStream",
2360
+ value: function () {
2361
+ this.executor.Send("INTENT_START_STREAM");
2362
+ },
2363
+ },
2364
+ {
2365
+ key: "cleanup",
2366
+ value: function () {
2367
+ var e;
2368
+ null === (e = this.audioStream) ||
2369
+ void 0 === e ||
2370
+ null === (e = e.getTracks()) ||
2371
+ void 0 === e ||
2372
+ e.forEach(function (e) {
2373
+ try {
2374
+ e.stop();
2375
+ } catch (e) {}
2376
+ }),
2377
+ this.source.disconnect(),
2378
+ this.processorNode.disconnect(),
2379
+ this.processorNode.port.close(),
2380
+ this.audioContext.close(),
2381
+ (this.audioData = []);
2382
+ },
2383
+ },
2384
+ {
2385
+ key: "saveAudio",
2386
+ value: function () {
2387
+ var e = this.encodeWAV(),
2388
+ t = URL.createObjectURL(new Blob([e], { type: "audio/wav" }));
2389
+ this.log("Download Recording: ".concat(t));
2390
+ },
2391
+ },
2392
+ {
2393
+ key: "getBlob",
2394
+ value: function () {
2395
+ var e = this.encodeWAV();
2396
+ return new Blob([e], { type: "audio/wav" });
2397
+ },
2398
+ },
2399
+ {
2400
+ key: "encodeWAV",
2401
+ value: function () {
2402
+ var e = new DataView(new ArrayBuffer(2 * this.audioData.length));
2403
+ this.audioData.forEach(function (t, i) {
2404
+ e.setInt16(2 * i, t, !0);
2405
+ });
2406
+ var t = e.buffer.byteLength,
2407
+ i = 44 + t,
2408
+ n = new DataView(new ArrayBuffer(i));
2409
+ n.setUint32(0, 1380533830, !1),
2410
+ n.setUint32(4, i - 8, !0),
2411
+ n.setUint32(8, 1463899717, !1),
2412
+ n.setUint32(12, 1718449184, !1),
2413
+ n.setUint32(16, 16, !0),
2414
+ n.setUint16(20, 1, !0),
2415
+ n.setUint16(22, 1, !0),
2416
+ n.setUint32(24, 16e3, !0),
2417
+ n.setUint32(28, 32e3, !0),
2418
+ n.setUint16(32, 2, !0),
2419
+ n.setUint16(34, 16, !0),
2420
+ n.setUint32(36, 1684108385, !1),
2421
+ n.setUint32(40, t, !0);
2422
+ for (var r = 0; r < t; r++) n.setInt8(44 + r, e.getInt8(r));
2423
+ return n;
2424
+ },
2425
+ },
2426
+ {
2427
+ key: "log",
2428
+ value: function (e) {
2429
+ if (this.enableLogs) {
2430
+ var t = ""
2431
+ .concat(new Date().toLocaleTimeString(), " Augnito: ")
2432
+ .concat(e);
2433
+ console.log(t + "\n");
2434
+ }
2435
+ },
2436
+ },
2437
+ ],
2438
+ );
2439
+ function K(e) {
2440
+ return j.apply(this, arguments);
2441
+ }
2442
+ function j() {
2443
+ return (
2444
+ (j = g(
2445
+ h().mark(function e(t) {
2446
+ var i,
2447
+ n,
2448
+ r,
2449
+ o,
2450
+ s,
2451
+ a,
2452
+ c,
2453
+ u,
2454
+ l,
2455
+ d = arguments;
2456
+ return h().wrap(
2457
+ function (e) {
2458
+ for (;;)
2459
+ switch ((e.prev = e.next)) {
2460
+ case 0:
2461
+ return (
2462
+ (i = d.length > 1 && void 0 !== d[1] ? d[1] : 350),
2463
+ (n = d.length > 2 && void 0 !== d[2] ? d[2] : 0.01),
2464
+ (r = null),
2465
+ (o = null),
2466
+ (e.prev = 4),
2467
+ (e.next = 7),
2468
+ navigator.mediaDevices.getUserMedia({
2469
+ audio: { deviceId: { exact: t }, channelCount: 1 },
2470
+ })
2471
+ );
2472
+ case 7:
2473
+ return (
2474
+ (r = e.sent),
2475
+ (o = new AudioContext()),
2476
+ (s = o.createMediaStreamSource(r)),
2477
+ ((a = o.createAnalyser()).fftSize = 256),
2478
+ s.connect(a),
2479
+ (c = a.frequencyBinCount),
2480
+ (u = new Float32Array(c)),
2481
+ (e.next = 17),
2482
+ new Promise(function (e) {
2483
+ var t = 0,
2484
+ r = performance.now();
2485
+ requestAnimationFrame(function o() {
2486
+ a.getFloatTimeDomainData(u);
2487
+ for (var s = 0, l = 0; l < c; l++) s += u[l] * u[l];
2488
+ var d = Math.sqrt(s / c);
2489
+ d > t && (t = d),
2490
+ performance.now() - r < i
2491
+ ? requestAnimationFrame(o)
2492
+ : e(t > n);
2493
+ });
2494
+ })
2495
+ );
2496
+ case 17:
2497
+ return e.abrupt("return", e.sent);
2498
+ case 20:
2499
+ return (
2500
+ (e.prev = 20), (e.t0 = e.catch(4)), e.abrupt("return", !1)
2501
+ );
2502
+ case 23:
2503
+ return (
2504
+ (e.prev = 23),
2505
+ null === (l = r) ||
2506
+ void 0 === l ||
2507
+ l.getTracks().forEach(function (e) {
2508
+ return e.stop();
2509
+ }),
2510
+ o &&
2511
+ "closed" !== o.state &&
2512
+ o.close().catch(function () {}),
2513
+ e.finish(23)
2514
+ );
2515
+ case 27:
2516
+ case "end":
2517
+ return e.stop();
2518
+ }
2519
+ },
2520
+ e,
2521
+ null,
2522
+ [[4, 20, 23, 27]],
2523
+ );
2524
+ }),
2525
+ )),
2526
+ j.apply(this, arguments)
2527
+ );
2528
+ }
2529
+ function W(e) {
2530
+ return G.apply(this, arguments);
2531
+ }
2532
+ function G() {
2533
+ return (G = g(
2534
+ h().mark(function e(t) {
2535
+ var i, n, r, o, s;
2536
+ return h().wrap(
2537
+ function (e) {
2538
+ for (;;)
2539
+ switch ((e.prev = e.next)) {
2540
+ case 0:
2541
+ return (
2542
+ (e.prev = 1),
2543
+ (e.next = 4),
2544
+ navigator.mediaDevices.enumerateDevices()
2545
+ );
2546
+ case 4:
2547
+ (i = e.sent), (e.next = 10);
2548
+ break;
2549
+ case 7:
2550
+ return (
2551
+ (e.prev = 7), (e.t0 = e.catch(1)), e.abrupt("return", null)
2552
+ );
2553
+ case 10:
2554
+ (n = i.filter(function (e) {
2555
+ return "audioinput" === e.kind && e.deviceId !== t;
2556
+ })),
2557
+ (r = S(n)),
2558
+ (e.prev = 12),
2559
+ r.s();
2560
+ case 14:
2561
+ if ((o = r.n()).done) {
2562
+ e.next = 23;
2563
+ break;
2564
+ }
2565
+ return (s = o.value), (e.next = 18), K(s.deviceId);
2566
+ case 18:
2567
+ if (!e.sent) {
2568
+ e.next = 21;
2569
+ break;
2570
+ }
2571
+ return e.abrupt("return", s.deviceId);
2572
+ case 21:
2573
+ e.next = 14;
2574
+ break;
2575
+ case 23:
2576
+ e.next = 28;
2577
+ break;
2578
+ case 25:
2579
+ (e.prev = 25), (e.t1 = e.catch(12)), r.e(e.t1);
2580
+ case 28:
2581
+ return (e.prev = 28), r.f(), e.finish(28);
2582
+ case 31:
2583
+ return e.abrupt("return", null);
2584
+ case 32:
2585
+ case "end":
2586
+ return e.stop();
2587
+ }
2588
+ },
2589
+ e,
2590
+ null,
2591
+ [
2592
+ [1, 7],
2593
+ [12, 25, 28, 31],
2594
+ ],
2595
+ );
2596
+ }),
2597
+ )).apply(this, arguments);
2598
+ }
2599
+ var F = (function () {
2600
+ function e() {
2601
+ var t,
2602
+ i,
2603
+ n,
2604
+ r,
2605
+ o =
2606
+ arguments.length > 0 && void 0 !== arguments[0]
2607
+ ? arguments[0]
2608
+ : {
2609
+ serverURL: "",
2610
+ enableLogs: !1,
2611
+ isDebug: !1,
2612
+ bufferInterval: 1,
2613
+ pausedBufferInterval: 1,
2614
+ EOS_Message: void 0,
2615
+ socketTimeoutInterval: void 0,
2616
+ shouldSendAudioDataSequence: !1,
2617
+ reconnectAudioDuration: 0,
2618
+ shouldPreIntialiseRecorder: !1,
2619
+ shouldReadIntensity: !1,
2620
+ debounceDelay: 300,
2621
+ switchToRegularSpeechProfile: !1,
2622
+ echoCancellation: void 0,
2623
+ noiseSuppression: void 0,
2624
+ autoGainControl: void 0,
2625
+ },
2626
+ s = arguments.length > 1 ? arguments[1] : void 0;
2627
+ if ((v(this, e), e.instance)) return e.instance;
2628
+ (this.WebsocketURL = null !== (t = o.serverURL) && void 0 !== t ? t : ""),
2629
+ (this.enableLogs = o.enableLogs),
2630
+ (this.isDebug = o.isDebug),
2631
+ (this.streamer = null),
2632
+ (this.streamerNotStarted = !1),
2633
+ (this.isStreamerStarting = !1),
2634
+ (this.pendingStartStream = !1),
2635
+ (this.heavyOp = s),
2636
+ (this.bufferInterval = o.bufferInterval),
2637
+ (this.pausedBufferInterval = o.pausedBufferInterval),
2638
+ (this.eosMessage = o.EOS_Message),
2639
+ (this.socketTimeoutInterval = o.socketTimeoutInterval),
2640
+ (this.shouldSendAudioDataSequence = o.shouldSendAudioDataSequence),
2641
+ (this.reconnectAudioDuration =
2642
+ null !== (i = o.reconnectAudioDuration) && void 0 !== i ? i : 0),
2643
+ (this.shouldPreIntialiseRecorder = o.shouldPreIntialiseRecorder),
2644
+ (this.switchToRegularSpeechProfile =
2645
+ null !== (n = o.switchToRegularSpeechProfile) && void 0 !== n && n),
2646
+ (this._echoCancellation = o.echoCancellation),
2647
+ (this._noiseSuppression = o.noiseSuppression),
2648
+ (this._autoGainControl = o.autoGainControl),
2649
+ this.shouldPreIntialiseRecorder &&
2650
+ (this.initialiseStreamer(), (this.streamerNotStarted = !0)),
2651
+ (this.shouldReadIntensity = o.shouldReadIntensity),
2652
+ (this.delay = null !== (r = o.debounceDelay) && void 0 !== r ? r : 300),
2653
+ (this.toggleStartStopAudioStream = B(
2654
+ this.toggleStartStopAudioStream.bind(this),
2655
+ this.delay,
2656
+ )),
2657
+ (this.togglePauseResumeAudioStream = B(
2658
+ this.togglePauseResumeAudioStream.bind(this),
2659
+ this.delay,
2660
+ )),
2661
+ (this.needsDispose = !1),
2662
+ (e.instance = this);
2663
+ }
2664
+ return m(e, [
2665
+ {
2666
+ key: "echoCancellation",
2667
+ get: function () {
2668
+ return this._echoCancellation;
2669
+ },
2670
+ set: function (e) {
2671
+ (this._echoCancellation = e),
2672
+ this.streamer && (this.streamer.echoCancellation = e);
2673
+ },
2674
+ },
2675
+ {
2676
+ key: "noiseSuppression",
2677
+ get: function () {
2678
+ return this._noiseSuppression;
2679
+ },
2680
+ set: function (e) {
2681
+ (this._noiseSuppression = e),
2682
+ this.streamer && (this.streamer.noiseSuppression = e);
2683
+ },
2684
+ },
2685
+ {
2686
+ key: "autoGainControl",
2687
+ get: function () {
2688
+ return this._autoGainControl;
2689
+ },
2690
+ set: function (e) {
2691
+ (this._autoGainControl = e),
2692
+ this.streamer && (this.streamer.autoGainControl = e);
2693
+ },
2694
+ },
2695
+ {
2696
+ key: "initialiseStreamer",
2697
+ value: function () {
2698
+ this.streamer = new J(
2699
+ this.WebsocketURL,
2700
+ this.enableLogs,
2701
+ this.isDebug,
2702
+ this.bufferInterval,
2703
+ this.pausedBufferInterval,
2704
+ this.eosMessage,
2705
+ this.socketTimeoutInterval,
2706
+ this.shouldSendAudioDataSequence,
2707
+ this.reconnectAudioDuration,
2708
+ this.shouldPreIntialiseRecorder,
2709
+ this.shouldReadIntensity,
2710
+ this.switchToRegularSpeechProfile,
2711
+ this._echoCancellation,
2712
+ this._noiseSuppression,
2713
+ this._autoGainControl,
2714
+ this.heavyOp,
2715
+ this.onFinalResultCallback.bind(this),
2716
+ this.onPartialResultCallback.bind(this),
2717
+ this.onErrorCallback.bind(this),
2718
+ this.onStateChangedCallback.bind(this),
2719
+ this.onSessionEventCallback.bind(this),
2720
+ this.onOtherResultCallback.bind(this),
2721
+ this.onSpeechResponseCallback.bind(this),
2722
+ this.onIntensityCallback.bind(this),
2723
+ this.onJobStatusCallback.bind(this),
2724
+ this.onMicReadyCallback.bind(this),
2725
+ );
2726
+ },
2727
+ },
2728
+ {
2729
+ key: "updateIntentStartStream",
2730
+ value: function () {
2731
+ var e;
2732
+ (this.pendingStartStream = !0),
2733
+ null === (e = this.streamer) || void 0 === e || e.IntentStartStream();
2734
+ },
2735
+ },
2736
+ {
2737
+ key: "togglePauseResumeAudioStream",
2738
+ value: function () {
2739
+ var e =
2740
+ arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0,
2741
+ t =
2742
+ arguments.length > 1 && void 0 !== arguments[1]
2743
+ ? arguments[1]
2744
+ : void 0;
2745
+ !this.streamer || this.streamerNotStarted
2746
+ ? (t && (this.WebsocketURL = t), this.startAudio(e))
2747
+ : this.streamer.IsPaused
2748
+ ? this.resumeAudio()
2749
+ : this.pauseAudio();
2750
+ },
2751
+ },
2752
+ {
2753
+ key: "toggleStartStopAudioStream",
2754
+ value: function () {
2755
+ var e =
2756
+ arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0,
2757
+ t =
2758
+ arguments.length > 1 && void 0 !== arguments[1]
2759
+ ? arguments[1]
2760
+ : void 0;
2761
+ !this.streamer || this.streamerNotStarted
2762
+ ? (t && (this.WebsocketURL = t), this.startAudio(e))
2763
+ : this.stopAudio();
2764
+ },
2765
+ },
2766
+ {
2767
+ key: "startAudio",
2768
+ value:
2769
+ ((t = g(
2770
+ h().mark(function e(t) {
2771
+ return h().wrap(
2772
+ function (e) {
2773
+ for (;;)
2774
+ switch ((e.prev = e.next)) {
2775
+ case 0:
2776
+ if (!this.isStreamerStarting) {
2777
+ e.next = 2;
2778
+ break;
2779
+ }
2780
+ return e.abrupt("return");
2781
+ case 2:
2782
+ return (
2783
+ (this.isStreamerStarting = !0),
2784
+ (this.shouldPreIntialiseRecorder && this.streamer) ||
2785
+ this.initialiseStreamer(),
2786
+ (e.prev = 4),
2787
+ (e.next = 7),
2788
+ this.streamer.StartStream(t, this.WebsocketURL)
2789
+ );
2790
+ case 7:
2791
+ e.sent
2792
+ ? ((this.streamerNotStarted = !1),
2793
+ this.log("Stream Started..."))
2794
+ : (this.streamer = null);
2795
+ case 9:
2796
+ return (
2797
+ (e.prev = 9),
2798
+ (this.isStreamerStarting = !1),
2799
+ e.finish(9)
2800
+ );
2801
+ case 12:
2802
+ case "end":
2803
+ return e.stop();
2804
+ }
2805
+ },
2806
+ e,
2807
+ this,
2808
+ [[4, , 9, 12]],
2809
+ );
2810
+ }),
2811
+ )),
2812
+ function (e) {
2813
+ return t.apply(this, arguments);
2814
+ }),
2815
+ },
2816
+ {
2817
+ key: "pauseAudio",
2818
+ value: function () {
2819
+ this.streamer.PauseStream(), this.log("Stream Paused...");
2820
+ },
2821
+ },
2822
+ {
2823
+ key: "resumeAudio",
2824
+ value: function () {
2825
+ this.streamer.ResumeStream(),
2826
+ this.enableLogs && this.log("Stream Resumed...");
2827
+ },
2828
+ },
2829
+ {
2830
+ key: "stopAudio",
2831
+ value: function () {
2832
+ var e,
2833
+ t,
2834
+ i = this,
2835
+ n =
2836
+ !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0],
2837
+ r = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
2838
+ ((null !== (e = this.streamer) && void 0 !== e && e.IsStreaming) ||
2839
+ r) &&
2840
+ (null === (t = this.streamer) || void 0 === t || t.StopStream(n),
2841
+ (this.streamer = null),
2842
+ this.log("Stream Stopped..."),
2843
+ this.shouldPreIntialiseRecorder &&
2844
+ setTimeout(function () {
2845
+ i.needsDispose
2846
+ ? (i.needsDispose = !1)
2847
+ : (i.initialiseStreamer(), (i.streamerNotStarted = !0));
2848
+ }, 500));
2849
+ },
2850
+ },
2851
+ {
2852
+ key: "getBlob",
2853
+ value: function () {
2854
+ var e = this.streamer.getBlob();
2855
+ return this.log("Blob Sent..."), e;
2856
+ },
2857
+ },
2858
+ {
2859
+ key: "log",
2860
+ value: function (e) {
2861
+ if (this.enableLogs) {
2862
+ var t = ""
2863
+ .concat(new Date().toLocaleTimeString(), " Augnito: ")
2864
+ .concat(e);
2865
+ this.showLogCallback(t + "\n");
2866
+ }
2867
+ },
2868
+ },
2869
+ {
2870
+ key: "dispose",
2871
+ value: function () {
2872
+ var t;
2873
+ (this.needsDispose = !0),
2874
+ null === (t = this.streamer) || void 0 === t || t.StopStream(!1),
2875
+ (this.streamer = null),
2876
+ (e.instance = null);
2877
+ },
2878
+ },
2879
+ {
2880
+ key: "onSessionEventCallback",
2881
+ value: function (e) {
2882
+ this.onSessionEvent && this.onSessionEvent(e);
2883
+ },
2884
+ },
2885
+ {
2886
+ key: "onStateChangedCallback",
2887
+ value: function (e) {
2888
+ this.onStateChanged && this.onStateChanged(e);
2889
+ },
2890
+ },
2891
+ {
2892
+ key: "onIntensityCallback",
2893
+ value: function (e) {
2894
+ this.onIntensity && this.onIntensity(e);
2895
+ },
2896
+ },
2897
+ {
2898
+ key: "onErrorCallback",
2899
+ value: function (e) {
2900
+ this.onError && this.onError(e);
2901
+ },
2902
+ },
2903
+ {
2904
+ key: "onPartialResultCallback",
2905
+ value: function (e) {
2906
+ this.onPartialResult && this.onPartialResult(e);
2907
+ },
2908
+ },
2909
+ {
2910
+ key: "onFinalResultCallback",
2911
+ value: function (e) {
2912
+ this.onFinalResult && this.onFinalResult(e);
2913
+ },
2914
+ },
2915
+ {
2916
+ key: "onOtherResultCallback",
2917
+ value: function (e) {
2918
+ this.onOtherResults && this.onOtherResults(e);
2919
+ },
2920
+ },
2921
+ {
2922
+ key: "onSpeechResponseCallback",
2923
+ value: function (e) {
2924
+ this.onSpeechResponse && this.onSpeechResponse(e);
2925
+ },
2926
+ },
2927
+ {
2928
+ key: "onJobStatusCallback",
2929
+ value: function (e) {
2930
+ this.onJobStatus && this.onJobStatus(e);
2931
+ },
2932
+ },
2933
+ {
2934
+ key: "onMicReadyCallback",
2935
+ value: function () {
2936
+ this.onMicReady && this.onMicReady();
2937
+ },
2938
+ },
2939
+ {
2940
+ key: "showLogCallback",
2941
+ value: function (e) {
2942
+ this.showLog && this.showLog(e);
2943
+ },
2944
+ },
2945
+ ]);
2946
+ var t;
2947
+ })();
2948
+ function B(e, t) {
2949
+ var i;
2950
+ return function () {
2951
+ for (
2952
+ var n = this, r = arguments.length, o = new Array(r), s = 0;
2953
+ s < r;
2954
+ s++
2955
+ )
2956
+ o[s] = arguments[s];
2957
+ i && clearTimeout(i),
2958
+ (i = setTimeout(function () {
2959
+ return e.apply(n, o);
2960
+ }, t));
2961
+ };
2962
+ }
2963
+ class V extends u {
2964
+ constructor(e) {
2965
+ super(),
2966
+ Object.defineProperty(this, "_config", {
2967
+ enumerable: !0,
2968
+ configurable: !0,
2969
+ writable: !0,
2970
+ value: e,
2971
+ }),
2972
+ Object.defineProperty(this, "_baseUrl", {
2973
+ enumerable: !0,
2974
+ configurable: !0,
2975
+ writable: !0,
2976
+ value: void 0,
2977
+ }),
2978
+ (this._baseUrl = `https://${e.server}/pace/v1/sdk`);
2979
+ }
2980
+ getURL(e) {
2981
+ return `${this._baseUrl}${e}`;
2982
+ }
2983
+ getNoteParams() {
2984
+ return e(this, void 0, void 0, function* () {
2985
+ const e = this.getURL("/noteparams"),
2986
+ t = {
2987
+ SubscriptionCode: this._config.subscriptionCode,
2988
+ AccessKey: this._config.accessKey,
2989
+ UserTag: this._config.userTag,
2990
+ };
2991
+ return yield this.makePostRequest(e, t);
2992
+ });
2993
+ }
2994
+ getSettingsConfigMaster(t) {
2995
+ return e(this, void 0, void 0, function* () {
2996
+ const e = this.getURL("/configmaster"),
2997
+ i = {
2998
+ SubscriptionCode: this._config.subscriptionCode,
2999
+ AccessKey: this._config.accessKey,
3000
+ UserTag: this._config.userTag,
3001
+ ConfigTypeId: t,
3002
+ };
3003
+ return yield this.makePostRequest(e, i);
3004
+ });
3005
+ }
3006
+ getOrgConfigMapping(t) {
3007
+ return e(this, void 0, void 0, function* () {
3008
+ const e = this.getURL("/configmapping").replace("/v1", "/v2"),
3009
+ i = {
3010
+ SubscriptionCode: this._config.subscriptionCode,
3011
+ AccessKey: this._config.accessKey,
3012
+ UserTag: this._config.userTag,
3013
+ ConfigTypeId: t,
3014
+ };
3015
+ return yield this.makePostRequest(e, i);
3016
+ });
3017
+ }
3018
+ getUserConfigSettings(t) {
3019
+ return e(this, void 0, void 0, function* () {
3020
+ const e = this.getURL("/userconfigmapping"),
3021
+ i = {
3022
+ SubscriptionCode: this._config.subscriptionCode,
3023
+ AccessKey: this._config.accessKey,
3024
+ UserTag: this._config.userTag,
3025
+ ConfigTypeId: t,
3026
+ };
3027
+ return yield this.makePostRequest(e, i);
3028
+ });
3029
+ }
3030
+ updateUserConfig(t) {
3031
+ return e(this, void 0, void 0, function* () {
3032
+ const e = this.getURL("/userconfigmapping"),
3033
+ i = {
3034
+ SubscriptionCode: this._config.subscriptionCode,
3035
+ AccessKey: this._config.accessKey,
3036
+ UserTag: this._config.userTag,
3037
+ UserConfigMapping: t,
3038
+ };
3039
+ return yield this.makePatchRequest(e, i);
3040
+ });
3041
+ }
3042
+ getUserPreferences() {
3043
+ return e(this, void 0, void 0, function* () {
3044
+ const e = this.getURL("/getuserpreferences"),
3045
+ t = {
3046
+ SubscriptionCode: this._config.subscriptionCode,
3047
+ AccessKey: this._config.accessKey,
3048
+ UserTag: this._config.userTag,
3049
+ };
3050
+ return yield this.makePostRequest(e, t);
3051
+ });
3052
+ }
3053
+ updateUserPreference(t, i, n, r, o, s) {
3054
+ return e(this, void 0, void 0, function* () {
3055
+ const e = this.getURL("/postuserpreferences"),
3056
+ a = {
3057
+ SubscriptionCode: this._config.subscriptionCode,
3058
+ AccessKey: this._config.accessKey,
3059
+ UserTag: this._config.userTag,
3060
+ UserPreferences: {
3061
+ AutomaticallyGenerateTranscript: t,
3062
+ PreferredTranscriptionLanguage: i,
3063
+ HighlightMedicalTerms: n,
3064
+ DisplayPatientContext: r,
3065
+ NoteOutputStyle: o,
3066
+ NoteOutputVerbosity: s,
3067
+ },
3068
+ };
3069
+ return yield this.makePostRequest(e, a);
3070
+ });
3071
+ }
3072
+ }
3073
+ const H = "Invalid user details, please check again",
3074
+ q = "Subscription is not valid.",
3075
+ z =
3076
+ "invalid request. Please make sure AccessKey, SubscriptionCode and UserTag is sent along with the request",
3077
+ $ = "Active seat is not available for user",
3078
+ Y = "Unable to fetch account details, please try again.",
3079
+ Q = "Unable to fetch job details, please try again.",
3080
+ X = "Job not reconnectable",
3081
+ Z = "Timeout exceeded",
3082
+ ee = "Rate Limit Exceeded, Please try again in sometime!",
3083
+ te = "Audio Signal is power very LOW, Mic might be muted",
3084
+ ie = "Job Id is empty",
3085
+ ne = "Page Size is undefined",
3086
+ re = "Note Data is empty",
3087
+ oe = "Job Name is empty",
3088
+ se = "Patient Context is empty",
3089
+ ae = "Mic permission denied",
3090
+ ce = "Microphone is muted",
3091
+ ue = "Audio track ended. Possibly the mic was unplugged",
3092
+ le = "Internet is not available. Try again later.",
3093
+ de =
3094
+ "Feedback is not enabled. Please contact administrator for more details.",
3095
+ he = "Automatic Transcription is not enabled for the organisation",
3096
+ fe = "Resume job is not enabled for the organisation";
3097
+ class pe {
3098
+ static isBrowserOnline() {
3099
+ return "undefined" != typeof navigator && !0 === navigator.onLine;
3100
+ }
3101
+ static isValidHttpUrl(e) {
3102
+ if ("string" != typeof e || e.length > 2048) return !1;
3103
+ try {
3104
+ const t = new URL(e);
3105
+ return (
3106
+ ("http:" === t.protocol || "https:" === t.protocol) &&
3107
+ !t.username &&
3108
+ !t.password
3109
+ );
3110
+ } catch (e) {
3111
+ return !1;
3112
+ }
3113
+ }
3114
+ static hasInternetConnection() {
3115
+ return e(
3116
+ this,
3117
+ arguments,
3118
+ void 0,
3119
+ function* (e = { url: null, timeoutMs: null }) {
3120
+ var t = e.url || pe.DEFAULT_URL;
3121
+ const i = e.timeoutMs || pe.DEFAULT_TIMEOUT;
3122
+ if (!pe.isBrowserOnline()) return !1;
3123
+ pe.isValidHttpUrl(t) || (t = pe.DEFAULT_URL);
3124
+ const n = new AbortController(),
3125
+ r = setTimeout(() => n.abort(), i);
3126
+ try {
3127
+ return (
3128
+ yield fetch(t, {
3129
+ method: "HEAD",
3130
+ mode: "no-cors",
3131
+ cache: "no-cache",
3132
+ signal: n.signal,
3133
+ }),
3134
+ !0
3135
+ );
3136
+ } catch (e) {
3137
+ return !1;
3138
+ } finally {
3139
+ clearTimeout(r);
3140
+ }
3141
+ },
3142
+ );
3143
+ }
3144
+ static isOnline(t) {
3145
+ return e(this, void 0, void 0, function* () {
3146
+ return pe.hasInternetConnection(t);
3147
+ });
3148
+ }
3149
+ }
3150
+ Object.defineProperty(pe, "DEFAULT_URL", {
3151
+ enumerable: !0,
3152
+ configurable: !0,
3153
+ writable: !0,
3154
+ value: "https://www.google.com/favicon.ico",
3155
+ }),
3156
+ Object.defineProperty(pe, "DEFAULT_TIMEOUT", {
3157
+ enumerable: !0,
3158
+ configurable: !0,
3159
+ writable: !0,
3160
+ value: 5e3,
3161
+ });
3162
+ class ge {
3163
+ constructor(e) {
3164
+ Object.defineProperty(this, "_logTag", {
3165
+ enumerable: !0,
3166
+ configurable: !0,
3167
+ writable: !0,
3168
+ value: "Augnito-Ambient",
3169
+ }),
3170
+ Object.defineProperty(this, "_ambientRestAPI", {
3171
+ enumerable: !0,
3172
+ configurable: !0,
3173
+ writable: !0,
3174
+ value: void 0,
3175
+ }),
3176
+ Object.defineProperty(this, "_ambientPaceAPI", {
3177
+ enumerable: !0,
3178
+ configurable: !0,
3179
+ writable: !0,
3180
+ value: void 0,
3181
+ }),
3182
+ Object.defineProperty(this, "config", {
3183
+ enumerable: !0,
3184
+ configurable: !0,
3185
+ writable: !0,
3186
+ value: void 0,
3187
+ }),
3188
+ Object.defineProperty(this, "enableLog", {
3189
+ enumerable: !0,
3190
+ configurable: !0,
3191
+ writable: !0,
3192
+ value: void 0,
3193
+ }),
3194
+ Object.defineProperty(this, "shouldReadAudioIntensity", {
3195
+ enumerable: !0,
3196
+ configurable: !0,
3197
+ writable: !0,
3198
+ value: void 0,
3199
+ }),
3200
+ Object.defineProperty(this, "recorderIns", {
3201
+ enumerable: !0,
3202
+ configurable: !0,
3203
+ writable: !0,
3204
+ value: void 0,
3205
+ }),
3206
+ Object.defineProperty(this, "forceStopAudio", {
3207
+ enumerable: !0,
3208
+ configurable: !0,
3209
+ writable: !0,
3210
+ value: !1,
3211
+ }),
3212
+ Object.defineProperty(this, "_isRecording", {
3213
+ enumerable: !0,
3214
+ configurable: !0,
3215
+ writable: !0,
3216
+ value: !1,
3217
+ }),
3218
+ Object.defineProperty(this, "echoCancellation", {
3219
+ enumerable: !0,
3220
+ configurable: !0,
3221
+ writable: !0,
3222
+ value: void 0,
3223
+ }),
3224
+ Object.defineProperty(this, "noiseSuppression", {
3225
+ enumerable: !0,
3226
+ configurable: !0,
3227
+ writable: !0,
3228
+ value: void 0,
3229
+ }),
3230
+ Object.defineProperty(this, "autoGainControl", {
3231
+ enumerable: !0,
3232
+ configurable: !0,
3233
+ writable: !0,
3234
+ value: void 0,
3235
+ }),
3236
+ Object.defineProperty(this, "onJobCreated", {
3237
+ enumerable: !0,
3238
+ configurable: !0,
3239
+ writable: !0,
3240
+ value: void 0,
3241
+ }),
3242
+ Object.defineProperty(this, "onStateChanged", {
3243
+ enumerable: !0,
3244
+ configurable: !0,
3245
+ writable: !0,
3246
+ value: void 0,
3247
+ }),
3248
+ Object.defineProperty(this, "onError", {
3249
+ enumerable: !0,
3250
+ configurable: !0,
3251
+ writable: !0,
3252
+ value: void 0,
3253
+ }),
3254
+ Object.defineProperty(this, "onOtherResult", {
3255
+ enumerable: !0,
3256
+ configurable: !0,
3257
+ writable: !0,
3258
+ value: void 0,
3259
+ }),
3260
+ Object.defineProperty(this, "onIntensityValue", {
3261
+ enumerable: !0,
3262
+ configurable: !0,
3263
+ writable: !0,
3264
+ value: void 0,
3265
+ }),
3266
+ Object.defineProperty(this, "onIdleMic", {
3267
+ enumerable: !0,
3268
+ configurable: !0,
3269
+ writable: !0,
3270
+ value: void 0,
3271
+ }),
3272
+ Object.defineProperty(this, "onSoapNoteGenerated", {
3273
+ enumerable: !0,
3274
+ configurable: !0,
3275
+ writable: !0,
3276
+ value: void 0,
3277
+ }),
3278
+ Object.defineProperty(this, "onTranscriptGenerated", {
3279
+ enumerable: !0,
3280
+ configurable: !0,
3281
+ writable: !0,
3282
+ value: void 0,
3283
+ }),
3284
+ Object.defineProperty(this, "onCodesGenerated", {
3285
+ enumerable: !0,
3286
+ configurable: !0,
3287
+ writable: !0,
3288
+ value: void 0,
3289
+ }),
3290
+ Object.defineProperty(this, "onJobStatus", {
3291
+ enumerable: !0,
3292
+ configurable: !0,
3293
+ writable: !0,
3294
+ value: void 0,
3295
+ }),
3296
+ Object.defineProperty(this, "onMicRecoveredAfterUnplugged", {
3297
+ enumerable: !0,
3298
+ configurable: !0,
3299
+ writable: !0,
3300
+ value: void 0,
3301
+ }),
3302
+ (this._ambientRestAPI = new l(this.validateConfig(e))),
3303
+ (this._ambientPaceAPI = new V(e)),
3304
+ (this.config = this.createSocketConfig(e)),
3305
+ (this.enableLog = e.enableLogs),
3306
+ (this.shouldReadAudioIntensity = e.shouldReadAudioIntensity),
3307
+ (this.echoCancellation = e.echoCancellation),
3308
+ (this.noiseSuppression = e.noiseSuppression),
3309
+ (this.autoGainControl = e.autoGainControl);
3310
+ }
3311
+ initRecorder(e) {
3312
+ var t, i, n, r, o;
3313
+ (this.recorderIns = new F({
3314
+ serverURL: e,
3315
+ enableLogs: null !== (t = this.enableLog) && void 0 !== t && t,
3316
+ isDebug: null !== (i = this.enableLog) && void 0 !== i && i,
3317
+ bufferInterval: 15,
3318
+ EOS_Message: '{"JobAction": "EOS","Status": 0,"Type": "meta"}',
3319
+ socketTimeoutInterval: 2e4,
3320
+ shouldSendAudioDataSequence: !0,
3321
+ shouldReadIntensity: this.shouldReadAudioIntensity,
3322
+ echoCancellation: this.echoCancellation,
3323
+ noiseSuppression: this.noiseSuppression,
3324
+ autoGainControl: this.autoGainControl,
3325
+ })),
3326
+ (this.recorderIns.echoCancellation =
3327
+ null !== (n = this.echoCancellation) && void 0 !== n && n),
3328
+ (this.recorderIns.noiseSuppression =
3329
+ null !== (r = this.noiseSuppression) && void 0 !== r && r),
3330
+ (this.recorderIns.autoGainControl =
3331
+ null !== (o = this.autoGainControl) && void 0 !== o && o),
3332
+ (this.recorderIns.onError = this.onErrorCallback.bind(this)),
3333
+ (this.recorderIns.onStateChanged = this.onStateChangeCallback.bind(this)),
3334
+ (this.recorderIns.onSessionEvent =
3335
+ this.onSessionEventCallback.bind(this)),
3336
+ (this.recorderIns.onOtherResults =
3337
+ this.onOtherResultsCallback.bind(this)),
3338
+ (this.recorderIns.onIntensity = this.onIntensityCallback.bind(this)),
3339
+ (this.recorderIns.onSpeechResponse =
3340
+ this.onSpeechResponseCallback.bind(this)),
3341
+ (this.recorderIns.onJobStatus = this.onJobStatusEventCallback.bind(this)),
3342
+ (this.recorderIns.onMicReady =
3343
+ this.onMicRecoveredAfterUnpluggedCallback.bind(this));
3344
+ }
3345
+ getNoteParams() {
3346
+ return e(this, void 0, void 0, function* () {
3347
+ try {
3348
+ if (!this._ambientRestAPI)
3349
+ return void d.error("SDK not initialized", this._logTag);
3350
+ var e = yield this._ambientPaceAPI.getNoteParams();
3351
+ if (e) {
3352
+ if (200 === e.Status) return e;
3353
+ this.onErrorCallback(e.ServerMessage);
3354
+ } else this.onErrorCallback("Unknown Error!");
3355
+ } catch (e) {
3356
+ this.handleException(e);
3357
+ }
3358
+ });
3359
+ }
3360
+ getAllNotes(t, i, n) {
3361
+ return e(this, void 0, void 0, function* () {
3362
+ try {
3363
+ if (!this._ambientRestAPI)
3364
+ return void d.error("SDK not initialized", this._logTag);
3365
+ var e = yield this._ambientRestAPI.ListJobs(t, i, null == n || n);
3366
+ if (e) {
3367
+ if (200 === e.Status) return e;
3368
+ this.onErrorCallback(e.ServerMessage);
3369
+ } else this.onErrorCallback("Unknown Error!");
3370
+ } catch (e) {
3371
+ this.handleException(e);
3372
+ }
3373
+ });
3374
+ }
3375
+ getSummarizedNote(t) {
3376
+ return e(this, void 0, void 0, function* () {
3377
+ try {
3378
+ if (!this._ambientRestAPI)
3379
+ return void d.error("SDK not initialized", this._logTag);
3380
+ var e = yield this._ambientRestAPI.FetchJob(t);
3381
+ if (e) {
3382
+ if (200 === e.Status) return e;
3383
+ this.onErrorCallback(e.ServerMessage);
3384
+ } else this.onErrorCallback("Unknown Error!");
3385
+ } catch (e) {
3386
+ this.handleException(e);
3387
+ }
3388
+ });
3389
+ }
3390
+ sendSummarizedNote(t, i) {
3391
+ return e(this, void 0, void 0, function* () {
3392
+ try {
3393
+ return this._ambientRestAPI
3394
+ ? yield this._ambientRestAPI.SendFinalNote(t, i)
3395
+ : void d.error("SDK not initialized", this._logTag);
3396
+ } catch (e) {
3397
+ this.handleException(e);
3398
+ }
3399
+ });
3400
+ }
3401
+ toggleListening(t, i, r, o, s, a, c) {
3402
+ return e(this, void 0, void 0, function* () {
3403
+ var e, u;
3404
+ if (void 0 !== a && "" !== a.trim()) {
3405
+ var l = yield this._ambientPaceAPI.getOrgConfigMapping(n.CDIVersion);
3406
+ if (
3407
+ (null == l ? void 0 : l.Items) &&
3408
+ l.Items.length > 0 &&
3409
+ l.Items[0].Settings
3410
+ )
3411
+ if (!l.Items[0].Settings.find((e) => 300 === e.ID))
3412
+ return void this.onErrorCallback(fe);
3413
+ }
3414
+ var d =
3415
+ (null === (e = this.config) || void 0 === e
3416
+ ? void 0
3417
+ : e.prepareWSSURL(t, i, r, o, a, c)) || "";
3418
+ this.recorderIns || this.initRecorder(d),
3419
+ null === (u = this.recorderIns) ||
3420
+ void 0 === u ||
3421
+ u.toggleStartStopAudioStream(s, d);
3422
+ });
3423
+ }
3424
+ togglePauseResumeListening(t, i, r, o, s, a, c) {
3425
+ return e(this, void 0, void 0, function* () {
3426
+ var e, u;
3427
+ if (void 0 !== a && "" !== a.trim()) {
3428
+ var l = yield this._ambientPaceAPI.getOrgConfigMapping(n.CDIVersion);
3429
+ if (
3430
+ (null == l ? void 0 : l.Items) &&
3431
+ l.Items.length > 0 &&
3432
+ l.Items[0].Settings
3433
+ )
3434
+ if (!l.Items[0].Settings.find((e) => 300 === e.ID))
3435
+ return void this.onErrorCallback(fe);
3436
+ }
3437
+ var d =
3438
+ (null === (e = this.config) || void 0 === e
3439
+ ? void 0
3440
+ : e.prepareWSSURL(t, i, r, o, a, c)) || "";
3441
+ this.recorderIns || this.initRecorder(d),
3442
+ null === (u = this.recorderIns) ||
3443
+ void 0 === u ||
3444
+ u.togglePauseResumeAudioStream(s, d);
3445
+ });
3446
+ }
3447
+ startListening() {
3448
+ var e;
3449
+ null === (e = this.recorderIns) || void 0 === e || e.startAudio();
3450
+ }
3451
+ stopListening() {
3452
+ var e;
3453
+ null === (e = this.recorderIns) || void 0 === e || e.stopAudio(!0, !0);
3454
+ }
3455
+ deleteNotes(t, i) {
3456
+ return e(this, void 0, void 0, function* () {
3457
+ var e;
3458
+ try {
3459
+ if (!this._ambientRestAPI)
3460
+ return void d.error("SDK not initialized", this._logTag);
3461
+ var n = yield this._ambientRestAPI.DeleteNotes(t, i);
3462
+ if (n) {
3463
+ if (200 === n.Status)
3464
+ return (
3465
+ null === (e = this.recorderIns) ||
3466
+ void 0 === e ||
3467
+ e.stopAudio(!1, !0),
3468
+ n
3469
+ );
3470
+ this.onErrorCallback(n.ServerMessage);
3471
+ } else this.onErrorCallback("Unknown Error!");
3472
+ } catch (e) {
3473
+ this.handleException(e);
3474
+ }
3475
+ });
3476
+ }
3477
+ renameNoteTitle(t, i) {
3478
+ return e(this, void 0, void 0, function* () {
3479
+ try {
3480
+ if (!this._ambientRestAPI)
3481
+ return void d.error("SDK not initialized", this._logTag);
3482
+ var e = yield this._ambientRestAPI.RenameNoteTitle(t, i);
3483
+ if (e) {
3484
+ if (200 === e.Status) return e;
3485
+ this.onErrorCallback(e.ServerMessage);
3486
+ } else this.onErrorCallback("Unknown Error!");
3487
+ } catch (e) {
3488
+ this.handleException(e);
3489
+ }
3490
+ });
3491
+ }
3492
+ getNotePDF(t, i, n, r, o, s) {
3493
+ return e(this, void 0, void 0, function* () {
3494
+ try {
3495
+ if (!this._ambientRestAPI)
3496
+ return void d.error("SDK not initialized", this._logTag);
3497
+ var e = yield this._ambientRestAPI.DownloadNotePDF(t, i, n, r, o, s);
3498
+ if (e) {
3499
+ if (200 === e.Status) return e;
3500
+ this.onErrorCallback(e.ServerMessage);
3501
+ } else this.onErrorCallback("Unknown Error!");
3502
+ } catch (e) {
3503
+ this.handleException(e);
3504
+ }
3505
+ });
3506
+ }
3507
+ endPausedJob(t) {
3508
+ return e(this, void 0, void 0, function* () {
3509
+ try {
3510
+ if (!this._ambientRestAPI)
3511
+ return void d.error("SDK not initialized", this._logTag);
3512
+ var e = yield this._ambientRestAPI.EndJob(t);
3513
+ if (e) {
3514
+ if (200 === e.Status) return e;
3515
+ this.onErrorCallback(e.ServerMessage);
3516
+ } else this.onErrorCallback("Unknown Error!");
3517
+ } catch (e) {
3518
+ this.handleException(e);
3519
+ }
3520
+ });
3521
+ }
3522
+ generateCDISuggestions(t, i, r, o, s) {
3523
+ return e(this, void 0, void 0, function* () {
3524
+ try {
3525
+ if (!this._ambientRestAPI)
3526
+ return void d.error("SDK not initialized", this._logTag);
3527
+ var e = 1,
3528
+ a = yield this._ambientPaceAPI.getOrgConfigMapping(n.CDIVersion);
3529
+ if (
3530
+ (null == a ? void 0 : a.Items) &&
3531
+ a.Items.length > 0 &&
3532
+ a.Items[0].Settings
3533
+ ) {
3534
+ var c = a.Items[0].Settings.find((e) => 209 === e.ID);
3535
+ c && (e = Number.parseInt(c.ConfigValue));
3536
+ }
3537
+ var u = yield this._ambientRestAPI.GenerateSuggestions(
3538
+ t,
3539
+ i,
3540
+ r,
3541
+ s,
3542
+ o,
3543
+ e,
3544
+ );
3545
+ if (u) {
3546
+ if (200 === u.Status) return u;
3547
+ this.onErrorCallback(u.ServerMessage);
3548
+ } else this.onErrorCallback("Unknown Error!");
3549
+ } catch (e) {
3550
+ this.handleException(e);
3551
+ }
3552
+ });
3553
+ }
3554
+ updatePatientContext(t, i, n) {
3555
+ return e(this, void 0, void 0, function* () {
3556
+ try {
3557
+ if (!this._ambientRestAPI)
3558
+ return void d.error("SDK not initialized", this._logTag);
3559
+ var e = yield this._ambientRestAPI.UpdatePatientContext(t, i, n);
3560
+ if (e) {
3561
+ if (200 === e.Status) return e;
3562
+ this.onErrorCallback(e.ServerMessage);
3563
+ } else this.onErrorCallback("Unknown Error!");
3564
+ } catch (e) {
3565
+ this.handleException(e);
3566
+ }
3567
+ });
3568
+ }
3569
+ modifyGeneratedNote(t, i, n) {
3570
+ return e(this, void 0, void 0, function* () {
3571
+ try {
3572
+ if (!this._ambientRestAPI)
3573
+ return void d.error("SDK not initialized", this._logTag);
3574
+ var e = yield this._ambientRestAPI.ModifyGeneratedNote(t, i, n);
3575
+ if (e) {
3576
+ if (200 === e.Status) return e;
3577
+ this.onErrorCallback(e.ServerMessage);
3578
+ } else this.onErrorCallback("Unknown Error!");
3579
+ } catch (e) {
3580
+ this.handleException(e);
3581
+ }
3582
+ });
3583
+ }
3584
+ fetchTranscriptionForNote(t) {
3585
+ return e(this, void 0, void 0, function* () {
3586
+ try {
3587
+ if (!this._ambientRestAPI)
3588
+ return void d.error("SDK not initialized", this._logTag);
3589
+ if (
3590
+ (yield this._ambientPaceAPI.getUserPreferences()).Items[0]
3591
+ .AutomaticTranscriptionEnabledForOrg
3592
+ ) {
3593
+ var e = yield this._ambientRestAPI.FetchTranscription(t);
3594
+ if (e) {
3595
+ if (200 === e.Status) return e;
3596
+ this.onErrorCallback(e.ServerMessage);
3597
+ } else this.onErrorCallback("Unknown Error!");
3598
+ } else this.onErrorCallback(he);
3599
+ } catch (e) {
3600
+ this.handleException(e);
3601
+ }
3602
+ });
3603
+ }
3604
+ sendFeedback(t, i, n, r) {
3605
+ return e(this, void 0, void 0, function* () {
3606
+ var e, o;
3607
+ try {
3608
+ if (!this._ambientRestAPI)
3609
+ return void d.error("SDK not initialized", this._logTag);
3610
+ var s = yield this._ambientPaceAPI.getUserPreferences();
3611
+ if (
3612
+ (null === (e = s.Items[0]) || void 0 === e
3613
+ ? void 0
3614
+ : e.FeedbackEnabledForOrg) &&
3615
+ (null === (o = s.Items[0]) || void 0 === o
3616
+ ? void 0
3617
+ : o.FeedbackEnabled)
3618
+ ) {
3619
+ var a = yield this._ambientRestAPI.SendFeedback(
3620
+ t,
3621
+ i,
3622
+ null != n ? n : "",
3623
+ null != r ? r : "SOAPFeedBack",
3624
+ );
3625
+ if (a) {
3626
+ if (200 === a.Status) return a;
3627
+ this.onErrorCallback(a.ServerMessage);
3628
+ } else this.onErrorCallback("Unknown Error!");
3629
+ } else this.onErrorCallback(de);
3630
+ } catch (e) {
3631
+ this.handleException(e);
3632
+ }
3633
+ });
3634
+ }
3635
+ getUserConfiguration(t) {
3636
+ return e(this, void 0, void 0, function* () {
3637
+ try {
3638
+ if (!this._ambientPaceAPI)
3639
+ return void d.error("SDK not initialized", this._logTag);
3640
+ var e = yield this._ambientPaceAPI.getUserConfigSettings(t);
3641
+ if (e) {
3642
+ if (200 === e.Status) return e;
3643
+ this.onErrorCallback(e.ServerMessage);
3644
+ } else this.onErrorCallback("Unknown Error!");
3645
+ } catch (e) {
3646
+ this.handleException(e);
3647
+ }
3648
+ });
3649
+ }
3650
+ updateUserConfiguration(t) {
3651
+ return e(this, void 0, void 0, function* () {
3652
+ try {
3653
+ if (!this._ambientPaceAPI)
3654
+ return void d.error("SDK not initialized", this._logTag);
3655
+ var e = yield this._ambientPaceAPI.updateUserConfig(t);
3656
+ if (e) {
3657
+ if (200 === e.Status) return e;
3658
+ this.onErrorCallback(e.ServerMessage);
3659
+ } else this.onErrorCallback("Unknown Error!");
3660
+ } catch (e) {
3661
+ this.handleException(e);
3662
+ }
3663
+ });
3664
+ }
3665
+ getUserPreferenceSettings() {
3666
+ return e(this, void 0, void 0, function* () {
3667
+ try {
3668
+ if (!this._ambientPaceAPI)
3669
+ return void d.error("SDK not initialized", this._logTag);
3670
+ var e = yield this._ambientPaceAPI.getUserPreferences();
3671
+ if (e) {
3672
+ if (200 === e.Status) return e;
3673
+ this.onErrorCallback(e.ServerMessage);
3674
+ } else this.onErrorCallback("Unknown Error!");
3675
+ } catch (e) {
3676
+ this.handleException(e);
3677
+ }
3678
+ });
3679
+ }
3680
+ updateUserPreferenceSettings(t) {
3681
+ return e(this, void 0, void 0, function* () {
3682
+ var e, i, n, r, o, c;
3683
+ try {
3684
+ if (!this._ambientPaceAPI)
3685
+ return void d.error("SDK not initialized", this._logTag);
3686
+ var u = yield this._ambientPaceAPI.updateUserPreference(
3687
+ null !== (e = t.AutomaticallyGenerateTranscript) && void 0 !== e && e,
3688
+ null !== (i = t.PreferredTranscriptionLanguage) && void 0 !== i
3689
+ ? i
3690
+ : "English",
3691
+ null !== (n = t.HighlightMedicalTerms) && void 0 !== n && n,
3692
+ null !== (r = t.DisplayPatientContext) && void 0 !== r && r,
3693
+ null !== (o = t.NoteOutputStyle) && void 0 !== o ? o : a.DashFormat,
3694
+ null !== (c = t.NoteOutputVerbosity) && void 0 !== c ? c : s.Detailed,
3695
+ );
3696
+ if (u) {
3697
+ if (200 === u.Status) return u;
3698
+ this.onErrorCallback(u.ServerMessage);
3699
+ } else this.onErrorCallback("Unknown Error!");
3700
+ } catch (e) {
3701
+ this.handleException(e);
3702
+ }
3703
+ });
3704
+ }
3705
+ isInternetAvailable(t) {
3706
+ return e(this, void 0, void 0, function* () {
3707
+ const e = yield pe.isOnline(t);
3708
+ return e || this.onErrorCallback(le), e;
3709
+ });
3710
+ }
3711
+ onEventCallback(e) {
3712
+ this.onJobCreated && this.onJobCreated(e);
3713
+ }
3714
+ onStateChangeCallback(e) {
3715
+ var t;
3716
+ if (this.forceStopAudio)
3717
+ return (
3718
+ null === (t = this.recorderIns) || void 0 === t || t.stopAudio(!1, !0),
3719
+ void (this.forceStopAudio = !1)
3720
+ );
3721
+ (this._isRecording = e), this.onStateChanged && this.onStateChanged(e);
3722
+ }
3723
+ handleException(e) {
3724
+ if (e instanceof TypeError) this.onErrorCallback(e.message);
3725
+ else {
3726
+ if (e instanceof c) throw e;
3727
+ d.error(e.message, this._logTag);
3728
+ }
3729
+ }
3730
+ onErrorCallback(e, t) {
3731
+ var i,
3732
+ n,
3733
+ r,
3734
+ s,
3735
+ a,
3736
+ c,
3737
+ u,
3738
+ l,
3739
+ h,
3740
+ f,
3741
+ p,
3742
+ g,
3743
+ v,
3744
+ b,
3745
+ m,
3746
+ y,
3747
+ S = { ErrorCode: null != t ? t : o.ERRUNKNOWN, ErrorMessage: e };
3748
+ try {
3749
+ var C = JSON.parse(e);
3750
+ (S.ErrorMessage = C.Data),
3751
+ C.Data === Z
3752
+ ? (this.stopListening(),
3753
+ d.error("Recording time limit exceeded", this._logTag),
3754
+ (S.ErrorCode = o.WSJOB05))
3755
+ : C.Data === H
3756
+ ? (this._isRecording
3757
+ ? null === (i = this.recorderIns) ||
3758
+ void 0 === i ||
3759
+ i.stopAudio(!1, !0)
3760
+ : (this.forceStopAudio = !0),
3761
+ (S.ErrorCode = o.WSAUTH03))
3762
+ : C.Data.includes(Y)
3763
+ ? (S.ErrorCode = o.WSAUTH04)
3764
+ : C.Data.includes(Q)
3765
+ ? (S.ErrorCode = o.WSJOB01)
3766
+ : C.Data.includes(X)
3767
+ ? (S.ErrorCode = o.WSJOB02)
3768
+ : C.Data.includes(ee)
3769
+ ? (S.ErrorCode = o.WSACC01)
3770
+ : C.Data.includes(te) && (S.ErrorCode = o.WSAUD01);
3771
+ } catch (e) {}
3772
+ (null === (n = S.ErrorMessage) || void 0 === n ? void 0 : n.includes(ie))
3773
+ ? (S.ErrorCode = o.SDK01)
3774
+ : (
3775
+ null === (r = S.ErrorMessage) || void 0 === r
3776
+ ? void 0
3777
+ : r.includes(ne)
3778
+ )
3779
+ ? (S.ErrorCode = o.SDK02)
3780
+ : (
3781
+ null === (s = S.ErrorMessage) || void 0 === s
3782
+ ? void 0
3783
+ : s.includes(re)
3784
+ )
3785
+ ? (S.ErrorCode = o.SDK03)
3786
+ : (
3787
+ null === (a = S.ErrorMessage) || void 0 === a
3788
+ ? void 0
3789
+ : a.includes(oe)
3790
+ )
3791
+ ? (S.ErrorCode = o.SDK04)
3792
+ : (
3793
+ null === (c = S.ErrorMessage) || void 0 === c
3794
+ ? void 0
3795
+ : c.includes(se)
3796
+ )
3797
+ ? (S.ErrorCode = o.SDK05)
3798
+ : (
3799
+ null === (u = S.ErrorMessage) || void 0 === u
3800
+ ? void 0
3801
+ : u.includes(ae)
3802
+ )
3803
+ ? (S.ErrorCode = o.SDK06)
3804
+ : (
3805
+ null === (l = S.ErrorMessage) || void 0 === l
3806
+ ? void 0
3807
+ : l.includes(ce)
3808
+ )
3809
+ ? (S.ErrorCode = o.SDK07)
3810
+ : (
3811
+ null === (h = S.ErrorMessage) || void 0 === h
3812
+ ? void 0
3813
+ : h.includes(ue)
3814
+ )
3815
+ ? (S.ErrorCode = o.SDK08)
3816
+ : (null === (f = S.ErrorMessage) || void 0 === f
3817
+ ? void 0
3818
+ : f.includes(q)) ||
3819
+ (null === (p = S.ErrorMessage) || void 0 === p ? void 0 : p.includes(z))
3820
+ ? (S.ErrorCode = o.AUTH01)
3821
+ : (null === (g = S.ErrorMessage) || void 0 === g ? void 0 : g.includes($))
3822
+ ? (S.ErrorCode = o.AUTH02)
3823
+ : (
3824
+ null === (v = S.ErrorMessage) || void 0 === v
3825
+ ? void 0
3826
+ : v.includes(le)
3827
+ )
3828
+ ? (S.ErrorCode = o.SDK12)
3829
+ : (
3830
+ null === (b = S.ErrorMessage) || void 0 === b
3831
+ ? void 0
3832
+ : b.includes(he)
3833
+ )
3834
+ ? (S.ErrorCode = o.SDK13)
3835
+ : (
3836
+ null === (m = S.ErrorMessage) || void 0 === m
3837
+ ? void 0
3838
+ : m.includes(de)
3839
+ )
3840
+ ? (S.ErrorCode = o.SDK14)
3841
+ : (null === (y = S.ErrorMessage) || void 0 === y
3842
+ ? void 0
3843
+ : y.includes(fe)) && (S.ErrorCode = o.SDK15),
3844
+ this.onError && this.onError(S);
3845
+ }
3846
+ onOtherResultsCallback(e) {
3847
+ this.onOtherResult && this.onOtherResult(e);
3848
+ }
3849
+ onIntensityCallback(e) {
3850
+ this.onIntensityValue && this.onIntensityValue(e);
3851
+ }
3852
+ onIdleMicCallback() {
3853
+ this.onIdleMic && this.onIdleMic();
3854
+ }
3855
+ onSpeechResponseCallback(e) {
3856
+ var t = JSON.parse(e);
3857
+ "note" === t.Type.toLowerCase() && this.onSoapNoteGenerated
3858
+ ? this.onSoapNoteGenerated(t.Data)
3859
+ : "transcript" === t.Type.toLowerCase() && this.onTranscriptGenerated
3860
+ ? this.onTranscriptGenerated(t.Data)
3861
+ : "codes" === t.Type.toLowerCase() &&
3862
+ this.onCodesGenerated &&
3863
+ this.onCodesGenerated(t.Data);
3864
+ }
3865
+ onJobStatusEventCallback(e) {
3866
+ this.onJobStatus && this.onJobStatus(e);
3867
+ }
3868
+ onMicRecoveredAfterUnpluggedCallback() {
3869
+ this.onMicRecoveredAfterUnplugged && this.onMicRecoveredAfterUnplugged();
3870
+ }
3871
+ onSessionEventCallback(e) {
3872
+ var t;
3873
+ if (!e) return;
3874
+ let i;
3875
+ try {
3876
+ i = "string" == typeof e ? JSON.parse(e) : e;
3877
+ } catch (e) {
3878
+ return void d.error(
3879
+ `Error parsing session event data: ${e}`,
3880
+ this._logTag,
3881
+ );
3882
+ }
3883
+ if (!i || !("Type" in i)) return;
3884
+ if (
3885
+ "meta" === i.Type.toLowerCase() &&
3886
+ (null === (t = this.config) || void 0 === t ? void 0 : t.onMetaEvent)
3887
+ ) {
3888
+ if (!i.JobID)
3889
+ return void d.error("JobID is missing in meta event", this._logTag);
3890
+ this.config.onMetaEvent(i.JobID);
3891
+ } else
3892
+ "error" === i.Type.toLowerCase() &&
3893
+ i.Data &&
3894
+ this.onErrorCallback(i.Data);
3895
+ if ("object" != typeof i.Event || null === i.Event) return;
3896
+ const { Type: n, Value: r } = i.Event;
3897
+ n &&
3898
+ ("SESSION_CREATED" === n && r
3899
+ ? d.log(`session Token ${r}`, this._logTag)
3900
+ : "SERVICE_DOWN" === n
3901
+ ? d.error(n, this._logTag)
3902
+ : "NO_DICTATION_STOP_MIC" === n
3903
+ ? (d.log("NO_DICTATION_STOP_MIC", this._logTag),
3904
+ this.onIdleMicCallback())
3905
+ : "INVALID_AUTH_CREDENTIALS" === n
3906
+ ? d.error("INVALID_AUTH_CREDENTIALS", this._logTag)
3907
+ : "LOW_BANDWIDTH" === n &&
3908
+ d.log("LOW_BANDWIDTH: Check internet connection", this._logTag));
3909
+ }
3910
+ validateConfig(e) {
3911
+ return (
3912
+ i.Against.NullOrEmpty(e.server, "Server"),
3913
+ i.Against.NullOrEmpty(e.subscriptionCode, "SubscriptionCode"),
3914
+ i.Against.NullOrEmpty(e.accessKey, "AccessKey"),
3915
+ i.Against.NullOrEmpty(e.userTag, "UserTag"),
3916
+ e
3917
+ );
3918
+ }
3919
+ createSocketConfig(e) {
3920
+ const i = new t(e);
3921
+ return (
3922
+ (i.onError = this.onErrorCallback.bind(this)),
3923
+ (i.onMetaEvent = this.onEventCallback.bind(this)),
3924
+ i
3925
+ );
3926
+ }
3927
+ }
3928
+ export {
3929
+ ge as AugnitoAmbient,
3930
+ o as ErrorCodes,
3931
+ c as HttpCodedError,
3932
+ a as NoteOutputStyleConfig,
3933
+ r as NoteTypeConfig,
3934
+ s as NoteVerbosityConfig,
3935
+ n as SettingsConfigType,
3936
+ };