testaugnitoambientsdk2 2.1.66 → 2.1.68

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,3943 @@
1
- function e(e,t,i,n){return new(i||(i=Promise))(function(r,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(s,a)}c((n=n.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,i,n,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}`,i&&""!==i&&(s+=`&filename=${i}`),n&&""!==n&&(s+=`&jobid=${n}`),r&&""!==r&&(s+=`&parentjobid=${r}`),void 0!==o&&(s+=`&inheritparentconfig=${o}`),s}}class i{constructor(){}static get Against(){return i.instance||(i.instance=new i),i.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=i.Against.NullOrUndefined(e,t)))throw new TypeError(`${t} is empty`);return e}}var n,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"}(n||(n={})),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,i){return e(this,void 0,void 0,function*(){try{const n=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.ok){const t=yield n.text();var e=JSON.parse(t);throw new c(e.message,e.code.toString())}return yield n.json()}catch(e){throw e}})}makePatchRequest(t,i){return e(this,void 0,void 0,function*(){try{const n=yield fetch(t,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.ok){const t=yield n.text();var e=JSON.parse(t);throw new c(e.message,n.status.toString())}return yield n.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,n,r){return e(this,void 0,void 0,function*(){i.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:n,Collapse:r};return yield this.makePostRequest(e,o)})}FetchJob(t){return e(this,void 0,void 0,function*(){i.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/fetch-job"),n={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t};return yield this.makePostRequest(e,n)})}SendFinalNote(t,n){return e(this,void 0,void 0,function*(){i.Against.NullOrEmpty(t,"Job Id"),i.Against.NullOrEmpty(n,"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:n};return yield this.makePostRequest(e,r)})}DeleteNotes(t,n){return e(this,void 0,void 0,function*(){i.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:n};return yield this.makePostRequest(e,r)})}RenameNoteTitle(t,n){return e(this,void 0,void 0,function*(){i.Against.NullOrEmpty(t,"Job Id"),i.Against.NullOrEmpty(n,"Job Name");const e=this.getURL("/rename-job"),r={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,JobName:n};return yield this.makePostRequest(e,r)})}DownloadNotePDF(t,n,r,o,s,a){return e(this,void 0,void 0,function*(){i.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:n,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*(){i.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/end-job"),n={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t};return yield this.makePostRequest(e,n)})}UpdatePatientContext(t,n,r){return e(this,void 0,void 0,function*(){i.Against.NullOrEmpty(t,"Job Id"),i.Against.NullOrEmpty(n,"Patient Context");const e=this.getURL("/patient-context"),o={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t,NewContext:n,Replace:r};return yield this.makePostRequest(e,o)})}GenerateSuggestions(t,n,r,o,s,a){return e(this,void 0,void 0,function*(){i.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:n,SoapData:r,PatientContext:o,Codes:s};return yield this.makePostRequest(e,c)})}ModifyGeneratedNote(t,n,r){return e(this,void 0,void 0,function*(){i.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:n,NewNote:null!=r?r:""};return yield this.makePostRequest(e,o)})}FetchTranscription(t){return e(this,void 0,void 0,function*(){i.Against.NullOrEmpty(t,"Job Id");const e=this.getURL("/fetch-transcript"),n={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,JobID:t};return yield this.makePostRequest(e,n)})}SendFeedback(t,n,r,o){return e(this,void 0,void 0,function*(){i.Against.NullOrEmpty(t,"Job Id"),i.Against.NullOrUndefined(n,"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:n,FeedBack:null!=r?r:"",Type:null!=o?o:""};return yield this.makePostRequest(e,s)})}}class d{static log(e,t){const i=null!=t?t:this.defaultTag;console.log(`${i}:`,e)}static error(e,t){const i=null!=t?t:this.defaultTag;console.error(`${i}:`,e)}}function h(){h=function(){return t};var e,t={},i=Object.prototype,n=i.hasOwnProperty,r=Object.defineProperty||function(e,t,i){e[t]=i.value},o="function"==typeof Symbol?Symbol:{},s=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(e,t,i){return Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,i){return e[t]=i}}function l(e,t,i,n){var o=t&&t.prototype instanceof m?t:m,s=Object.create(o.prototype),a=new _(n||[]);return r(s,"_invoke",{value:w(e,i,a)}),s}function d(e,t,i){try{return{type:"normal",arg:e.call(t,i)}}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(O([])));E&&E!==i&&n.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 i(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&&n.call(l,"__await")?t.resolve(l.__await).then(function(e){i("next",e,s,a)},function(e){i("throw",e,s,a)}):t.resolve(l).then(function(e){u.value=e,s(u)},function(e){return i("throw",e,s,a)})}a(c.arg)}var o;r(this,"_invoke",{value:function(e,n){function r(){return new t(function(t,r){i(e,n,t,r)})}return o=o?o.then(r,r):r()}})}function w(t,i,n){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(n.method=o,n.arg=s;;){var a=n.delegate;if(a){var c=P(a,n);if(c){if(c===b)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===f)throw r=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=g;var u=d(t,i,n);if("normal"===u.type){if(r=n.done?v:p,u.arg===b)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=v,n.method="throw",n.arg=u.arg)}}}function P(t,i){var n=i.method,r=t.iterator[n];if(r===e)return i.delegate=null,"throw"===n&&t.iterator.return&&(i.method="return",i.arg=e,P(t,i),"throw"===i.method)||"return"!==n&&(i.method="throw",i.arg=new TypeError("The iterator does not provide a '"+n+"' method")),b;var o=d(r,t.iterator,i.arg);if("throw"===o.type)return i.method="throw",i.arg=o.arg,i.delegate=null,b;var s=o.arg;return s?s.done?(i[t.resultName]=s.value,i.next=t.nextLoc,"return"!==i.method&&(i.method="next",i.arg=e),i.delegate=null,b):s:(i.method="throw",i.arg=new TypeError("iterator result is not an object"),i.delegate=null,b)}function D(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 T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(D,this),this.reset(!0)}function O(t){if(t||""===t){var i=t[s];if(i)return i.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function i(){for(;++r<t.length;)if(n.call(t,r))return i.value=t[r],i.done=!1,i;return i.value=e,i.done=!0,i};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,i,n,r,o){void 0===o&&(o=Promise);var s=new R(l(e,i,n,r),o);return t.isGeneratorFunction(i)?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),i=[];for(var n in t)i.push(n);return i.reverse(),function e(){for(;i.length;){var n=i.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,_.prototype={constructor:_,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(T),!t)for(var i in this)"t"===i.charAt(0)&&n.call(this,i)&&!isNaN(+i.slice(1))&&(this[i]=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 i=this;function r(n,r){return a.type="throw",a.arg=t,i.next=n,r&&(i.method="next",i.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=n.call(s,"catchLoc"),u=n.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 i=this.tryEntries.length-1;i>=0;--i){var r=this.tryEntries[i];if(r.tryLoc<=this.prev&&n.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 i=this.tryEntries[t];if(i.finallyLoc===e)return this.complete(i.completion,i.afterLoc),T(i),b}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc===e){var n=i.completion;if("throw"===n.type){var r=n.arg;T(i)}return r}}throw Error("illegal catch attempt")},delegateYield:function(t,i,n){return this.delegate={iterator:O(t),resultName:i,nextLoc:n},"next"===this.method&&(this.arg=e),b}},t}function f(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=typeof n)return n;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,i,n,r,o,s){try{var a=e[o](s),c=a.value}catch(e){return void i(e)}a.done?t(c):Promise.resolve(c).then(n,r)}function g(e){return function(){var t=this,i=arguments;return new Promise(function(n,r){var o=e.apply(t,i);function s(e){p(o,n,r,s,a,"next",e)}function a(e){p(o,n,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 i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,f(n.key),n)}}function m(e,t,i){return t&&b(e.prototype,t),i&&b(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}function S(e,t){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!i){if(Array.isArray(e)||(i=function(e,t){if(e){if("string"==typeof e)return y(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?y(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){i&&(e=i);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},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(){i=i.call(e)},n:function(){var e=i.next();return s=e.done,e},e:function(e){a=!0,o=e},f:function(){try{s||null==i.return||i.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,i,n,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=i||"EOS",this.socketTimeoutInterval=n||1e4,this.bufferSizeInterval=h,this.switchToRegularSpeech=f},[{key:"Start",value:function(e,t,i){var n=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(i),", ").concat(JSON.stringify(this.heavyOp),");\n })();\n");this.worker=new Worker(URL.createObjectURL(new Blob([r],{type:"application/javascript"}))),this.worker.onmessage=function(e){n.enableLogs&&console.log("Augnito [MAIN]: "+JSON.stringify(e.data));var t=e.data;"final"==t.type?n.onFinalResultCallback(t.data):"partial"==t.type?n.onPartialResultCallback(t.data):"meta"==t.type?n.onSessionEventCallback(t.data):"error"==t.type?n.onErrorCallback(t.data):"other"==t.type?n.onOtherResultsCallback(t.data):"jobstatus"==t.type?n.onJobStatusCallback(t.data.status):"speechResponse"==t.type&&n.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),i=new DataView(t),n=0;n<4;n++)i.setUint8(n,"@BSR".charCodeAt(n));return i.setBigInt64(4,BigInt(this.packetSeqId),!1),i.setUint8(12,e?1:0),t}},{key:"appendAudioData",value:function(e,t){var i=e.byteLength+t.byteLength,n=new ArrayBuffer(i),r=new Uint8Array(n);return r.set(new Uint8Array(e),0),r.set(new Uint8Array(t),e.byteLength),n}},{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 i,n=this.createAudioPacketHeader(!0);null===(i=this.worker)||void 0===i||i.postMessage(n)}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?(n=this.createAudioPacketHeader(!1),l=this.appendAudioData(n,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,i,n,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=[],D=!1,T=[],_=!1,O=!1,N=!1,x="",U=v;function L(){m=+new Date,(E=""!=x?new WebSocket(u+"&jobid="+x):new WebSocket(u)).onopen=function(e){l&&console.log("Augnito: WebSocket connection established - "+JSON.stringify(e)),T.length>0&&(O=!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&&(x=t.JobID,console.log("Augnito JobID:",x)),self.postMessage({type:"meta",data:e.data});var i=JSON.parse(e.data);N=!(!i.Event||"INVALID_AUTH_CREDENTIALS"!==i.Event.Type)}else if(t.Result&&t.Result.Final){var n=JSON.stringify(t.Result);b&&(n=b(JSON.stringify(t.Result)),console.log(n)),self.postMessage({type:"final",data:n})}else t.Result&&!t.Result.Final?self.postMessage({type:"partial",data:t.Result.Transcript}):"ACK"==t.Type?(T=T.filter(function(e){return e.packetNumber>t.Index}),"RECEIVED_EOS"===t.Data.toUpperCase()&&(_=!0,clearInterval(R)),self.postMessage({type:"other",data:e.data})):"ERROR"==t.Type?("Timeout exceeded"==t.Data&&(_=!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 i=+new Date;return y<=S&&(S=i-1),y=i,!0}return e===t?(l&&console.warn("Gulping ".concat(t," as socket seems already closed...")),K(),!0):(+new Date-m>n&&!N&&L(),!1)}function J(e){w.push(e)}function K(){_&&(console.log("Augnito: Cleaning up worker resources..."),clearInterval(I),clearInterval(A),clearInterval(R),w=[],T=[],self.close())}L(),I=setInterval(function(){if(O){for(var e=0;e<T.length;e++){if(!M(T[e].packetData))break}O=!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 i=new DataView(t),n={packetNumber:Number(i.getBigInt64(4)),packetData:t};T.push(n)}}},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(n){if(n.data===i)x="",_=!0,N=!0,E.close();else if(n.data===e)J(t),x="",l&&console.log("Augnito: Worker received DONE, time to terminate..."),_=!0;else if(n.data===h)U=!0;else if(n.data===p)D=!0;else if(n.data===f){if(k instanceof ArrayBuffer&&J(k),P.length>0)for(var r=0;r<P.length;r++)J(P[r]);P=[],D=!1,U=!1,k=[]}else U&&!D?k=n.data:U&&D?P.push(n.data):J(n.data)}}var P,D,T,_,O,N,x,U,L,M,J=m(function e(t,i,n,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(i,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=n,this.enableLogs=i,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._originalDeviceId=null,this._originalDeviceLabel=null,this.shouldPreIntialiseRecorder&&this.InitialiseMediaStream(u,t)},[{key:"InitialiseMediaStream",value:(M=g(h().mark(function e(t,i){var n=this;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.currentDuration=t,this.currentWsUrl=i,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),""!==i&&this.executor.Start(t,i,this.shouldPreIntialiseRecorder),this.deviceChangeHandler||(this.deviceChangeHandler=g(h().mark(function e(){var t,i,r,o,s,a,c;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if((s=null===(t=n.audioStream)||void 0===t||null===(i=t.getAudioTracks)||void 0===i?void 0:i.call(t)[0])&&"ended"!==s.readyState){e.next=7;break}return n.micNeedsRecovery=!0,e.next=6,n.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,n.log('Device change detected. Probing current device: "'.concat(s.label,'"')),e.next=11,K(a);case 11:if(e.sent){e.next=23;break}return n.log('Current device "'.concat(s.label,'" appears silent/virtual. Searching for a real input device...')),n.micNeedsRecovery=!0,e.next=17,W(a,n.enableLogs);case 17:return(c=e.sent)?n._preferredDeviceId=c:(n.log("No active audio input device found after device change"),n._preferredDeviceId=null),e.next=21,n.recoverAudioGraph();case 21:e.next=24;break;case 23:n.log('Current device "'.concat(s.label,'" is producing audio — no switch needed'));case 24: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,i){var n,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,i,!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===(n=this.audioStream)||void 0===n||null===(r=n.getTracks)||void 0===r||null===(r=r.call(n))||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:(x=g(h().mark(function e(){var t,i,n,r,o,s,a,c,u=this;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r={channelCount:1,noiseSuppression:void 0!==this.noiseSuppression&&this.noiseSuppression},void 0!==this.echoCancellation&&(r.echoCancellation=this.echoCancellation,r.googEchoCancellation=this.echoCancellation),void 0!==this.noiseSuppression&&(r.googNoiseSuppression=this.noiseSuppression),void 0!==this.autoGainControl&&(r.autoGainControl=this.autoGainControl,r.googAutoGainControl=this.autoGainControl),this._preferredDeviceId&&(r.deviceId={exact:this._preferredDeviceId}),e.next=8,navigator.mediaDevices.getUserMedia({audio:r});case 8:this.audioStream=e.sent,this.audioContext&&"closed"!==this.audioContext.state||(this.audioContext=new AudioContext),this.source=this.audioContext.createMediaStreamSource(this.audioStream),o=this.audioStream.getAudioTracks()[0],s=null!==(t=null===(i=o.getSettings)||void 0===i||null===(i=i.call(o))||void 0===i?void 0:i.deviceId)&&void 0!==t?t:"",a=null!==(n=o.label)&&void 0!==n?n:"",this._originalDeviceId||(this._originalDeviceId=s,this._originalDeviceLabel=a),this.trackEndedHandler&&(this.trackEndedHandler=null),this.trackEndedHandler=function(){u.micNeedsRecovery=!0,u.onError(JSON.stringify({Type:"ERROR",Data:"Audio track ended. Possibly the mic was unplugged."}))},o.addEventListener("ended",this.trackEndedHandler),e.next=25;break;case 20:e.prev=20,e.t0=e.catch(0),c="","NotAllowedError"==e.t0.name?c="Mic permission denied":"NotFoundError"===e.t0.name?c="No suitable media device found":"NotReadableError"===e.t0.name&&(c="Microphone is being used by another application"),this.onError(JSON.stringify({Type:"ERROR",Data:c}));case 25:case"end":return e.stop()}},e,this,[[0,20]])})),function(){return x.apply(this,arguments)})},{key:"loadAudio",value:(N=g(h().mark(function e(){var t,i,n;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 i=e.sent,e.next=9,this.audioContext.decodeAudioData(i);case 9:return n=e.sent,e.abrupt("return",n);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 N.apply(this,arguments)})},{key:"createProcessorNode",value:(O=g(h().mark(function e(){var t,i=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,n=t.type,r=t.value;if(n==C)i.log("Worklet processing done, clearing resources..."),i.isDebug&&i.saveAudio(),i.cleanup();else if(e.data==k)i.executor.Send(k);else{var o;"intensity"===n?null===(o=i.onIntensity)||void 0===o||o.call(i,r):"audioData"===n&&i.isDebug&&new Int16Array(r).forEach(function(e){i.audioData.length<=288e5&&i.audioData.push(e)})}i.executor&&(i.closeSocketWithoutEOS?(i.executor.Send(A),i.closeSocketWithoutEOS=!1):"intensity"!==n&&i.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 O.apply(this,arguments)})},{key:"PauseStream",value:(_=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 _.apply(this,arguments)})},{key:"ResumeStream",value:(T=g(h().mark(function e(){var t,i,n;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if((n=null===(t=this.audioStream)||void 0===t||null===(i=t.getAudioTracks)||void 0===i?void 0:i.call(t)[0])&&"ended"!==n.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 T.apply(this,arguments)})},{key:"IsPaused",get:function(){return this.isPaused}},{key:"IsStreaming",get:function(){return this.isStreaming}},{key:"IsMicrophoneMuted",get:function(){var e,t,i=null===(e=this.audioStream)||void 0===e||null===(t=e.getAudioTracks)||void 0===t?void 0:t.call(e)[0];return!i||i.muted||"ended"===i.readyState}},{key:"StopStream",value:(D=g(h().mark(function e(t){var i,n,r,o,s,a,c,u;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if("suspended"===(null===(i=this.audioContext)||void 0===i?void 0:i.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===(n=this.audioStream)||void 0===n||null===(r=n.getAudioTracks)||void 0===r?void 0:r.call(n)[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 D.apply(this,arguments)})},{key:"recoverAudioGraph",value:(P=g(h().mark(function e(){var t,i,n,r,o,s,a,c,u,l,d,f,p=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===(a=this.source)||void 0===a||a.disconnect()}catch(e){}try{null===(c=this.processorNode)||void 0===c||c.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,u=null===(i=this.audioStream)||void 0===i||null===(n=i.getAudioTracks)||void 0===n?void 0:n.call(i)[0],l=null!==(r=null==u||null===(o=u.getSettings)||void 0===o||null===(o=o.call(u))||void 0===o?void 0:o.deviceId)&&void 0!==r?r:"",d=null!==(s=null==u?void 0:u.label)&&void 0!==s?s:"",f=!!this._originalDeviceId&&l===this._originalDeviceId&&!!this._originalDeviceLabel&&d===this._originalDeviceLabel,!this.isPaused||this.IsMicrophoneMuted&&!f||this.onMicReady&&!this._micReadyFired&&(this._micReadyFired=!0,setTimeout(function(){p._micReadyFired=!1},300),this.onMicReady()),this.log("Audio graph recovery completed"),e.next=34;break;case 31:e.prev=31,e.t0=e.catch(3),console.error("Recovery failed",e.t0);case 34:return e.prev=34,this.isRecovering=!1,e.finish(34);case 37:case"end":return e.stop()}},e,this,[[3,31,34,37]])})),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,i){e.setInt16(2*i,t,!0)});var t=e.buffer.byteLength,i=44+t,n=new DataView(new ArrayBuffer(i));n.setUint32(0,1380533830,!1),n.setUint32(4,i-8,!0),n.setUint32(8,1463899717,!1),n.setUint32(12,1718449184,!1),n.setUint32(16,16,!0),n.setUint16(20,1,!0),n.setUint16(22,1,!0),n.setUint32(24,16e3,!0),n.setUint32(28,32e3,!0),n.setUint16(32,2,!0),n.setUint16(34,16,!0),n.setUint32(36,1684108385,!1),n.setUint32(40,t,!0);for(var r=0;r<t;r++)n.setInt8(44+r,e.getInt8(r));return n}},{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 i,n,r,o,s,a,c,u,l,d=arguments;return h().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=d.length>1&&void 0!==d[1]?d[1]:350,n=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<i?requestAnimationFrame(o):e(t>n)})});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 i,n,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:i=e.sent,e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(1),e.abrupt("return",null);case 10:n=i.filter(function(e){return"audioinput"===e.kind&&e.deviceId!==t}),r=S(n),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,i,n,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!==(i=o.reconnectAudioDuration)&&void 0!==i?i:0,this.shouldPreIntialiseRecorder=o.shouldPreIntialiseRecorder,this.switchToRegularSpeechProfile=null!==(n=o.switchToRegularSpeechProfile)&&void 0!==n&&n,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,i=this,n=!(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(n),this.streamer=null,this.log("Stream Stopped..."),this.shouldPreIntialiseRecorder&&setTimeout(function(){i.needsDispose?i.needsDispose=!1:(i.initialiseStreamer(),i.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 i;return function(){for(var n=this,r=arguments.length,o=new Array(r),s=0;s<r;s++)o[s]=arguments[s];i&&clearTimeout(i),i=setTimeout(function(){return e.apply(n,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"),i={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,ConfigTypeId:t};return yield this.makePostRequest(e,i)})}getOrgConfigMapping(t){return e(this,void 0,void 0,function*(){const e=this.getURL("/configmapping").replace("/v1","/v2"),i={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,ConfigTypeId:t};return yield this.makePostRequest(e,i)})}getUserConfigSettings(t){return e(this,void 0,void 0,function*(){const e=this.getURL("/userconfigmapping"),i={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,ConfigTypeId:t};return yield this.makePostRequest(e,i)})}updateUserConfig(t){return e(this,void 0,void 0,function*(){const e=this.getURL("/userconfigmapping"),i={SubscriptionCode:this._config.subscriptionCode,AccessKey:this._config.accessKey,UserTag:this._config.userTag,UserConfigMapping:t};return yield this.makePatchRequest(e,i)})}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,i,n,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:i,HighlightMedicalTerms:n,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",ie="Job Id is empty",ne="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 i=e.timeoutMs||pe.DEFAULT_TIMEOUT;if(!pe.isBrowserOnline())return!1;pe.isValidHttpUrl(t)||(t=pe.DEFAULT_URL);const n=new AbortController,r=setTimeout(()=>n.abort(),i);try{return yield fetch(t,{method:"HEAD",mode:"no-cors",cache:"no-cache",signal:n.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,i,n,r,o;this.recorderIns=new F({serverURL:e,enableLogs:null!==(t=this.enableLog)&&void 0!==t&&t,isDebug:null!==(i=this.enableLog)&&void 0!==i&&i,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!==(n=this.echoCancellation)&&void 0!==n&&n,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,i,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.ListJobs(t,i,null==n||n);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,i){return e(this,void 0,void 0,function*(){try{return this._ambientRestAPI?yield this._ambientRestAPI.SendFinalNote(t,i):void d.error("SDK not initialized",this._logTag)}catch(e){this.handleException(e)}})}toggleListening(t,i,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(n.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,i,r,o,a,c))||"";this.recorderIns||this.initRecorder(d),null===(u=this.recorderIns)||void 0===u||u.toggleStartStopAudioStream(s,d)})}togglePauseResumeListening(t,i,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(n.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,i,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,i){return e(this,void 0,void 0,function*(){var e;try{if(!this._ambientRestAPI)return void d.error("SDK not initialized",this._logTag);var n=yield this._ambientRestAPI.DeleteNotes(t,i);if(n){if(200===n.Status)return null===(e=this.recorderIns)||void 0===e||e.stopAudio(!1,!0),n;this.onErrorCallback(n.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}renameNoteTitle(t,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.RenameNoteTitle(t,i);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}getNotePDF(t,i,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=yield this._ambientRestAPI.DownloadNotePDF(t,i,n,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,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=1,a=yield this._ambientPaceAPI.getOrgConfigMapping(n.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,i,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,i,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.UpdatePatientContext(t,i,n);if(e){if(200===e.Status)return e;this.onErrorCallback(e.ServerMessage)}else this.onErrorCallback("Unknown Error!")}catch(e){this.handleException(e)}})}modifyGeneratedNote(t,i,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.ModifyGeneratedNote(t,i,n);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,i,n,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,i,null!=n?n:"",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,i,n,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!==(i=t.PreferredTranscriptionLanguage)&&void 0!==i?i:"English",null!==(n=t.HighlightMedicalTerms)&&void 0!==n&&n,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 i,n,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===(i=this.recorderIns)||void 0===i||i.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===(n=S.ErrorMessage)||void 0===n?void 0:n.includes(ie))?S.ErrorCode=o.SDK01:(null===(r=S.ErrorMessage)||void 0===r?void 0:r.includes(ne))?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 i;try{i="string"==typeof e?JSON.parse(e):e}catch(e){return void d.error(`Error parsing session event data: ${e}`,this._logTag)}if(!i||!("Type"in i))return;if("meta"===i.Type.toLowerCase()&&(null===(t=this.config)||void 0===t?void 0:t.onMetaEvent)){if(!i.JobID)return void d.error("JobID is missing in meta event",this._logTag);this.config.onMetaEvent(i.JobID)}else"error"===i.Type.toLowerCase()&&i.Data&&this.onErrorCallback(i.Data);if("object"!=typeof i.Event||null===i.Event)return;const{Type:n,Value:r}=i.Event;n&&("SESSION_CREATED"===n&&r?d.log(`session Token ${r}`,this._logTag):"SERVICE_DOWN"===n?d.error(n,this._logTag):"NO_DICTATION_STOP_MIC"===n?(d.log("NO_DICTATION_STOP_MIC",this._logTag),this.onIdleMicCallback()):"INVALID_AUTH_CREDENTIALS"===n?d.error("INVALID_AUTH_CREDENTIALS",this._logTag):"LOW_BANDWIDTH"===n&&d.log("LOW_BANDWIDTH: Check internet connection",this._logTag))}validateConfig(e){return i.Against.NullOrEmpty(e.server,"Server"),i.Against.NullOrEmpty(e.subscriptionCode,"SubscriptionCode"),i.Against.NullOrEmpty(e.accessKey,"AccessKey"),i.Against.NullOrEmpty(e.userTag,"UserTag"),e}createSocketConfig(e){const i=new t(e);return i.onError=this.onErrorCallback.bind(this),i.onMetaEvent=this.onEventCallback.bind(this),i}}export{ge as AugnitoAmbient,o as ErrorCodes,c as HttpCodedError,a as NoteOutputStyleConfig,r as NoteTypeConfig,s as NoteVerbosityConfig,n as SettingsConfigType};
1
+ function e(e, t, n, i) {
2
+ return new (n || (n = Promise))(function (r, o) {
3
+ function s(e) {
4
+ try {
5
+ c(i.next(e));
6
+ } catch (e) {
7
+ o(e);
8
+ }
9
+ }
10
+ function a(e) {
11
+ try {
12
+ c(i.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 n
23
+ ? t
24
+ : new n(function (e) {
25
+ e(t);
26
+ })).then(s, a);
27
+ }
28
+ c((i = i.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, n, i, 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
+ n && "" !== n && (s += `&filename=${n}`),
69
+ i && "" !== i && (s += `&jobid=${i}`),
70
+ r && "" !== r && (s += `&parentjobid=${r}`),
71
+ void 0 !== o && (s += `&inheritparentconfig=${o}`),
72
+ s
73
+ );
74
+ }
75
+ }
76
+ class n {
77
+ constructor() {}
78
+ static get Against() {
79
+ return n.instance || (n.instance = new n()), n.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 = n.Against.NullOrUndefined(e, t)))
88
+ throw new TypeError(`${t} is empty`);
89
+ return e;
90
+ }
91
+ }
92
+ var i, 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
+ })(i || (i = {})),
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, n) {
158
+ return e(this, void 0, void 0, function* () {
159
+ try {
160
+ const i = yield fetch(t, {
161
+ method: "POST",
162
+ headers: { "Content-Type": "application/json" },
163
+ body: JSON.stringify(n),
164
+ });
165
+ if (!i.ok) {
166
+ const t = yield i.text();
167
+ var e = JSON.parse(t);
168
+ throw new c(e.message, e.code.toString());
169
+ }
170
+ return yield i.json();
171
+ } catch (e) {
172
+ throw e;
173
+ }
174
+ });
175
+ }
176
+ makePatchRequest(t, n) {
177
+ return e(this, void 0, void 0, function* () {
178
+ try {
179
+ const i = yield fetch(t, {
180
+ method: "PATCH",
181
+ headers: { "Content-Type": "application/json" },
182
+ body: JSON.stringify(n),
183
+ });
184
+ if (!i.ok) {
185
+ const t = yield i.text();
186
+ var e = JSON.parse(t);
187
+ throw new c(e.message, i.status.toString());
188
+ }
189
+ return yield i.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, i, r) {
230
+ return e(this, void 0, void 0, function* () {
231
+ n.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: i,
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
+ n.Against.NullOrEmpty(t, "Job Id");
247
+ const e = this.getURL("/fetch-job"),
248
+ i = {
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, i);
255
+ });
256
+ }
257
+ SendFinalNote(t, i) {
258
+ return e(this, void 0, void 0, function* () {
259
+ n.Against.NullOrEmpty(t, "Job Id"), n.Against.NullOrEmpty(i, "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: i,
267
+ };
268
+ return yield this.makePostRequest(e, r);
269
+ });
270
+ }
271
+ DeleteNotes(t, i) {
272
+ return e(this, void 0, void 0, function* () {
273
+ n.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: i,
281
+ };
282
+ return yield this.makePostRequest(e, r);
283
+ });
284
+ }
285
+ RenameNoteTitle(t, i) {
286
+ return e(this, void 0, void 0, function* () {
287
+ n.Against.NullOrEmpty(t, "Job Id"), n.Against.NullOrEmpty(i, "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: i,
295
+ };
296
+ return yield this.makePostRequest(e, r);
297
+ });
298
+ }
299
+ DownloadNotePDF(t, i, r, o, s, a) {
300
+ return e(this, void 0, void 0, function* () {
301
+ n.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: i,
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
+ n.Against.NullOrEmpty(t, "Job Id");
324
+ const e = this.getURL("/end-job"),
325
+ i = {
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, i);
332
+ });
333
+ }
334
+ UpdatePatientContext(t, i, r) {
335
+ return e(this, void 0, void 0, function* () {
336
+ n.Against.NullOrEmpty(t, "Job Id"),
337
+ n.Against.NullOrEmpty(i, "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: i,
345
+ Replace: r,
346
+ };
347
+ return yield this.makePostRequest(e, o);
348
+ });
349
+ }
350
+ GenerateSuggestions(t, i, r, o, s, a) {
351
+ return e(this, void 0, void 0, function* () {
352
+ n.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: i,
361
+ SoapData: r,
362
+ PatientContext: o,
363
+ Codes: s,
364
+ };
365
+ return yield this.makePostRequest(e, c);
366
+ });
367
+ }
368
+ ModifyGeneratedNote(t, i, r) {
369
+ return e(this, void 0, void 0, function* () {
370
+ n.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: i,
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
+ n.Against.NullOrEmpty(t, "Job Id");
386
+ const e = this.getURL("/fetch-transcript"),
387
+ i = {
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, i);
394
+ });
395
+ }
396
+ SendFeedback(t, i, r, o) {
397
+ return e(this, void 0, void 0, function* () {
398
+ n.Against.NullOrEmpty(t, "Job Id"),
399
+ n.Against.NullOrUndefined(i, "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: i,
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 n = null != t ? t : this.defaultTag;
417
+ console.log(`${n}:`, e);
418
+ }
419
+ static error(e, t) {
420
+ const n = null != t ? t : this.defaultTag;
421
+ console.error(`${n}:`, e);
422
+ }
423
+ }
424
+ function h() {
425
+ h = function () {
426
+ return t;
427
+ };
428
+ var e,
429
+ t = {},
430
+ n = Object.prototype,
431
+ i = n.hasOwnProperty,
432
+ r =
433
+ Object.defineProperty ||
434
+ function (e, t, n) {
435
+ e[t] = n.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, n) {
442
+ return (
443
+ Object.defineProperty(e, t, {
444
+ value: n,
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, n) {
456
+ return (e[t] = n);
457
+ };
458
+ }
459
+ function l(e, t, n, i) {
460
+ var o = t && t.prototype instanceof m ? t : m,
461
+ s = Object.create(o.prototype),
462
+ a = new _(i || []);
463
+ return r(s, "_invoke", { value: w(e, n, a) }), s;
464
+ }
465
+ function d(e, t, n) {
466
+ try {
467
+ return { type: "normal", arg: e.call(t, n) };
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 !== n && i.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 n(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 && i.call(l, "__await")
503
+ ? t.resolve(l.__await).then(
504
+ function (e) {
505
+ n("next", e, s, a);
506
+ },
507
+ function (e) {
508
+ n("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 n("throw", e, s, a);
517
+ },
518
+ );
519
+ }
520
+ a(c.arg);
521
+ }
522
+ var o;
523
+ r(this, "_invoke", {
524
+ value: function (e, i) {
525
+ function r() {
526
+ return new t(function (t, r) {
527
+ n(e, i, t, r);
528
+ });
529
+ }
530
+ return (o = o ? o.then(r, r) : r());
531
+ },
532
+ });
533
+ }
534
+ function w(t, n, i) {
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 (i.method = o, i.arg = s; ; ) {
543
+ var a = i.delegate;
544
+ if (a) {
545
+ var c = P(a, i);
546
+ if (c) {
547
+ if (c === b) continue;
548
+ return c;
549
+ }
550
+ }
551
+ if ("next" === i.method) i.sent = i._sent = i.arg;
552
+ else if ("throw" === i.method) {
553
+ if (r === f) throw ((r = v), i.arg);
554
+ i.dispatchException(i.arg);
555
+ } else "return" === i.method && i.abrupt("return", i.arg);
556
+ r = g;
557
+ var u = d(t, n, i);
558
+ if ("normal" === u.type) {
559
+ if (((r = i.done ? v : p), u.arg === b)) continue;
560
+ return { value: u.arg, done: i.done };
561
+ }
562
+ "throw" === u.type && ((r = v), (i.method = "throw"), (i.arg = u.arg));
563
+ }
564
+ };
565
+ }
566
+ function P(t, n) {
567
+ var i = n.method,
568
+ r = t.iterator[i];
569
+ if (r === e)
570
+ return (
571
+ (n.delegate = null),
572
+ ("throw" === i &&
573
+ t.iterator.return &&
574
+ ((n.method = "return"),
575
+ (n.arg = e),
576
+ P(t, n),
577
+ "throw" === n.method)) ||
578
+ ("return" !== i &&
579
+ ((n.method = "throw"),
580
+ (n.arg = new TypeError(
581
+ "The iterator does not provide a '" + i + "' method",
582
+ )))),
583
+ b
584
+ );
585
+ var o = d(r, t.iterator, n.arg);
586
+ if ("throw" === o.type)
587
+ return (n.method = "throw"), (n.arg = o.arg), (n.delegate = null), b;
588
+ var s = o.arg;
589
+ return s
590
+ ? s.done
591
+ ? ((n[t.resultName] = s.value),
592
+ (n.next = t.nextLoc),
593
+ "return" !== n.method && ((n.method = "next"), (n.arg = e)),
594
+ (n.delegate = null),
595
+ b)
596
+ : s
597
+ : ((n.method = "throw"),
598
+ (n.arg = new TypeError("iterator result is not an object")),
599
+ (n.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 n = t[s];
620
+ if (n) return n.call(t);
621
+ if ("function" == typeof t.next) return t;
622
+ if (!isNaN(t.length)) {
623
+ var r = -1,
624
+ o = function n() {
625
+ for (; ++r < t.length; )
626
+ if (i.call(t, r)) return (n.value = t[r]), (n.done = !1), n;
627
+ return (n.value = e), (n.done = !0), n;
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, n, i, r, o) {
663
+ void 0 === o && (o = Promise);
664
+ var s = new R(l(e, n, i, r), o);
665
+ return t.isGeneratorFunction(n)
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
+ n = [];
682
+ for (var i in t) n.push(i);
683
+ return (
684
+ n.reverse(),
685
+ function e() {
686
+ for (; n.length; ) {
687
+ var i = n.pop();
688
+ if (i in t) return (e.value = i), (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 n in this)
710
+ "t" === n.charAt(0) &&
711
+ i.call(this, n) &&
712
+ !isNaN(+n.slice(1)) &&
713
+ (this[n] = 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 n = this;
724
+ function r(i, r) {
725
+ return (
726
+ (a.type = "throw"),
727
+ (a.arg = t),
728
+ (n.next = i),
729
+ r && ((n.method = "next"), (n.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 = i.call(s, "catchLoc"),
739
+ u = i.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 n = this.tryEntries.length - 1; n >= 0; --n) {
754
+ var r = this.tryEntries[n];
755
+ if (
756
+ r.tryLoc <= this.prev &&
757
+ i.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 n = this.tryEntries[t];
794
+ if (n.finallyLoc === e)
795
+ return this.complete(n.completion, n.afterLoc), T(n), b;
796
+ }
797
+ },
798
+ catch: function (e) {
799
+ for (var t = this.tryEntries.length - 1; t >= 0; --t) {
800
+ var n = this.tryEntries[t];
801
+ if (n.tryLoc === e) {
802
+ var i = n.completion;
803
+ if ("throw" === i.type) {
804
+ var r = i.arg;
805
+ T(n);
806
+ }
807
+ return r;
808
+ }
809
+ }
810
+ throw Error("illegal catch attempt");
811
+ },
812
+ delegateYield: function (t, n, i) {
813
+ return (
814
+ (this.delegate = { iterator: O(t), resultName: n, nextLoc: i }),
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 n = e[Symbol.toPrimitive];
827
+ if (void 0 !== n) {
828
+ var i = n.call(e, t || "default");
829
+ if ("object" != typeof i) return i;
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, n, i, r, o, s) {
837
+ try {
838
+ var a = e[o](s),
839
+ c = a.value;
840
+ } catch (e) {
841
+ return void n(e);
842
+ }
843
+ a.done ? t(c) : Promise.resolve(c).then(i, r);
844
+ }
845
+ function g(e) {
846
+ return function () {
847
+ var t = this,
848
+ n = arguments;
849
+ return new Promise(function (i, r) {
850
+ var o = e.apply(t, n);
851
+ function s(e) {
852
+ p(o, i, r, s, a, "next", e);
853
+ }
854
+ function a(e) {
855
+ p(o, i, 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 n = 0; n < t.length; n++) {
867
+ var i = t[n];
868
+ (i.enumerable = i.enumerable || !1),
869
+ (i.configurable = !0),
870
+ "value" in i && (i.writable = !0),
871
+ Object.defineProperty(e, f(i.key), i);
872
+ }
873
+ }
874
+ function m(e, t, n) {
875
+ return (
876
+ t && b(e.prototype, t),
877
+ n && b(e, n),
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 n = 0, i = new Array(t); n < t; n++) i[n] = e[n];
885
+ return i;
886
+ }
887
+ function S(e, t) {
888
+ var n =
889
+ ("undefined" != typeof Symbol && e[Symbol.iterator]) || e["@@iterator"];
890
+ if (!n) {
891
+ if (
892
+ Array.isArray(e) ||
893
+ (n = (function (e, t) {
894
+ if (e) {
895
+ if ("string" == typeof e) return y(e, t);
896
+ var n = Object.prototype.toString.call(e).slice(8, -1);
897
+ return (
898
+ "Object" === n && e.constructor && (n = e.constructor.name),
899
+ "Map" === n || "Set" === n
900
+ ? Array.from(e)
901
+ : "Arguments" === n ||
902
+ /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)
903
+ ? y(e, t)
904
+ : void 0
905
+ );
906
+ }
907
+ })(e)) ||
908
+ (t && e && "number" == typeof e.length)
909
+ ) {
910
+ n && (e = n);
911
+ var i = 0,
912
+ r = function () {};
913
+ return {
914
+ s: r,
915
+ n: function () {
916
+ return i >= e.length ? { done: !0 } : { done: !1, value: e[i++] };
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
+ n = n.call(e);
934
+ },
935
+ n: function () {
936
+ var e = n.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 == n.return || n.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, n, i, 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 = n || "EOS"),
981
+ (this.socketTimeoutInterval = i || 1e4),
982
+ (this.bufferSizeInterval = h),
983
+ (this.switchToRegularSpeech = f);
984
+ },
985
+ [
986
+ {
987
+ key: "Start",
988
+ value: function (e, t, n) {
989
+ var i = 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(n), ", ")
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
+ i.enableLogs &&
1018
+ console.log("Augnito [MAIN]: " + JSON.stringify(e.data));
1019
+ var t = e.data;
1020
+ "final" == t.type
1021
+ ? i.onFinalResultCallback(t.data)
1022
+ : "partial" == t.type
1023
+ ? i.onPartialResultCallback(t.data)
1024
+ : "meta" == t.type
1025
+ ? i.onSessionEventCallback(t.data)
1026
+ : "error" == t.type
1027
+ ? i.onErrorCallback(t.data)
1028
+ : "other" == t.type
1029
+ ? i.onOtherResultsCallback(t.data)
1030
+ : "jobstatus" == t.type
1031
+ ? i.onJobStatusCallback(t.data.status)
1032
+ : "speechResponse" == t.type &&
1033
+ i.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), n = new DataView(t), i = 0;
1047
+ i < 4;
1048
+ i++
1049
+ )
1050
+ n.setUint8(i, "@BSR".charCodeAt(i));
1051
+ return (
1052
+ n.setBigInt64(4, BigInt(this.packetSeqId), !1),
1053
+ n.setUint8(12, e ? 1 : 0),
1054
+ t
1055
+ );
1056
+ },
1057
+ },
1058
+ {
1059
+ key: "appendAudioData",
1060
+ value: function (e, t) {
1061
+ var n = e.byteLength + t.byteLength,
1062
+ i = new ArrayBuffer(n),
1063
+ r = new Uint8Array(i);
1064
+ return (
1065
+ r.set(new Uint8Array(e), 0),
1066
+ r.set(new Uint8Array(t), e.byteLength),
1067
+ i
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 n,
1080
+ i = this.createAudioPacketHeader(!0);
1081
+ null === (n = this.worker) || void 0 === n || n.postMessage(i);
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
+ ? ((i = this.createAudioPacketHeader(!1)),
1106
+ (l = this.appendAudioData(i, 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, n, i, 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 n = JSON.parse(e.data);
1174
+ x = !(
1175
+ !n.Event || "INVALID_AUTH_CREDENTIALS" !== n.Event.Type
1176
+ );
1177
+ } else if (t.Result && t.Result.Final) {
1178
+ var i = JSON.stringify(t.Result);
1179
+ b && ((i = b(JSON.stringify(t.Result))), console.log(i)),
1180
+ self.postMessage({ type: "final", data: i });
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 n = +new Date();
1231
+ return y <= S && (S = n - 1), (y = n), !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 > i && !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 n = new DataView(t),
1272
+ i = { packetNumber: Number(n.getBigInt64(4)), packetData: t };
1273
+ T.push(i);
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 (i) {
1307
+ if (i.data === n) (N = ""), (_ = !0), (x = !0), E.close();
1308
+ else if (i.data === e)
1309
+ J(t),
1310
+ (N = ""),
1311
+ l &&
1312
+ console.log("Augnito: Worker received DONE, time to terminate..."),
1313
+ (_ = !0);
1314
+ else if (i.data === h) U = !0;
1315
+ else if (i.data === p) D = !0;
1316
+ else if (i.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 = i.data) : U && D ? P.push(i.data) : J(i.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
+ n,
1337
+ i,
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(n, 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 = i),
1373
+ (this.enableLogs = n),
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._originalDeviceLabel = null),
1395
+ this.shouldPreIntialiseRecorder && this.InitialiseMediaStream(u, t);
1396
+ },
1397
+ [
1398
+ {
1399
+ key: "InitialiseMediaStream",
1400
+ value:
1401
+ ((M = g(
1402
+ h().mark(function e(t, n) {
1403
+ var i = this;
1404
+ return h().wrap(
1405
+ function (e) {
1406
+ for (;;)
1407
+ switch ((e.prev = e.next)) {
1408
+ case 0:
1409
+ return (
1410
+ (this.currentDuration = t),
1411
+ (this.currentWsUrl = n),
1412
+ (e.next = 4),
1413
+ this.createMediaStreamSourceNode()
1414
+ );
1415
+ case 4:
1416
+ if (this.source) {
1417
+ e.next = 7;
1418
+ break;
1419
+ }
1420
+ return (
1421
+ console.error("Error: unable to create source node"),
1422
+ e.abrupt("return", !1)
1423
+ );
1424
+ case 7:
1425
+ return (e.next = 9), this.createProcessorNode();
1426
+ case 9:
1427
+ if (this.processorNode) {
1428
+ e.next = 12;
1429
+ break;
1430
+ }
1431
+ return (
1432
+ console.error(
1433
+ "Error: unable to create processor node",
1434
+ ),
1435
+ e.abrupt("return", !1)
1436
+ );
1437
+ case 12:
1438
+ this.source
1439
+ .connect(this.processorNode)
1440
+ .connect(this.audioContext.destination),
1441
+ this.log(
1442
+ "AudioContext Sample Rate: " +
1443
+ this.audioContext.sampleRate,
1444
+ ),
1445
+ "" !== n &&
1446
+ this.executor.Start(
1447
+ t,
1448
+ n,
1449
+ this.shouldPreIntialiseRecorder,
1450
+ ),
1451
+ this.deviceChangeHandler ||
1452
+ ((this.deviceChangeHandler = g(
1453
+ h().mark(function e() {
1454
+ var t, n, r, o, s, a, c;
1455
+ return h().wrap(function (e) {
1456
+ for (;;)
1457
+ switch ((e.prev = e.next)) {
1458
+ case 0:
1459
+ if (
1460
+ (s =
1461
+ null === (t = i.audioStream) ||
1462
+ void 0 === t ||
1463
+ null === (n = t.getAudioTracks) ||
1464
+ void 0 === n
1465
+ ? void 0
1466
+ : n.call(t)[0]) &&
1467
+ "ended" !== s.readyState
1468
+ ) {
1469
+ e.next = 7;
1470
+ break;
1471
+ }
1472
+ return (
1473
+ (i.micNeedsRecovery = !0),
1474
+ (e.next = 6),
1475
+ i.recoverAudioGraph()
1476
+ );
1477
+ case 6:
1478
+ return e.abrupt("return");
1479
+ case 7:
1480
+ return (
1481
+ (a =
1482
+ null !==
1483
+ (r =
1484
+ null === (o = s.getSettings) ||
1485
+ void 0 === o ||
1486
+ null === (o = o.call(s)) ||
1487
+ void 0 === o
1488
+ ? void 0
1489
+ : o.deviceId) && void 0 !== r
1490
+ ? r
1491
+ : s.label),
1492
+ i.log(
1493
+ 'Device change detected. Probing current device: "'.concat(
1494
+ s.label,
1495
+ '"',
1496
+ ),
1497
+ ),
1498
+ (e.next = 11),
1499
+ K(a)
1500
+ );
1501
+ case 11:
1502
+ if (e.sent) {
1503
+ e.next = 23;
1504
+ break;
1505
+ }
1506
+ return (
1507
+ i.log(
1508
+ 'Current device "'.concat(
1509
+ s.label,
1510
+ '" appears silent/virtual. Searching for a real input device...',
1511
+ ),
1512
+ ),
1513
+ (i.micNeedsRecovery = !0),
1514
+ (e.next = 17),
1515
+ W(a, i.enableLogs)
1516
+ );
1517
+ case 17:
1518
+ return (
1519
+ (c = e.sent)
1520
+ ? (i._preferredDeviceId = c)
1521
+ : (i.log(
1522
+ "No active audio input device found after device change",
1523
+ ),
1524
+ (i._preferredDeviceId = null)),
1525
+ (e.next = 21),
1526
+ i.recoverAudioGraph()
1527
+ );
1528
+ case 21:
1529
+ e.next = 24;
1530
+ break;
1531
+ case 23:
1532
+ i.log(
1533
+ 'Current device "'.concat(
1534
+ s.label,
1535
+ '" is producing audio — no switch needed',
1536
+ ),
1537
+ );
1538
+ case 24:
1539
+ case "end":
1540
+ return e.stop();
1541
+ }
1542
+ }, e);
1543
+ }),
1544
+ )),
1545
+ navigator.mediaDevices.addEventListener(
1546
+ "devicechange",
1547
+ this.deviceChangeHandler,
1548
+ ));
1549
+ case 16:
1550
+ case "end":
1551
+ return e.stop();
1552
+ }
1553
+ },
1554
+ e,
1555
+ this,
1556
+ );
1557
+ }),
1558
+ )),
1559
+ function (e, t) {
1560
+ return M.apply(this, arguments);
1561
+ }),
1562
+ },
1563
+ {
1564
+ key: "StartStream",
1565
+ value:
1566
+ ((L = g(
1567
+ h().mark(function e(t, n) {
1568
+ var i, r;
1569
+ return h().wrap(
1570
+ function (e) {
1571
+ for (;;)
1572
+ switch ((e.prev = e.next)) {
1573
+ case 0:
1574
+ if (
1575
+ (this.log("New stream started..."),
1576
+ this.shouldPreIntialiseRecorder && this.source)
1577
+ ) {
1578
+ e.next = 6;
1579
+ break;
1580
+ }
1581
+ return (
1582
+ (e.next = 4), this.InitialiseMediaStream(t, n, !1)
1583
+ );
1584
+ case 4:
1585
+ e.next = 7;
1586
+ break;
1587
+ case 6:
1588
+ this.shouldPreIntialiseRecorder &&
1589
+ this.executor.Send(E);
1590
+ case 7:
1591
+ if (!this.IsMicrophoneMuted) {
1592
+ e.next = 15;
1593
+ break;
1594
+ }
1595
+ if (
1596
+ !this.audioContext ||
1597
+ "running" != this.audioContext.state
1598
+ ) {
1599
+ e.next = 11;
1600
+ break;
1601
+ }
1602
+ return (e.next = 11), this.audioContext.suspend();
1603
+ case 11:
1604
+ return (
1605
+ null === (i = this.audioStream) ||
1606
+ void 0 === i ||
1607
+ null === (r = i.getTracks) ||
1608
+ void 0 === r ||
1609
+ null === (r = r.call(i)) ||
1610
+ void 0 === r ||
1611
+ r.forEach(function (e) {
1612
+ try {
1613
+ e.stop();
1614
+ } catch (e) {}
1615
+ }),
1616
+ this.executor.Send(A),
1617
+ this.onError(
1618
+ JSON.stringify({
1619
+ Type: "ERROR",
1620
+ Data: "Microphone is muted.",
1621
+ }),
1622
+ ),
1623
+ e.abrupt("return", !1)
1624
+ );
1625
+ case 15:
1626
+ return (
1627
+ this.onStateChanged(!0),
1628
+ (this.isStreaming = !0),
1629
+ e.abrupt("return", !0)
1630
+ );
1631
+ case 18:
1632
+ case "end":
1633
+ return e.stop();
1634
+ }
1635
+ },
1636
+ e,
1637
+ this,
1638
+ );
1639
+ }),
1640
+ )),
1641
+ function (e, t) {
1642
+ return L.apply(this, arguments);
1643
+ }),
1644
+ },
1645
+ {
1646
+ key: "createBufferedSourceNode",
1647
+ value:
1648
+ ((U = g(
1649
+ h().mark(function e() {
1650
+ var t;
1651
+ return h().wrap(
1652
+ function (e) {
1653
+ for (;;)
1654
+ switch ((e.prev = e.next)) {
1655
+ case 0:
1656
+ return (e.next = 2), this.loadAudio();
1657
+ case 2:
1658
+ if ((t = e.sent)) {
1659
+ e.next = 6;
1660
+ break;
1661
+ }
1662
+ return (
1663
+ console.error("Error: unable to create audio buffer"),
1664
+ e.abrupt("return")
1665
+ );
1666
+ case 6:
1667
+ (this.source = this.audioContext.createBufferSource()),
1668
+ (this.source.buffer = t),
1669
+ (this.source.loop = !0),
1670
+ this.source.start();
1671
+ case 10:
1672
+ case "end":
1673
+ return e.stop();
1674
+ }
1675
+ },
1676
+ e,
1677
+ this,
1678
+ );
1679
+ }),
1680
+ )),
1681
+ function () {
1682
+ return U.apply(this, arguments);
1683
+ }),
1684
+ },
1685
+ {
1686
+ key: "createMediaStreamSourceNode",
1687
+ value:
1688
+ ((N = g(
1689
+ h().mark(function e() {
1690
+ var t,
1691
+ n,
1692
+ i,
1693
+ r,
1694
+ o,
1695
+ s,
1696
+ a,
1697
+ c,
1698
+ u = this;
1699
+ return h().wrap(
1700
+ function (e) {
1701
+ for (;;)
1702
+ switch ((e.prev = e.next)) {
1703
+ case 0:
1704
+ return (
1705
+ (e.prev = 0),
1706
+ (r = {
1707
+ channelCount: 1,
1708
+ noiseSuppression:
1709
+ void 0 !== this.noiseSuppression &&
1710
+ this.noiseSuppression,
1711
+ }),
1712
+ void 0 !== this.echoCancellation &&
1713
+ ((r.echoCancellation = this.echoCancellation),
1714
+ (r.googEchoCancellation = this.echoCancellation)),
1715
+ void 0 !== this.noiseSuppression &&
1716
+ (r.googNoiseSuppression = this.noiseSuppression),
1717
+ void 0 !== this.autoGainControl &&
1718
+ ((r.autoGainControl = this.autoGainControl),
1719
+ (r.googAutoGainControl = this.autoGainControl)),
1720
+ this._preferredDeviceId &&
1721
+ (r.deviceId = { exact: this._preferredDeviceId }),
1722
+ (e.next = 8),
1723
+ navigator.mediaDevices.getUserMedia({ audio: r })
1724
+ );
1725
+ case 8:
1726
+ (this.audioStream = e.sent),
1727
+ (this.audioContext &&
1728
+ "closed" !== this.audioContext.state) ||
1729
+ (this.audioContext = new AudioContext()),
1730
+ (this.source =
1731
+ this.audioContext.createMediaStreamSource(
1732
+ this.audioStream,
1733
+ )),
1734
+ (o = this.audioStream.getAudioTracks()[0]),
1735
+ (s =
1736
+ null !==
1737
+ (t =
1738
+ null === (n = o.getSettings) ||
1739
+ void 0 === n ||
1740
+ null === (n = n.call(o)) ||
1741
+ void 0 === n
1742
+ ? void 0
1743
+ : n.deviceId) && void 0 !== t
1744
+ ? t
1745
+ : ""),
1746
+ (a = null !== (i = o.label) && void 0 !== i ? i : ""),
1747
+ this._originalDeviceId ||
1748
+ ((this._originalDeviceId = s),
1749
+ (this._originalDeviceLabel = a)),
1750
+ this.trackEndedHandler &&
1751
+ (this.trackEndedHandler = null),
1752
+ (this.trackEndedHandler = function () {
1753
+ (u.micNeedsRecovery = !0),
1754
+ u.onError(
1755
+ JSON.stringify({
1756
+ Type: "ERROR",
1757
+ Data: "Audio track ended. Possibly the mic was unplugged.",
1758
+ }),
1759
+ );
1760
+ }),
1761
+ o.addEventListener("ended", this.trackEndedHandler),
1762
+ (e.next = 25);
1763
+ break;
1764
+ case 20:
1765
+ (e.prev = 20),
1766
+ (e.t0 = e.catch(0)),
1767
+ (c = ""),
1768
+ "NotAllowedError" == e.t0.name
1769
+ ? (c = "Mic permission denied")
1770
+ : "NotFoundError" === e.t0.name
1771
+ ? (c = "No suitable media device found")
1772
+ : "NotReadableError" === e.t0.name &&
1773
+ (c =
1774
+ "Microphone is being used by another application"),
1775
+ this.onError(
1776
+ JSON.stringify({ Type: "ERROR", Data: c }),
1777
+ );
1778
+ case 25:
1779
+ case "end":
1780
+ return e.stop();
1781
+ }
1782
+ },
1783
+ e,
1784
+ this,
1785
+ [[0, 20]],
1786
+ );
1787
+ }),
1788
+ )),
1789
+ function () {
1790
+ return N.apply(this, arguments);
1791
+ }),
1792
+ },
1793
+ {
1794
+ key: "loadAudio",
1795
+ value:
1796
+ ((x = g(
1797
+ h().mark(function e() {
1798
+ var t, n, i;
1799
+ return h().wrap(
1800
+ function (e) {
1801
+ for (;;)
1802
+ switch ((e.prev = e.next)) {
1803
+ case 0:
1804
+ return (
1805
+ (e.prev = 0),
1806
+ (e.next = 3),
1807
+ fetch("./radiology_speed_test.wav")
1808
+ );
1809
+ case 3:
1810
+ return (t = e.sent), (e.next = 6), t.arrayBuffer();
1811
+ case 6:
1812
+ return (
1813
+ (n = e.sent),
1814
+ (e.next = 9),
1815
+ this.audioContext.decodeAudioData(n)
1816
+ );
1817
+ case 9:
1818
+ return (i = e.sent), e.abrupt("return", i);
1819
+ case 13:
1820
+ return (
1821
+ (e.prev = 13),
1822
+ (e.t0 = e.catch(0)),
1823
+ console.error(
1824
+ "Unable to fetch the audio file. Error: ".concat(
1825
+ e.t0.message,
1826
+ ),
1827
+ ),
1828
+ e.abrupt("return", null)
1829
+ );
1830
+ case 17:
1831
+ case "end":
1832
+ return e.stop();
1833
+ }
1834
+ },
1835
+ e,
1836
+ this,
1837
+ [[0, 13]],
1838
+ );
1839
+ }),
1840
+ )),
1841
+ function () {
1842
+ return x.apply(this, arguments);
1843
+ }),
1844
+ },
1845
+ {
1846
+ key: "createProcessorNode",
1847
+ value:
1848
+ ((O = g(
1849
+ h().mark(function e() {
1850
+ var t,
1851
+ n = this;
1852
+ return h().wrap(
1853
+ function (e) {
1854
+ for (;;)
1855
+ switch ((e.prev = e.next)) {
1856
+ case 0:
1857
+ return (
1858
+ (e.prev = 0),
1859
+ (e.next = 3),
1860
+ this.audioContext.audioWorklet.addModule(
1861
+ "data:application/javascript,".concat(
1862
+ encodeURIComponent(
1863
+ '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);',
1864
+ ),
1865
+ ),
1866
+ )
1867
+ );
1868
+ case 3:
1869
+ (this.processorNode = new AudioWorkletNode(
1870
+ this.audioContext,
1871
+ "worklet-processor",
1872
+ )),
1873
+ this.processorNode.parameters
1874
+ .get("sampleRate")
1875
+ .setValueAtTime(
1876
+ this.audioContext.sampleRate,
1877
+ this.audioContext.currentTime,
1878
+ ),
1879
+ this.processorNode.parameters
1880
+ .get("bufferSizeInterval")
1881
+ .setValueAtTime(
1882
+ this.bufferSizeInterval,
1883
+ this.audioContext.currentTime,
1884
+ ),
1885
+ this.processorNode.parameters
1886
+ .get("pausedBufferInterval")
1887
+ .setValueAtTime(
1888
+ this.pausedBufferInterval,
1889
+ this.audioContext.currentTime,
1890
+ ),
1891
+ this.processorNode.parameters
1892
+ .get("shouldReadIntensity")
1893
+ .setValueAtTime(
1894
+ null !== (t = this.shouldReadIntensity) &&
1895
+ void 0 !== t &&
1896
+ t,
1897
+ this.audioContext.currentTime,
1898
+ ),
1899
+ (this.processorNode.port.onmessage = function (e) {
1900
+ var t = e.data,
1901
+ i = t.type,
1902
+ r = t.value;
1903
+ if (i == C)
1904
+ n.log(
1905
+ "Worklet processing done, clearing resources...",
1906
+ ),
1907
+ n.isDebug && n.saveAudio(),
1908
+ n.cleanup();
1909
+ else if (e.data == k) n.executor.Send(k);
1910
+ else {
1911
+ var o;
1912
+ "intensity" === i
1913
+ ? null === (o = n.onIntensity) ||
1914
+ void 0 === o ||
1915
+ o.call(n, r)
1916
+ : "audioData" === i &&
1917
+ n.isDebug &&
1918
+ new Int16Array(r).forEach(function (e) {
1919
+ n.audioData.length <= 288e5 &&
1920
+ n.audioData.push(e);
1921
+ });
1922
+ }
1923
+ n.executor &&
1924
+ (n.closeSocketWithoutEOS
1925
+ ? (n.executor.Send(A),
1926
+ (n.closeSocketWithoutEOS = !1))
1927
+ : "intensity" !== i && n.executor.Send(r));
1928
+ }),
1929
+ (e.next = 18);
1930
+ break;
1931
+ case 15:
1932
+ (e.prev = 15),
1933
+ (e.t0 = e.catch(0)),
1934
+ console.error(
1935
+ "Error: Unable to create worklet node: ",
1936
+ e.t0,
1937
+ );
1938
+ case 18:
1939
+ case "end":
1940
+ return e.stop();
1941
+ }
1942
+ },
1943
+ e,
1944
+ this,
1945
+ [[0, 15]],
1946
+ );
1947
+ }),
1948
+ )),
1949
+ function () {
1950
+ return O.apply(this, arguments);
1951
+ }),
1952
+ },
1953
+ {
1954
+ key: "PauseStream",
1955
+ value:
1956
+ ((_ = g(
1957
+ h().mark(function e() {
1958
+ return h().wrap(
1959
+ function (e) {
1960
+ for (;;)
1961
+ switch ((e.prev = e.next)) {
1962
+ case 0:
1963
+ if ("running" != this.audioContext.state) {
1964
+ e.next = 9;
1965
+ break;
1966
+ }
1967
+ if (this.shouldPreIntialiseRecorder) {
1968
+ e.next = 8;
1969
+ break;
1970
+ }
1971
+ return (e.next = 4), this.audioContext.suspend();
1972
+ case 4:
1973
+ this.log("Stream paused..."),
1974
+ this.processorNode.port.postMessage("PAUSE"),
1975
+ (e.next = 9);
1976
+ break;
1977
+ case 8:
1978
+ this.processorNode.port.postMessage(k);
1979
+ case 9:
1980
+ this.onStateChanged(!1),
1981
+ (this.isPaused = !0),
1982
+ (this.isStreaming = !1);
1983
+ case 12:
1984
+ case "end":
1985
+ return e.stop();
1986
+ }
1987
+ },
1988
+ e,
1989
+ this,
1990
+ );
1991
+ }),
1992
+ )),
1993
+ function () {
1994
+ return _.apply(this, arguments);
1995
+ }),
1996
+ },
1997
+ {
1998
+ key: "ResumeStream",
1999
+ value:
2000
+ ((T = g(
2001
+ h().mark(function e() {
2002
+ var t, n, i;
2003
+ return h().wrap(
2004
+ function (e) {
2005
+ for (;;)
2006
+ switch ((e.prev = e.next)) {
2007
+ case 0:
2008
+ if (
2009
+ (i =
2010
+ null === (t = this.audioStream) ||
2011
+ void 0 === t ||
2012
+ null === (n = t.getAudioTracks) ||
2013
+ void 0 === n
2014
+ ? void 0
2015
+ : n.call(t)[0]) &&
2016
+ "ended" !== i.readyState &&
2017
+ !this.micNeedsRecovery
2018
+ ) {
2019
+ e.next = 5;
2020
+ break;
2021
+ }
2022
+ return (e.next = 5), this.recoverAudioGraph();
2023
+ case 5:
2024
+ if (!this.IsMicrophoneMuted) {
2025
+ e.next = 11;
2026
+ break;
2027
+ }
2028
+ if (
2029
+ !this.audioContext ||
2030
+ "running" !== this.audioContext.state
2031
+ ) {
2032
+ e.next = 9;
2033
+ break;
2034
+ }
2035
+ return (e.next = 9), this.audioContext.suspend();
2036
+ case 9:
2037
+ return (
2038
+ this.onError(
2039
+ JSON.stringify({
2040
+ Type: "ERROR",
2041
+ Data: "Microphone is muted.",
2042
+ }),
2043
+ ),
2044
+ e.abrupt("return")
2045
+ );
2046
+ case 11:
2047
+ if (!this.shouldPreIntialiseRecorder) {
2048
+ e.next = 16;
2049
+ break;
2050
+ }
2051
+ this.processorNode.port.postMessage(E),
2052
+ this.executor.Send(E),
2053
+ (e.next = 20);
2054
+ break;
2055
+ case 16:
2056
+ if ("suspended" !== this.audioContext.state) {
2057
+ e.next = 19;
2058
+ break;
2059
+ }
2060
+ return (e.next = 19), this.audioContext.resume();
2061
+ case 19:
2062
+ this.log("Stream resumed...");
2063
+ case 20:
2064
+ this.onStateChanged(!0),
2065
+ (this.isPaused = !1),
2066
+ (this.isStreaming = !0);
2067
+ case 23:
2068
+ case "end":
2069
+ return e.stop();
2070
+ }
2071
+ },
2072
+ e,
2073
+ this,
2074
+ );
2075
+ }),
2076
+ )),
2077
+ function () {
2078
+ return T.apply(this, arguments);
2079
+ }),
2080
+ },
2081
+ {
2082
+ key: "IsPaused",
2083
+ get: function () {
2084
+ return this.isPaused;
2085
+ },
2086
+ },
2087
+ {
2088
+ key: "IsStreaming",
2089
+ get: function () {
2090
+ return this.isStreaming;
2091
+ },
2092
+ },
2093
+ {
2094
+ key: "IsMicrophoneMuted",
2095
+ get: function () {
2096
+ var e,
2097
+ t,
2098
+ n =
2099
+ null === (e = this.audioStream) ||
2100
+ void 0 === e ||
2101
+ null === (t = e.getAudioTracks) ||
2102
+ void 0 === t
2103
+ ? void 0
2104
+ : t.call(e)[0];
2105
+ return !n || n.muted || "ended" === n.readyState;
2106
+ },
2107
+ },
2108
+ {
2109
+ key: "StopStream",
2110
+ value:
2111
+ ((D = g(
2112
+ h().mark(function e(t) {
2113
+ var n, i, r, o, s, a, c, u;
2114
+ return h().wrap(
2115
+ function (e) {
2116
+ for (;;)
2117
+ switch ((e.prev = e.next)) {
2118
+ case 0:
2119
+ if (
2120
+ "suspended" ===
2121
+ (null === (n = this.audioContext) || void 0 === n
2122
+ ? void 0
2123
+ : n.state)
2124
+ ) {
2125
+ e.next = 4;
2126
+ break;
2127
+ }
2128
+ return (
2129
+ (e.next = 3),
2130
+ null === (c = this.audioContext) || void 0 === c
2131
+ ? void 0
2132
+ : c.suspend()
2133
+ );
2134
+ case 3:
2135
+ this.onStateChanged(!1);
2136
+ case 4:
2137
+ this.log("Stream stopped..."),
2138
+ (this.isStreaming = !1),
2139
+ (this.isPaused = !1),
2140
+ (this.closeSocketWithoutEOS = !t),
2141
+ this.deviceChangeHandler &&
2142
+ (navigator.mediaDevices.removeEventListener(
2143
+ "devicechange",
2144
+ this.deviceChangeHandler,
2145
+ ),
2146
+ (this.deviceChangeHandler = null)),
2147
+ (u =
2148
+ null === (i = this.audioStream) ||
2149
+ void 0 === i ||
2150
+ null === (r = i.getAudioTracks) ||
2151
+ void 0 === r
2152
+ ? void 0
2153
+ : r.call(i)[0]) &&
2154
+ this.trackEndedHandler &&
2155
+ u.removeEventListener(
2156
+ "ended",
2157
+ this.trackEndedHandler,
2158
+ ),
2159
+ (this.trackEndedHandler = null),
2160
+ null === (o = this.audioStream) ||
2161
+ void 0 === o ||
2162
+ null === (s = o.getTracks) ||
2163
+ void 0 === s ||
2164
+ null === (s = s.call(o)) ||
2165
+ void 0 === s ||
2166
+ s.forEach(function (e) {
2167
+ try {
2168
+ e.stop();
2169
+ } catch (e) {}
2170
+ }),
2171
+ null === (a = this.processorNode) ||
2172
+ void 0 === a ||
2173
+ null === (a = a.port) ||
2174
+ void 0 === a ||
2175
+ a.postMessage("STOP");
2176
+ case 14:
2177
+ case "end":
2178
+ return e.stop();
2179
+ }
2180
+ },
2181
+ e,
2182
+ this,
2183
+ );
2184
+ }),
2185
+ )),
2186
+ function (e) {
2187
+ return D.apply(this, arguments);
2188
+ }),
2189
+ },
2190
+ {
2191
+ key: "recoverAudioGraph",
2192
+ value:
2193
+ ((P = g(
2194
+ h().mark(function e() {
2195
+ var t,
2196
+ n,
2197
+ i,
2198
+ r,
2199
+ o,
2200
+ s,
2201
+ a,
2202
+ c,
2203
+ u,
2204
+ l,
2205
+ d,
2206
+ f,
2207
+ p,
2208
+ g,
2209
+ v = this;
2210
+ return h().wrap(
2211
+ function (e) {
2212
+ for (;;)
2213
+ switch ((e.prev = e.next)) {
2214
+ case 0:
2215
+ if (!this.isRecovering) {
2216
+ e.next = 2;
2217
+ break;
2218
+ }
2219
+ return e.abrupt("return");
2220
+ case 2:
2221
+ (this.isRecovering = !0),
2222
+ (e.prev = 3),
2223
+ null === (t = this.audioStream) ||
2224
+ void 0 === t ||
2225
+ null === (t = t.getTracks()) ||
2226
+ void 0 === t ||
2227
+ t.forEach(function (e) {
2228
+ try {
2229
+ e.stop();
2230
+ } catch (e) {}
2231
+ });
2232
+ try {
2233
+ null === (a = this.source) ||
2234
+ void 0 === a ||
2235
+ a.disconnect();
2236
+ } catch (e) {}
2237
+ try {
2238
+ null === (c = this.processorNode) ||
2239
+ void 0 === c ||
2240
+ c.disconnect();
2241
+ } catch (e) {}
2242
+ return (e.next = 9), this.createMediaStreamSourceNode();
2243
+ case 9:
2244
+ if (this.source) {
2245
+ e.next = 11;
2246
+ break;
2247
+ }
2248
+ throw new Error("Failed to recreate source");
2249
+ case 11:
2250
+ if (
2251
+ ((this.audioContext &&
2252
+ "closed" !== this.audioContext.state) ||
2253
+ (this.audioContext = new AudioContext()),
2254
+ "suspended" !== this.audioContext.state)
2255
+ ) {
2256
+ e.next = 15;
2257
+ break;
2258
+ }
2259
+ return (e.next = 15), this.audioContext.resume();
2260
+ case 15:
2261
+ return (e.next = 17), this.createProcessorNode();
2262
+ case 17:
2263
+ if (
2264
+ (this.source
2265
+ .connect(this.processorNode)
2266
+ .connect(this.audioContext.destination),
2267
+ this.isStreaming && !this.isPaused)
2268
+ ) {
2269
+ e.next = 22;
2270
+ break;
2271
+ }
2272
+ if ("running" !== this.audioContext.state) {
2273
+ e.next = 22;
2274
+ break;
2275
+ }
2276
+ return (e.next = 22), this.audioContext.suspend();
2277
+ case 22:
2278
+ return (
2279
+ (this.micNeedsRecovery = !1),
2280
+ (u =
2281
+ null === (n = this.audioStream) ||
2282
+ void 0 === n ||
2283
+ null === (i = n.getAudioTracks) ||
2284
+ void 0 === i
2285
+ ? void 0
2286
+ : i.call(n)[0]),
2287
+ (l =
2288
+ null !==
2289
+ (r =
2290
+ null == u ||
2291
+ null === (o = u.getSettings) ||
2292
+ void 0 === o ||
2293
+ null === (o = o.call(u)) ||
2294
+ void 0 === o
2295
+ ? void 0
2296
+ : o.deviceId) && void 0 !== r
2297
+ ? r
2298
+ : ""),
2299
+ (d =
2300
+ null !== (s = null == u ? void 0 : u.label) &&
2301
+ void 0 !== s
2302
+ ? s
2303
+ : ""),
2304
+ (e.next = 28),
2305
+ navigator.mediaDevices.enumerateDevices()
2306
+ );
2307
+ case 28:
2308
+ if (
2309
+ ((f = e.sent),
2310
+ (p = f.some(function (e) {
2311
+ return (
2312
+ "audioinput" === e.kind &&
2313
+ e.label &&
2314
+ e.label === v._originalDeviceLabel
2315
+ );
2316
+ })),
2317
+ console.log("Original device present:", p),
2318
+ console.log("Recovered device:", d),
2319
+ (e.t0 = l),
2320
+ !e.t0)
2321
+ ) {
2322
+ e.next = 37;
2323
+ break;
2324
+ }
2325
+ return (e.next = 36), K(l);
2326
+ case 36:
2327
+ e.t0 = e.sent;
2328
+ case 37:
2329
+ (g = e.t0),
2330
+ this.isPaused &&
2331
+ (g || p) &&
2332
+ this.onMicReady &&
2333
+ !this._micReadyFired &&
2334
+ ((this._micReadyFired = !0),
2335
+ setTimeout(function () {
2336
+ v._micReadyFired = !1;
2337
+ }, 300),
2338
+ this.onMicReady()),
2339
+ this.log("Audio graph recovery completed"),
2340
+ (e.next = 45);
2341
+ break;
2342
+ case 42:
2343
+ (e.prev = 42),
2344
+ (e.t1 = e.catch(3)),
2345
+ console.error("Recovery failed", e.t1);
2346
+ case 45:
2347
+ return (
2348
+ (e.prev = 45), (this.isRecovering = !1), e.finish(45)
2349
+ );
2350
+ case 48:
2351
+ case "end":
2352
+ return e.stop();
2353
+ }
2354
+ },
2355
+ e,
2356
+ this,
2357
+ [[3, 42, 45, 48]],
2358
+ );
2359
+ }),
2360
+ )),
2361
+ function () {
2362
+ return P.apply(this, arguments);
2363
+ }),
2364
+ },
2365
+ {
2366
+ key: "IntentStartStream",
2367
+ value: function () {
2368
+ this.executor.Send("INTENT_START_STREAM");
2369
+ },
2370
+ },
2371
+ {
2372
+ key: "cleanup",
2373
+ value: function () {
2374
+ var e;
2375
+ null === (e = this.audioStream) ||
2376
+ void 0 === e ||
2377
+ null === (e = e.getTracks()) ||
2378
+ void 0 === e ||
2379
+ e.forEach(function (e) {
2380
+ try {
2381
+ e.stop();
2382
+ } catch (e) {}
2383
+ }),
2384
+ this.source.disconnect(),
2385
+ this.processorNode.disconnect(),
2386
+ this.processorNode.port.close(),
2387
+ this.audioContext.close(),
2388
+ (this.audioData = []);
2389
+ },
2390
+ },
2391
+ {
2392
+ key: "saveAudio",
2393
+ value: function () {
2394
+ var e = this.encodeWAV(),
2395
+ t = URL.createObjectURL(new Blob([e], { type: "audio/wav" }));
2396
+ this.log("Download Recording: ".concat(t));
2397
+ },
2398
+ },
2399
+ {
2400
+ key: "getBlob",
2401
+ value: function () {
2402
+ var e = this.encodeWAV();
2403
+ return new Blob([e], { type: "audio/wav" });
2404
+ },
2405
+ },
2406
+ {
2407
+ key: "encodeWAV",
2408
+ value: function () {
2409
+ var e = new DataView(new ArrayBuffer(2 * this.audioData.length));
2410
+ this.audioData.forEach(function (t, n) {
2411
+ e.setInt16(2 * n, t, !0);
2412
+ });
2413
+ var t = e.buffer.byteLength,
2414
+ n = 44 + t,
2415
+ i = new DataView(new ArrayBuffer(n));
2416
+ i.setUint32(0, 1380533830, !1),
2417
+ i.setUint32(4, n - 8, !0),
2418
+ i.setUint32(8, 1463899717, !1),
2419
+ i.setUint32(12, 1718449184, !1),
2420
+ i.setUint32(16, 16, !0),
2421
+ i.setUint16(20, 1, !0),
2422
+ i.setUint16(22, 1, !0),
2423
+ i.setUint32(24, 16e3, !0),
2424
+ i.setUint32(28, 32e3, !0),
2425
+ i.setUint16(32, 2, !0),
2426
+ i.setUint16(34, 16, !0),
2427
+ i.setUint32(36, 1684108385, !1),
2428
+ i.setUint32(40, t, !0);
2429
+ for (var r = 0; r < t; r++) i.setInt8(44 + r, e.getInt8(r));
2430
+ return i;
2431
+ },
2432
+ },
2433
+ {
2434
+ key: "log",
2435
+ value: function (e) {
2436
+ if (this.enableLogs) {
2437
+ var t = ""
2438
+ .concat(new Date().toLocaleTimeString(), " Augnito: ")
2439
+ .concat(e);
2440
+ console.log(t + "\n");
2441
+ }
2442
+ },
2443
+ },
2444
+ ],
2445
+ );
2446
+ function K(e) {
2447
+ return j.apply(this, arguments);
2448
+ }
2449
+ function j() {
2450
+ return (
2451
+ (j = g(
2452
+ h().mark(function e(t) {
2453
+ var n,
2454
+ i,
2455
+ r,
2456
+ o,
2457
+ s,
2458
+ a,
2459
+ c,
2460
+ u,
2461
+ l,
2462
+ d = arguments;
2463
+ return h().wrap(
2464
+ function (e) {
2465
+ for (;;)
2466
+ switch ((e.prev = e.next)) {
2467
+ case 0:
2468
+ return (
2469
+ (n = d.length > 1 && void 0 !== d[1] ? d[1] : 350),
2470
+ (i = d.length > 2 && void 0 !== d[2] ? d[2] : 0.01),
2471
+ (r = null),
2472
+ (o = null),
2473
+ (e.prev = 4),
2474
+ (e.next = 7),
2475
+ navigator.mediaDevices.getUserMedia({
2476
+ audio: { deviceId: { exact: t }, channelCount: 1 },
2477
+ })
2478
+ );
2479
+ case 7:
2480
+ return (
2481
+ (r = e.sent),
2482
+ (o = new AudioContext()),
2483
+ (s = o.createMediaStreamSource(r)),
2484
+ ((a = o.createAnalyser()).fftSize = 256),
2485
+ s.connect(a),
2486
+ (c = a.frequencyBinCount),
2487
+ (u = new Float32Array(c)),
2488
+ (e.next = 17),
2489
+ new Promise(function (e) {
2490
+ var t = 0,
2491
+ r = performance.now();
2492
+ requestAnimationFrame(function o() {
2493
+ a.getFloatTimeDomainData(u);
2494
+ for (var s = 0, l = 0; l < c; l++) s += u[l] * u[l];
2495
+ var d = Math.sqrt(s / c);
2496
+ d > t && (t = d),
2497
+ performance.now() - r < n
2498
+ ? requestAnimationFrame(o)
2499
+ : e(t > i);
2500
+ });
2501
+ })
2502
+ );
2503
+ case 17:
2504
+ return e.abrupt("return", e.sent);
2505
+ case 20:
2506
+ return (
2507
+ (e.prev = 20), (e.t0 = e.catch(4)), e.abrupt("return", !1)
2508
+ );
2509
+ case 23:
2510
+ return (
2511
+ (e.prev = 23),
2512
+ null === (l = r) ||
2513
+ void 0 === l ||
2514
+ l.getTracks().forEach(function (e) {
2515
+ return e.stop();
2516
+ }),
2517
+ o &&
2518
+ "closed" !== o.state &&
2519
+ o.close().catch(function () {}),
2520
+ e.finish(23)
2521
+ );
2522
+ case 27:
2523
+ case "end":
2524
+ return e.stop();
2525
+ }
2526
+ },
2527
+ e,
2528
+ null,
2529
+ [[4, 20, 23, 27]],
2530
+ );
2531
+ }),
2532
+ )),
2533
+ j.apply(this, arguments)
2534
+ );
2535
+ }
2536
+ function W(e) {
2537
+ return G.apply(this, arguments);
2538
+ }
2539
+ function G() {
2540
+ return (G = g(
2541
+ h().mark(function e(t) {
2542
+ var n, i, r, o, s;
2543
+ return h().wrap(
2544
+ function (e) {
2545
+ for (;;)
2546
+ switch ((e.prev = e.next)) {
2547
+ case 0:
2548
+ return (
2549
+ (e.prev = 1),
2550
+ (e.next = 4),
2551
+ navigator.mediaDevices.enumerateDevices()
2552
+ );
2553
+ case 4:
2554
+ (n = e.sent), (e.next = 10);
2555
+ break;
2556
+ case 7:
2557
+ return (
2558
+ (e.prev = 7), (e.t0 = e.catch(1)), e.abrupt("return", null)
2559
+ );
2560
+ case 10:
2561
+ (i = n.filter(function (e) {
2562
+ return "audioinput" === e.kind && e.deviceId !== t;
2563
+ })),
2564
+ (r = S(i)),
2565
+ (e.prev = 12),
2566
+ r.s();
2567
+ case 14:
2568
+ if ((o = r.n()).done) {
2569
+ e.next = 23;
2570
+ break;
2571
+ }
2572
+ return (s = o.value), (e.next = 18), K(s.deviceId);
2573
+ case 18:
2574
+ if (!e.sent) {
2575
+ e.next = 21;
2576
+ break;
2577
+ }
2578
+ return e.abrupt("return", s.deviceId);
2579
+ case 21:
2580
+ e.next = 14;
2581
+ break;
2582
+ case 23:
2583
+ e.next = 28;
2584
+ break;
2585
+ case 25:
2586
+ (e.prev = 25), (e.t1 = e.catch(12)), r.e(e.t1);
2587
+ case 28:
2588
+ return (e.prev = 28), r.f(), e.finish(28);
2589
+ case 31:
2590
+ return e.abrupt("return", null);
2591
+ case 32:
2592
+ case "end":
2593
+ return e.stop();
2594
+ }
2595
+ },
2596
+ e,
2597
+ null,
2598
+ [
2599
+ [1, 7],
2600
+ [12, 25, 28, 31],
2601
+ ],
2602
+ );
2603
+ }),
2604
+ )).apply(this, arguments);
2605
+ }
2606
+ var F = (function () {
2607
+ function e() {
2608
+ var t,
2609
+ n,
2610
+ i,
2611
+ r,
2612
+ o =
2613
+ arguments.length > 0 && void 0 !== arguments[0]
2614
+ ? arguments[0]
2615
+ : {
2616
+ serverURL: "",
2617
+ enableLogs: !1,
2618
+ isDebug: !1,
2619
+ bufferInterval: 1,
2620
+ pausedBufferInterval: 1,
2621
+ EOS_Message: void 0,
2622
+ socketTimeoutInterval: void 0,
2623
+ shouldSendAudioDataSequence: !1,
2624
+ reconnectAudioDuration: 0,
2625
+ shouldPreIntialiseRecorder: !1,
2626
+ shouldReadIntensity: !1,
2627
+ debounceDelay: 300,
2628
+ switchToRegularSpeechProfile: !1,
2629
+ echoCancellation: void 0,
2630
+ noiseSuppression: void 0,
2631
+ autoGainControl: void 0,
2632
+ },
2633
+ s = arguments.length > 1 ? arguments[1] : void 0;
2634
+ if ((v(this, e), e.instance)) return e.instance;
2635
+ (this.WebsocketURL = null !== (t = o.serverURL) && void 0 !== t ? t : ""),
2636
+ (this.enableLogs = o.enableLogs),
2637
+ (this.isDebug = o.isDebug),
2638
+ (this.streamer = null),
2639
+ (this.streamerNotStarted = !1),
2640
+ (this.isStreamerStarting = !1),
2641
+ (this.pendingStartStream = !1),
2642
+ (this.heavyOp = s),
2643
+ (this.bufferInterval = o.bufferInterval),
2644
+ (this.pausedBufferInterval = o.pausedBufferInterval),
2645
+ (this.eosMessage = o.EOS_Message),
2646
+ (this.socketTimeoutInterval = o.socketTimeoutInterval),
2647
+ (this.shouldSendAudioDataSequence = o.shouldSendAudioDataSequence),
2648
+ (this.reconnectAudioDuration =
2649
+ null !== (n = o.reconnectAudioDuration) && void 0 !== n ? n : 0),
2650
+ (this.shouldPreIntialiseRecorder = o.shouldPreIntialiseRecorder),
2651
+ (this.switchToRegularSpeechProfile =
2652
+ null !== (i = o.switchToRegularSpeechProfile) && void 0 !== i && i),
2653
+ (this._echoCancellation = o.echoCancellation),
2654
+ (this._noiseSuppression = o.noiseSuppression),
2655
+ (this._autoGainControl = o.autoGainControl),
2656
+ this.shouldPreIntialiseRecorder &&
2657
+ (this.initialiseStreamer(), (this.streamerNotStarted = !0)),
2658
+ (this.shouldReadIntensity = o.shouldReadIntensity),
2659
+ (this.delay = null !== (r = o.debounceDelay) && void 0 !== r ? r : 300),
2660
+ (this.toggleStartStopAudioStream = B(
2661
+ this.toggleStartStopAudioStream.bind(this),
2662
+ this.delay,
2663
+ )),
2664
+ (this.togglePauseResumeAudioStream = B(
2665
+ this.togglePauseResumeAudioStream.bind(this),
2666
+ this.delay,
2667
+ )),
2668
+ (this.needsDispose = !1),
2669
+ (e.instance = this);
2670
+ }
2671
+ return m(e, [
2672
+ {
2673
+ key: "echoCancellation",
2674
+ get: function () {
2675
+ return this._echoCancellation;
2676
+ },
2677
+ set: function (e) {
2678
+ (this._echoCancellation = e),
2679
+ this.streamer && (this.streamer.echoCancellation = e);
2680
+ },
2681
+ },
2682
+ {
2683
+ key: "noiseSuppression",
2684
+ get: function () {
2685
+ return this._noiseSuppression;
2686
+ },
2687
+ set: function (e) {
2688
+ (this._noiseSuppression = e),
2689
+ this.streamer && (this.streamer.noiseSuppression = e);
2690
+ },
2691
+ },
2692
+ {
2693
+ key: "autoGainControl",
2694
+ get: function () {
2695
+ return this._autoGainControl;
2696
+ },
2697
+ set: function (e) {
2698
+ (this._autoGainControl = e),
2699
+ this.streamer && (this.streamer.autoGainControl = e);
2700
+ },
2701
+ },
2702
+ {
2703
+ key: "initialiseStreamer",
2704
+ value: function () {
2705
+ this.streamer = new J(
2706
+ this.WebsocketURL,
2707
+ this.enableLogs,
2708
+ this.isDebug,
2709
+ this.bufferInterval,
2710
+ this.pausedBufferInterval,
2711
+ this.eosMessage,
2712
+ this.socketTimeoutInterval,
2713
+ this.shouldSendAudioDataSequence,
2714
+ this.reconnectAudioDuration,
2715
+ this.shouldPreIntialiseRecorder,
2716
+ this.shouldReadIntensity,
2717
+ this.switchToRegularSpeechProfile,
2718
+ this._echoCancellation,
2719
+ this._noiseSuppression,
2720
+ this._autoGainControl,
2721
+ this.heavyOp,
2722
+ this.onFinalResultCallback.bind(this),
2723
+ this.onPartialResultCallback.bind(this),
2724
+ this.onErrorCallback.bind(this),
2725
+ this.onStateChangedCallback.bind(this),
2726
+ this.onSessionEventCallback.bind(this),
2727
+ this.onOtherResultCallback.bind(this),
2728
+ this.onSpeechResponseCallback.bind(this),
2729
+ this.onIntensityCallback.bind(this),
2730
+ this.onJobStatusCallback.bind(this),
2731
+ this.onMicReadyCallback.bind(this),
2732
+ );
2733
+ },
2734
+ },
2735
+ {
2736
+ key: "updateIntentStartStream",
2737
+ value: function () {
2738
+ var e;
2739
+ (this.pendingStartStream = !0),
2740
+ null === (e = this.streamer) || void 0 === e || e.IntentStartStream();
2741
+ },
2742
+ },
2743
+ {
2744
+ key: "togglePauseResumeAudioStream",
2745
+ value: function () {
2746
+ var e =
2747
+ arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0,
2748
+ t =
2749
+ arguments.length > 1 && void 0 !== arguments[1]
2750
+ ? arguments[1]
2751
+ : void 0;
2752
+ !this.streamer || this.streamerNotStarted
2753
+ ? (t && (this.WebsocketURL = t), this.startAudio(e))
2754
+ : this.streamer.IsPaused
2755
+ ? this.resumeAudio()
2756
+ : this.pauseAudio();
2757
+ },
2758
+ },
2759
+ {
2760
+ key: "toggleStartStopAudioStream",
2761
+ value: function () {
2762
+ var e =
2763
+ arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0,
2764
+ t =
2765
+ arguments.length > 1 && void 0 !== arguments[1]
2766
+ ? arguments[1]
2767
+ : void 0;
2768
+ !this.streamer || this.streamerNotStarted
2769
+ ? (t && (this.WebsocketURL = t), this.startAudio(e))
2770
+ : this.stopAudio();
2771
+ },
2772
+ },
2773
+ {
2774
+ key: "startAudio",
2775
+ value:
2776
+ ((t = g(
2777
+ h().mark(function e(t) {
2778
+ return h().wrap(
2779
+ function (e) {
2780
+ for (;;)
2781
+ switch ((e.prev = e.next)) {
2782
+ case 0:
2783
+ if (!this.isStreamerStarting) {
2784
+ e.next = 2;
2785
+ break;
2786
+ }
2787
+ return e.abrupt("return");
2788
+ case 2:
2789
+ return (
2790
+ (this.isStreamerStarting = !0),
2791
+ (this.shouldPreIntialiseRecorder && this.streamer) ||
2792
+ this.initialiseStreamer(),
2793
+ (e.prev = 4),
2794
+ (e.next = 7),
2795
+ this.streamer.StartStream(t, this.WebsocketURL)
2796
+ );
2797
+ case 7:
2798
+ e.sent
2799
+ ? ((this.streamerNotStarted = !1),
2800
+ this.log("Stream Started..."))
2801
+ : (this.streamer = null);
2802
+ case 9:
2803
+ return (
2804
+ (e.prev = 9),
2805
+ (this.isStreamerStarting = !1),
2806
+ e.finish(9)
2807
+ );
2808
+ case 12:
2809
+ case "end":
2810
+ return e.stop();
2811
+ }
2812
+ },
2813
+ e,
2814
+ this,
2815
+ [[4, , 9, 12]],
2816
+ );
2817
+ }),
2818
+ )),
2819
+ function (e) {
2820
+ return t.apply(this, arguments);
2821
+ }),
2822
+ },
2823
+ {
2824
+ key: "pauseAudio",
2825
+ value: function () {
2826
+ this.streamer.PauseStream(), this.log("Stream Paused...");
2827
+ },
2828
+ },
2829
+ {
2830
+ key: "resumeAudio",
2831
+ value: function () {
2832
+ this.streamer.ResumeStream(),
2833
+ this.enableLogs && this.log("Stream Resumed...");
2834
+ },
2835
+ },
2836
+ {
2837
+ key: "stopAudio",
2838
+ value: function () {
2839
+ var e,
2840
+ t,
2841
+ n = this,
2842
+ i =
2843
+ !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0],
2844
+ r = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
2845
+ ((null !== (e = this.streamer) && void 0 !== e && e.IsStreaming) ||
2846
+ r) &&
2847
+ (null === (t = this.streamer) || void 0 === t || t.StopStream(i),
2848
+ (this.streamer = null),
2849
+ this.log("Stream Stopped..."),
2850
+ this.shouldPreIntialiseRecorder &&
2851
+ setTimeout(function () {
2852
+ n.needsDispose
2853
+ ? (n.needsDispose = !1)
2854
+ : (n.initialiseStreamer(), (n.streamerNotStarted = !0));
2855
+ }, 500));
2856
+ },
2857
+ },
2858
+ {
2859
+ key: "getBlob",
2860
+ value: function () {
2861
+ var e = this.streamer.getBlob();
2862
+ return this.log("Blob Sent..."), e;
2863
+ },
2864
+ },
2865
+ {
2866
+ key: "log",
2867
+ value: function (e) {
2868
+ if (this.enableLogs) {
2869
+ var t = ""
2870
+ .concat(new Date().toLocaleTimeString(), " Augnito: ")
2871
+ .concat(e);
2872
+ this.showLogCallback(t + "\n");
2873
+ }
2874
+ },
2875
+ },
2876
+ {
2877
+ key: "dispose",
2878
+ value: function () {
2879
+ var t;
2880
+ (this.needsDispose = !0),
2881
+ null === (t = this.streamer) || void 0 === t || t.StopStream(!1),
2882
+ (this.streamer = null),
2883
+ (e.instance = null);
2884
+ },
2885
+ },
2886
+ {
2887
+ key: "onSessionEventCallback",
2888
+ value: function (e) {
2889
+ this.onSessionEvent && this.onSessionEvent(e);
2890
+ },
2891
+ },
2892
+ {
2893
+ key: "onStateChangedCallback",
2894
+ value: function (e) {
2895
+ this.onStateChanged && this.onStateChanged(e);
2896
+ },
2897
+ },
2898
+ {
2899
+ key: "onIntensityCallback",
2900
+ value: function (e) {
2901
+ this.onIntensity && this.onIntensity(e);
2902
+ },
2903
+ },
2904
+ {
2905
+ key: "onErrorCallback",
2906
+ value: function (e) {
2907
+ this.onError && this.onError(e);
2908
+ },
2909
+ },
2910
+ {
2911
+ key: "onPartialResultCallback",
2912
+ value: function (e) {
2913
+ this.onPartialResult && this.onPartialResult(e);
2914
+ },
2915
+ },
2916
+ {
2917
+ key: "onFinalResultCallback",
2918
+ value: function (e) {
2919
+ this.onFinalResult && this.onFinalResult(e);
2920
+ },
2921
+ },
2922
+ {
2923
+ key: "onOtherResultCallback",
2924
+ value: function (e) {
2925
+ this.onOtherResults && this.onOtherResults(e);
2926
+ },
2927
+ },
2928
+ {
2929
+ key: "onSpeechResponseCallback",
2930
+ value: function (e) {
2931
+ this.onSpeechResponse && this.onSpeechResponse(e);
2932
+ },
2933
+ },
2934
+ {
2935
+ key: "onJobStatusCallback",
2936
+ value: function (e) {
2937
+ this.onJobStatus && this.onJobStatus(e);
2938
+ },
2939
+ },
2940
+ {
2941
+ key: "onMicReadyCallback",
2942
+ value: function () {
2943
+ this.onMicReady && this.onMicReady();
2944
+ },
2945
+ },
2946
+ {
2947
+ key: "showLogCallback",
2948
+ value: function (e) {
2949
+ this.showLog && this.showLog(e);
2950
+ },
2951
+ },
2952
+ ]);
2953
+ var t;
2954
+ })();
2955
+ function B(e, t) {
2956
+ var n;
2957
+ return function () {
2958
+ for (
2959
+ var i = this, r = arguments.length, o = new Array(r), s = 0;
2960
+ s < r;
2961
+ s++
2962
+ )
2963
+ o[s] = arguments[s];
2964
+ n && clearTimeout(n),
2965
+ (n = setTimeout(function () {
2966
+ return e.apply(i, o);
2967
+ }, t));
2968
+ };
2969
+ }
2970
+ class V extends u {
2971
+ constructor(e) {
2972
+ super(),
2973
+ Object.defineProperty(this, "_config", {
2974
+ enumerable: !0,
2975
+ configurable: !0,
2976
+ writable: !0,
2977
+ value: e,
2978
+ }),
2979
+ Object.defineProperty(this, "_baseUrl", {
2980
+ enumerable: !0,
2981
+ configurable: !0,
2982
+ writable: !0,
2983
+ value: void 0,
2984
+ }),
2985
+ (this._baseUrl = `https://${e.server}/pace/v1/sdk`);
2986
+ }
2987
+ getURL(e) {
2988
+ return `${this._baseUrl}${e}`;
2989
+ }
2990
+ getNoteParams() {
2991
+ return e(this, void 0, void 0, function* () {
2992
+ const e = this.getURL("/noteparams"),
2993
+ t = {
2994
+ SubscriptionCode: this._config.subscriptionCode,
2995
+ AccessKey: this._config.accessKey,
2996
+ UserTag: this._config.userTag,
2997
+ };
2998
+ return yield this.makePostRequest(e, t);
2999
+ });
3000
+ }
3001
+ getSettingsConfigMaster(t) {
3002
+ return e(this, void 0, void 0, function* () {
3003
+ const e = this.getURL("/configmaster"),
3004
+ n = {
3005
+ SubscriptionCode: this._config.subscriptionCode,
3006
+ AccessKey: this._config.accessKey,
3007
+ UserTag: this._config.userTag,
3008
+ ConfigTypeId: t,
3009
+ };
3010
+ return yield this.makePostRequest(e, n);
3011
+ });
3012
+ }
3013
+ getOrgConfigMapping(t) {
3014
+ return e(this, void 0, void 0, function* () {
3015
+ const e = this.getURL("/configmapping").replace("/v1", "/v2"),
3016
+ n = {
3017
+ SubscriptionCode: this._config.subscriptionCode,
3018
+ AccessKey: this._config.accessKey,
3019
+ UserTag: this._config.userTag,
3020
+ ConfigTypeId: t,
3021
+ };
3022
+ return yield this.makePostRequest(e, n);
3023
+ });
3024
+ }
3025
+ getUserConfigSettings(t) {
3026
+ return e(this, void 0, void 0, function* () {
3027
+ const e = this.getURL("/userconfigmapping"),
3028
+ n = {
3029
+ SubscriptionCode: this._config.subscriptionCode,
3030
+ AccessKey: this._config.accessKey,
3031
+ UserTag: this._config.userTag,
3032
+ ConfigTypeId: t,
3033
+ };
3034
+ return yield this.makePostRequest(e, n);
3035
+ });
3036
+ }
3037
+ updateUserConfig(t) {
3038
+ return e(this, void 0, void 0, function* () {
3039
+ const e = this.getURL("/userconfigmapping"),
3040
+ n = {
3041
+ SubscriptionCode: this._config.subscriptionCode,
3042
+ AccessKey: this._config.accessKey,
3043
+ UserTag: this._config.userTag,
3044
+ UserConfigMapping: t,
3045
+ };
3046
+ return yield this.makePatchRequest(e, n);
3047
+ });
3048
+ }
3049
+ getUserPreferences() {
3050
+ return e(this, void 0, void 0, function* () {
3051
+ const e = this.getURL("/getuserpreferences"),
3052
+ t = {
3053
+ SubscriptionCode: this._config.subscriptionCode,
3054
+ AccessKey: this._config.accessKey,
3055
+ UserTag: this._config.userTag,
3056
+ };
3057
+ return yield this.makePostRequest(e, t);
3058
+ });
3059
+ }
3060
+ updateUserPreference(t, n, i, r, o, s) {
3061
+ return e(this, void 0, void 0, function* () {
3062
+ const e = this.getURL("/postuserpreferences"),
3063
+ a = {
3064
+ SubscriptionCode: this._config.subscriptionCode,
3065
+ AccessKey: this._config.accessKey,
3066
+ UserTag: this._config.userTag,
3067
+ UserPreferences: {
3068
+ AutomaticallyGenerateTranscript: t,
3069
+ PreferredTranscriptionLanguage: n,
3070
+ HighlightMedicalTerms: i,
3071
+ DisplayPatientContext: r,
3072
+ NoteOutputStyle: o,
3073
+ NoteOutputVerbosity: s,
3074
+ },
3075
+ };
3076
+ return yield this.makePostRequest(e, a);
3077
+ });
3078
+ }
3079
+ }
3080
+ const H = "Invalid user details, please check again",
3081
+ q = "Subscription is not valid.",
3082
+ z =
3083
+ "invalid request. Please make sure AccessKey, SubscriptionCode and UserTag is sent along with the request",
3084
+ $ = "Active seat is not available for user",
3085
+ Y = "Unable to fetch account details, please try again.",
3086
+ Q = "Unable to fetch job details, please try again.",
3087
+ X = "Job not reconnectable",
3088
+ Z = "Timeout exceeded",
3089
+ ee = "Rate Limit Exceeded, Please try again in sometime!",
3090
+ te = "Audio Signal is power very LOW, Mic might be muted",
3091
+ ne = "Job Id is empty",
3092
+ ie = "Page Size is undefined",
3093
+ re = "Note Data is empty",
3094
+ oe = "Job Name is empty",
3095
+ se = "Patient Context is empty",
3096
+ ae = "Mic permission denied",
3097
+ ce = "Microphone is muted",
3098
+ ue = "Audio track ended. Possibly the mic was unplugged",
3099
+ le = "Internet is not available. Try again later.",
3100
+ de =
3101
+ "Feedback is not enabled. Please contact administrator for more details.",
3102
+ he = "Automatic Transcription is not enabled for the organisation",
3103
+ fe = "Resume job is not enabled for the organisation";
3104
+ class pe {
3105
+ static isBrowserOnline() {
3106
+ return "undefined" != typeof navigator && !0 === navigator.onLine;
3107
+ }
3108
+ static isValidHttpUrl(e) {
3109
+ if ("string" != typeof e || e.length > 2048) return !1;
3110
+ try {
3111
+ const t = new URL(e);
3112
+ return (
3113
+ ("http:" === t.protocol || "https:" === t.protocol) &&
3114
+ !t.username &&
3115
+ !t.password
3116
+ );
3117
+ } catch (e) {
3118
+ return !1;
3119
+ }
3120
+ }
3121
+ static hasInternetConnection() {
3122
+ return e(
3123
+ this,
3124
+ arguments,
3125
+ void 0,
3126
+ function* (e = { url: null, timeoutMs: null }) {
3127
+ var t = e.url || pe.DEFAULT_URL;
3128
+ const n = e.timeoutMs || pe.DEFAULT_TIMEOUT;
3129
+ if (!pe.isBrowserOnline()) return !1;
3130
+ pe.isValidHttpUrl(t) || (t = pe.DEFAULT_URL);
3131
+ const i = new AbortController(),
3132
+ r = setTimeout(() => i.abort(), n);
3133
+ try {
3134
+ return (
3135
+ yield fetch(t, {
3136
+ method: "HEAD",
3137
+ mode: "no-cors",
3138
+ cache: "no-cache",
3139
+ signal: i.signal,
3140
+ }),
3141
+ !0
3142
+ );
3143
+ } catch (e) {
3144
+ return !1;
3145
+ } finally {
3146
+ clearTimeout(r);
3147
+ }
3148
+ },
3149
+ );
3150
+ }
3151
+ static isOnline(t) {
3152
+ return e(this, void 0, void 0, function* () {
3153
+ return pe.hasInternetConnection(t);
3154
+ });
3155
+ }
3156
+ }
3157
+ Object.defineProperty(pe, "DEFAULT_URL", {
3158
+ enumerable: !0,
3159
+ configurable: !0,
3160
+ writable: !0,
3161
+ value: "https://www.google.com/favicon.ico",
3162
+ }),
3163
+ Object.defineProperty(pe, "DEFAULT_TIMEOUT", {
3164
+ enumerable: !0,
3165
+ configurable: !0,
3166
+ writable: !0,
3167
+ value: 5e3,
3168
+ });
3169
+ class ge {
3170
+ constructor(e) {
3171
+ Object.defineProperty(this, "_logTag", {
3172
+ enumerable: !0,
3173
+ configurable: !0,
3174
+ writable: !0,
3175
+ value: "Augnito-Ambient",
3176
+ }),
3177
+ Object.defineProperty(this, "_ambientRestAPI", {
3178
+ enumerable: !0,
3179
+ configurable: !0,
3180
+ writable: !0,
3181
+ value: void 0,
3182
+ }),
3183
+ Object.defineProperty(this, "_ambientPaceAPI", {
3184
+ enumerable: !0,
3185
+ configurable: !0,
3186
+ writable: !0,
3187
+ value: void 0,
3188
+ }),
3189
+ Object.defineProperty(this, "config", {
3190
+ enumerable: !0,
3191
+ configurable: !0,
3192
+ writable: !0,
3193
+ value: void 0,
3194
+ }),
3195
+ Object.defineProperty(this, "enableLog", {
3196
+ enumerable: !0,
3197
+ configurable: !0,
3198
+ writable: !0,
3199
+ value: void 0,
3200
+ }),
3201
+ Object.defineProperty(this, "shouldReadAudioIntensity", {
3202
+ enumerable: !0,
3203
+ configurable: !0,
3204
+ writable: !0,
3205
+ value: void 0,
3206
+ }),
3207
+ Object.defineProperty(this, "recorderIns", {
3208
+ enumerable: !0,
3209
+ configurable: !0,
3210
+ writable: !0,
3211
+ value: void 0,
3212
+ }),
3213
+ Object.defineProperty(this, "forceStopAudio", {
3214
+ enumerable: !0,
3215
+ configurable: !0,
3216
+ writable: !0,
3217
+ value: !1,
3218
+ }),
3219
+ Object.defineProperty(this, "_isRecording", {
3220
+ enumerable: !0,
3221
+ configurable: !0,
3222
+ writable: !0,
3223
+ value: !1,
3224
+ }),
3225
+ Object.defineProperty(this, "echoCancellation", {
3226
+ enumerable: !0,
3227
+ configurable: !0,
3228
+ writable: !0,
3229
+ value: void 0,
3230
+ }),
3231
+ Object.defineProperty(this, "noiseSuppression", {
3232
+ enumerable: !0,
3233
+ configurable: !0,
3234
+ writable: !0,
3235
+ value: void 0,
3236
+ }),
3237
+ Object.defineProperty(this, "autoGainControl", {
3238
+ enumerable: !0,
3239
+ configurable: !0,
3240
+ writable: !0,
3241
+ value: void 0,
3242
+ }),
3243
+ Object.defineProperty(this, "onJobCreated", {
3244
+ enumerable: !0,
3245
+ configurable: !0,
3246
+ writable: !0,
3247
+ value: void 0,
3248
+ }),
3249
+ Object.defineProperty(this, "onStateChanged", {
3250
+ enumerable: !0,
3251
+ configurable: !0,
3252
+ writable: !0,
3253
+ value: void 0,
3254
+ }),
3255
+ Object.defineProperty(this, "onError", {
3256
+ enumerable: !0,
3257
+ configurable: !0,
3258
+ writable: !0,
3259
+ value: void 0,
3260
+ }),
3261
+ Object.defineProperty(this, "onOtherResult", {
3262
+ enumerable: !0,
3263
+ configurable: !0,
3264
+ writable: !0,
3265
+ value: void 0,
3266
+ }),
3267
+ Object.defineProperty(this, "onIntensityValue", {
3268
+ enumerable: !0,
3269
+ configurable: !0,
3270
+ writable: !0,
3271
+ value: void 0,
3272
+ }),
3273
+ Object.defineProperty(this, "onIdleMic", {
3274
+ enumerable: !0,
3275
+ configurable: !0,
3276
+ writable: !0,
3277
+ value: void 0,
3278
+ }),
3279
+ Object.defineProperty(this, "onSoapNoteGenerated", {
3280
+ enumerable: !0,
3281
+ configurable: !0,
3282
+ writable: !0,
3283
+ value: void 0,
3284
+ }),
3285
+ Object.defineProperty(this, "onTranscriptGenerated", {
3286
+ enumerable: !0,
3287
+ configurable: !0,
3288
+ writable: !0,
3289
+ value: void 0,
3290
+ }),
3291
+ Object.defineProperty(this, "onCodesGenerated", {
3292
+ enumerable: !0,
3293
+ configurable: !0,
3294
+ writable: !0,
3295
+ value: void 0,
3296
+ }),
3297
+ Object.defineProperty(this, "onJobStatus", {
3298
+ enumerable: !0,
3299
+ configurable: !0,
3300
+ writable: !0,
3301
+ value: void 0,
3302
+ }),
3303
+ Object.defineProperty(this, "onMicRecoveredAfterUnplugged", {
3304
+ enumerable: !0,
3305
+ configurable: !0,
3306
+ writable: !0,
3307
+ value: void 0,
3308
+ }),
3309
+ (this._ambientRestAPI = new l(this.validateConfig(e))),
3310
+ (this._ambientPaceAPI = new V(e)),
3311
+ (this.config = this.createSocketConfig(e)),
3312
+ (this.enableLog = e.enableLogs),
3313
+ (this.shouldReadAudioIntensity = e.shouldReadAudioIntensity),
3314
+ (this.echoCancellation = e.echoCancellation),
3315
+ (this.noiseSuppression = e.noiseSuppression),
3316
+ (this.autoGainControl = e.autoGainControl);
3317
+ }
3318
+ initRecorder(e) {
3319
+ var t, n, i, r, o;
3320
+ (this.recorderIns = new F({
3321
+ serverURL: e,
3322
+ enableLogs: null !== (t = this.enableLog) && void 0 !== t && t,
3323
+ isDebug: null !== (n = this.enableLog) && void 0 !== n && n,
3324
+ bufferInterval: 15,
3325
+ EOS_Message: '{"JobAction": "EOS","Status": 0,"Type": "meta"}',
3326
+ socketTimeoutInterval: 2e4,
3327
+ shouldSendAudioDataSequence: !0,
3328
+ shouldReadIntensity: this.shouldReadAudioIntensity,
3329
+ echoCancellation: this.echoCancellation,
3330
+ noiseSuppression: this.noiseSuppression,
3331
+ autoGainControl: this.autoGainControl,
3332
+ })),
3333
+ (this.recorderIns.echoCancellation =
3334
+ null !== (i = this.echoCancellation) && void 0 !== i && i),
3335
+ (this.recorderIns.noiseSuppression =
3336
+ null !== (r = this.noiseSuppression) && void 0 !== r && r),
3337
+ (this.recorderIns.autoGainControl =
3338
+ null !== (o = this.autoGainControl) && void 0 !== o && o),
3339
+ (this.recorderIns.onError = this.onErrorCallback.bind(this)),
3340
+ (this.recorderIns.onStateChanged = this.onStateChangeCallback.bind(this)),
3341
+ (this.recorderIns.onSessionEvent =
3342
+ this.onSessionEventCallback.bind(this)),
3343
+ (this.recorderIns.onOtherResults =
3344
+ this.onOtherResultsCallback.bind(this)),
3345
+ (this.recorderIns.onIntensity = this.onIntensityCallback.bind(this)),
3346
+ (this.recorderIns.onSpeechResponse =
3347
+ this.onSpeechResponseCallback.bind(this)),
3348
+ (this.recorderIns.onJobStatus = this.onJobStatusEventCallback.bind(this)),
3349
+ (this.recorderIns.onMicReady =
3350
+ this.onMicRecoveredAfterUnpluggedCallback.bind(this));
3351
+ }
3352
+ getNoteParams() {
3353
+ return e(this, void 0, void 0, function* () {
3354
+ try {
3355
+ if (!this._ambientRestAPI)
3356
+ return void d.error("SDK not initialized", this._logTag);
3357
+ var e = yield this._ambientPaceAPI.getNoteParams();
3358
+ if (e) {
3359
+ if (200 === e.Status) return e;
3360
+ this.onErrorCallback(e.ServerMessage);
3361
+ } else this.onErrorCallback("Unknown Error!");
3362
+ } catch (e) {
3363
+ this.handleException(e);
3364
+ }
3365
+ });
3366
+ }
3367
+ getAllNotes(t, n, i) {
3368
+ return e(this, void 0, void 0, function* () {
3369
+ try {
3370
+ if (!this._ambientRestAPI)
3371
+ return void d.error("SDK not initialized", this._logTag);
3372
+ var e = yield this._ambientRestAPI.ListJobs(t, n, null == i || i);
3373
+ if (e) {
3374
+ if (200 === e.Status) return e;
3375
+ this.onErrorCallback(e.ServerMessage);
3376
+ } else this.onErrorCallback("Unknown Error!");
3377
+ } catch (e) {
3378
+ this.handleException(e);
3379
+ }
3380
+ });
3381
+ }
3382
+ getSummarizedNote(t) {
3383
+ return e(this, void 0, void 0, function* () {
3384
+ try {
3385
+ if (!this._ambientRestAPI)
3386
+ return void d.error("SDK not initialized", this._logTag);
3387
+ var e = yield this._ambientRestAPI.FetchJob(t);
3388
+ if (e) {
3389
+ if (200 === e.Status) return e;
3390
+ this.onErrorCallback(e.ServerMessage);
3391
+ } else this.onErrorCallback("Unknown Error!");
3392
+ } catch (e) {
3393
+ this.handleException(e);
3394
+ }
3395
+ });
3396
+ }
3397
+ sendSummarizedNote(t, n) {
3398
+ return e(this, void 0, void 0, function* () {
3399
+ try {
3400
+ return this._ambientRestAPI
3401
+ ? yield this._ambientRestAPI.SendFinalNote(t, n)
3402
+ : void d.error("SDK not initialized", this._logTag);
3403
+ } catch (e) {
3404
+ this.handleException(e);
3405
+ }
3406
+ });
3407
+ }
3408
+ toggleListening(t, n, r, o, s, a, c) {
3409
+ return e(this, void 0, void 0, function* () {
3410
+ var e, u;
3411
+ if (void 0 !== a && "" !== a.trim()) {
3412
+ var l = yield this._ambientPaceAPI.getOrgConfigMapping(i.CDIVersion);
3413
+ if (
3414
+ (null == l ? void 0 : l.Items) &&
3415
+ l.Items.length > 0 &&
3416
+ l.Items[0].Settings
3417
+ )
3418
+ if (!l.Items[0].Settings.find((e) => 300 === e.ID))
3419
+ return void this.onErrorCallback(fe);
3420
+ }
3421
+ var d =
3422
+ (null === (e = this.config) || void 0 === e
3423
+ ? void 0
3424
+ : e.prepareWSSURL(t, n, r, o, a, c)) || "";
3425
+ this.recorderIns || this.initRecorder(d),
3426
+ null === (u = this.recorderIns) ||
3427
+ void 0 === u ||
3428
+ u.toggleStartStopAudioStream(s, d);
3429
+ });
3430
+ }
3431
+ togglePauseResumeListening(t, n, r, o, s, a, c) {
3432
+ return e(this, void 0, void 0, function* () {
3433
+ var e, u;
3434
+ if (void 0 !== a && "" !== a.trim()) {
3435
+ var l = yield this._ambientPaceAPI.getOrgConfigMapping(i.CDIVersion);
3436
+ if (
3437
+ (null == l ? void 0 : l.Items) &&
3438
+ l.Items.length > 0 &&
3439
+ l.Items[0].Settings
3440
+ )
3441
+ if (!l.Items[0].Settings.find((e) => 300 === e.ID))
3442
+ return void this.onErrorCallback(fe);
3443
+ }
3444
+ var d =
3445
+ (null === (e = this.config) || void 0 === e
3446
+ ? void 0
3447
+ : e.prepareWSSURL(t, n, r, o, a, c)) || "";
3448
+ this.recorderIns || this.initRecorder(d),
3449
+ null === (u = this.recorderIns) ||
3450
+ void 0 === u ||
3451
+ u.togglePauseResumeAudioStream(s, d);
3452
+ });
3453
+ }
3454
+ startListening() {
3455
+ var e;
3456
+ null === (e = this.recorderIns) || void 0 === e || e.startAudio();
3457
+ }
3458
+ stopListening() {
3459
+ var e;
3460
+ null === (e = this.recorderIns) || void 0 === e || e.stopAudio(!0, !0);
3461
+ }
3462
+ deleteNotes(t, n) {
3463
+ return e(this, void 0, void 0, function* () {
3464
+ var e;
3465
+ try {
3466
+ if (!this._ambientRestAPI)
3467
+ return void d.error("SDK not initialized", this._logTag);
3468
+ var i = yield this._ambientRestAPI.DeleteNotes(t, n);
3469
+ if (i) {
3470
+ if (200 === i.Status)
3471
+ return (
3472
+ null === (e = this.recorderIns) ||
3473
+ void 0 === e ||
3474
+ e.stopAudio(!1, !0),
3475
+ i
3476
+ );
3477
+ this.onErrorCallback(i.ServerMessage);
3478
+ } else this.onErrorCallback("Unknown Error!");
3479
+ } catch (e) {
3480
+ this.handleException(e);
3481
+ }
3482
+ });
3483
+ }
3484
+ renameNoteTitle(t, n) {
3485
+ return e(this, void 0, void 0, function* () {
3486
+ try {
3487
+ if (!this._ambientRestAPI)
3488
+ return void d.error("SDK not initialized", this._logTag);
3489
+ var e = yield this._ambientRestAPI.RenameNoteTitle(t, n);
3490
+ if (e) {
3491
+ if (200 === e.Status) return e;
3492
+ this.onErrorCallback(e.ServerMessage);
3493
+ } else this.onErrorCallback("Unknown Error!");
3494
+ } catch (e) {
3495
+ this.handleException(e);
3496
+ }
3497
+ });
3498
+ }
3499
+ getNotePDF(t, n, i, r, o, s) {
3500
+ return e(this, void 0, void 0, function* () {
3501
+ try {
3502
+ if (!this._ambientRestAPI)
3503
+ return void d.error("SDK not initialized", this._logTag);
3504
+ var e = yield this._ambientRestAPI.DownloadNotePDF(t, n, i, r, o, s);
3505
+ if (e) {
3506
+ if (200 === e.Status) return e;
3507
+ this.onErrorCallback(e.ServerMessage);
3508
+ } else this.onErrorCallback("Unknown Error!");
3509
+ } catch (e) {
3510
+ this.handleException(e);
3511
+ }
3512
+ });
3513
+ }
3514
+ endPausedJob(t) {
3515
+ return e(this, void 0, void 0, function* () {
3516
+ try {
3517
+ if (!this._ambientRestAPI)
3518
+ return void d.error("SDK not initialized", this._logTag);
3519
+ var e = yield this._ambientRestAPI.EndJob(t);
3520
+ if (e) {
3521
+ if (200 === e.Status) return e;
3522
+ this.onErrorCallback(e.ServerMessage);
3523
+ } else this.onErrorCallback("Unknown Error!");
3524
+ } catch (e) {
3525
+ this.handleException(e);
3526
+ }
3527
+ });
3528
+ }
3529
+ generateCDISuggestions(t, n, r, o, s) {
3530
+ return e(this, void 0, void 0, function* () {
3531
+ try {
3532
+ if (!this._ambientRestAPI)
3533
+ return void d.error("SDK not initialized", this._logTag);
3534
+ var e = 1,
3535
+ a = yield this._ambientPaceAPI.getOrgConfigMapping(i.CDIVersion);
3536
+ if (
3537
+ (null == a ? void 0 : a.Items) &&
3538
+ a.Items.length > 0 &&
3539
+ a.Items[0].Settings
3540
+ ) {
3541
+ var c = a.Items[0].Settings.find((e) => 209 === e.ID);
3542
+ c && (e = Number.parseInt(c.ConfigValue));
3543
+ }
3544
+ var u = yield this._ambientRestAPI.GenerateSuggestions(
3545
+ t,
3546
+ n,
3547
+ r,
3548
+ s,
3549
+ o,
3550
+ e,
3551
+ );
3552
+ if (u) {
3553
+ if (200 === u.Status) return u;
3554
+ this.onErrorCallback(u.ServerMessage);
3555
+ } else this.onErrorCallback("Unknown Error!");
3556
+ } catch (e) {
3557
+ this.handleException(e);
3558
+ }
3559
+ });
3560
+ }
3561
+ updatePatientContext(t, n, i) {
3562
+ return e(this, void 0, void 0, function* () {
3563
+ try {
3564
+ if (!this._ambientRestAPI)
3565
+ return void d.error("SDK not initialized", this._logTag);
3566
+ var e = yield this._ambientRestAPI.UpdatePatientContext(t, n, i);
3567
+ if (e) {
3568
+ if (200 === e.Status) return e;
3569
+ this.onErrorCallback(e.ServerMessage);
3570
+ } else this.onErrorCallback("Unknown Error!");
3571
+ } catch (e) {
3572
+ this.handleException(e);
3573
+ }
3574
+ });
3575
+ }
3576
+ modifyGeneratedNote(t, n, i) {
3577
+ return e(this, void 0, void 0, function* () {
3578
+ try {
3579
+ if (!this._ambientRestAPI)
3580
+ return void d.error("SDK not initialized", this._logTag);
3581
+ var e = yield this._ambientRestAPI.ModifyGeneratedNote(t, n, i);
3582
+ if (e) {
3583
+ if (200 === e.Status) return e;
3584
+ this.onErrorCallback(e.ServerMessage);
3585
+ } else this.onErrorCallback("Unknown Error!");
3586
+ } catch (e) {
3587
+ this.handleException(e);
3588
+ }
3589
+ });
3590
+ }
3591
+ fetchTranscriptionForNote(t) {
3592
+ return e(this, void 0, void 0, function* () {
3593
+ try {
3594
+ if (!this._ambientRestAPI)
3595
+ return void d.error("SDK not initialized", this._logTag);
3596
+ if (
3597
+ (yield this._ambientPaceAPI.getUserPreferences()).Items[0]
3598
+ .AutomaticTranscriptionEnabledForOrg
3599
+ ) {
3600
+ var e = yield this._ambientRestAPI.FetchTranscription(t);
3601
+ if (e) {
3602
+ if (200 === e.Status) return e;
3603
+ this.onErrorCallback(e.ServerMessage);
3604
+ } else this.onErrorCallback("Unknown Error!");
3605
+ } else this.onErrorCallback(he);
3606
+ } catch (e) {
3607
+ this.handleException(e);
3608
+ }
3609
+ });
3610
+ }
3611
+ sendFeedback(t, n, i, r) {
3612
+ return e(this, void 0, void 0, function* () {
3613
+ var e, o;
3614
+ try {
3615
+ if (!this._ambientRestAPI)
3616
+ return void d.error("SDK not initialized", this._logTag);
3617
+ var s = yield this._ambientPaceAPI.getUserPreferences();
3618
+ if (
3619
+ (null === (e = s.Items[0]) || void 0 === e
3620
+ ? void 0
3621
+ : e.FeedbackEnabledForOrg) &&
3622
+ (null === (o = s.Items[0]) || void 0 === o
3623
+ ? void 0
3624
+ : o.FeedbackEnabled)
3625
+ ) {
3626
+ var a = yield this._ambientRestAPI.SendFeedback(
3627
+ t,
3628
+ n,
3629
+ null != i ? i : "",
3630
+ null != r ? r : "SOAPFeedBack",
3631
+ );
3632
+ if (a) {
3633
+ if (200 === a.Status) return a;
3634
+ this.onErrorCallback(a.ServerMessage);
3635
+ } else this.onErrorCallback("Unknown Error!");
3636
+ } else this.onErrorCallback(de);
3637
+ } catch (e) {
3638
+ this.handleException(e);
3639
+ }
3640
+ });
3641
+ }
3642
+ getUserConfiguration(t) {
3643
+ return e(this, void 0, void 0, function* () {
3644
+ try {
3645
+ if (!this._ambientPaceAPI)
3646
+ return void d.error("SDK not initialized", this._logTag);
3647
+ var e = yield this._ambientPaceAPI.getUserConfigSettings(t);
3648
+ if (e) {
3649
+ if (200 === e.Status) return e;
3650
+ this.onErrorCallback(e.ServerMessage);
3651
+ } else this.onErrorCallback("Unknown Error!");
3652
+ } catch (e) {
3653
+ this.handleException(e);
3654
+ }
3655
+ });
3656
+ }
3657
+ updateUserConfiguration(t) {
3658
+ return e(this, void 0, void 0, function* () {
3659
+ try {
3660
+ if (!this._ambientPaceAPI)
3661
+ return void d.error("SDK not initialized", this._logTag);
3662
+ var e = yield this._ambientPaceAPI.updateUserConfig(t);
3663
+ if (e) {
3664
+ if (200 === e.Status) return e;
3665
+ this.onErrorCallback(e.ServerMessage);
3666
+ } else this.onErrorCallback("Unknown Error!");
3667
+ } catch (e) {
3668
+ this.handleException(e);
3669
+ }
3670
+ });
3671
+ }
3672
+ getUserPreferenceSettings() {
3673
+ return e(this, void 0, void 0, function* () {
3674
+ try {
3675
+ if (!this._ambientPaceAPI)
3676
+ return void d.error("SDK not initialized", this._logTag);
3677
+ var e = yield this._ambientPaceAPI.getUserPreferences();
3678
+ if (e) {
3679
+ if (200 === e.Status) return e;
3680
+ this.onErrorCallback(e.ServerMessage);
3681
+ } else this.onErrorCallback("Unknown Error!");
3682
+ } catch (e) {
3683
+ this.handleException(e);
3684
+ }
3685
+ });
3686
+ }
3687
+ updateUserPreferenceSettings(t) {
3688
+ return e(this, void 0, void 0, function* () {
3689
+ var e, n, i, r, o, c;
3690
+ try {
3691
+ if (!this._ambientPaceAPI)
3692
+ return void d.error("SDK not initialized", this._logTag);
3693
+ var u = yield this._ambientPaceAPI.updateUserPreference(
3694
+ null !== (e = t.AutomaticallyGenerateTranscript) && void 0 !== e && e,
3695
+ null !== (n = t.PreferredTranscriptionLanguage) && void 0 !== n
3696
+ ? n
3697
+ : "English",
3698
+ null !== (i = t.HighlightMedicalTerms) && void 0 !== i && i,
3699
+ null !== (r = t.DisplayPatientContext) && void 0 !== r && r,
3700
+ null !== (o = t.NoteOutputStyle) && void 0 !== o ? o : a.DashFormat,
3701
+ null !== (c = t.NoteOutputVerbosity) && void 0 !== c ? c : s.Detailed,
3702
+ );
3703
+ if (u) {
3704
+ if (200 === u.Status) return u;
3705
+ this.onErrorCallback(u.ServerMessage);
3706
+ } else this.onErrorCallback("Unknown Error!");
3707
+ } catch (e) {
3708
+ this.handleException(e);
3709
+ }
3710
+ });
3711
+ }
3712
+ isInternetAvailable(t) {
3713
+ return e(this, void 0, void 0, function* () {
3714
+ const e = yield pe.isOnline(t);
3715
+ return e || this.onErrorCallback(le), e;
3716
+ });
3717
+ }
3718
+ onEventCallback(e) {
3719
+ this.onJobCreated && this.onJobCreated(e);
3720
+ }
3721
+ onStateChangeCallback(e) {
3722
+ var t;
3723
+ if (this.forceStopAudio)
3724
+ return (
3725
+ null === (t = this.recorderIns) || void 0 === t || t.stopAudio(!1, !0),
3726
+ void (this.forceStopAudio = !1)
3727
+ );
3728
+ (this._isRecording = e), this.onStateChanged && this.onStateChanged(e);
3729
+ }
3730
+ handleException(e) {
3731
+ if (e instanceof TypeError) this.onErrorCallback(e.message);
3732
+ else {
3733
+ if (e instanceof c) throw e;
3734
+ d.error(e.message, this._logTag);
3735
+ }
3736
+ }
3737
+ onErrorCallback(e, t) {
3738
+ var n,
3739
+ i,
3740
+ r,
3741
+ s,
3742
+ a,
3743
+ c,
3744
+ u,
3745
+ l,
3746
+ h,
3747
+ f,
3748
+ p,
3749
+ g,
3750
+ v,
3751
+ b,
3752
+ m,
3753
+ y,
3754
+ S = { ErrorCode: null != t ? t : o.ERRUNKNOWN, ErrorMessage: e };
3755
+ try {
3756
+ var C = JSON.parse(e);
3757
+ (S.ErrorMessage = C.Data),
3758
+ C.Data === Z
3759
+ ? (this.stopListening(),
3760
+ d.error("Recording time limit exceeded", this._logTag),
3761
+ (S.ErrorCode = o.WSJOB05))
3762
+ : C.Data === H
3763
+ ? (this._isRecording
3764
+ ? null === (n = this.recorderIns) ||
3765
+ void 0 === n ||
3766
+ n.stopAudio(!1, !0)
3767
+ : (this.forceStopAudio = !0),
3768
+ (S.ErrorCode = o.WSAUTH03))
3769
+ : C.Data.includes(Y)
3770
+ ? (S.ErrorCode = o.WSAUTH04)
3771
+ : C.Data.includes(Q)
3772
+ ? (S.ErrorCode = o.WSJOB01)
3773
+ : C.Data.includes(X)
3774
+ ? (S.ErrorCode = o.WSJOB02)
3775
+ : C.Data.includes(ee)
3776
+ ? (S.ErrorCode = o.WSACC01)
3777
+ : C.Data.includes(te) && (S.ErrorCode = o.WSAUD01);
3778
+ } catch (e) {}
3779
+ (null === (i = S.ErrorMessage) || void 0 === i ? void 0 : i.includes(ne))
3780
+ ? (S.ErrorCode = o.SDK01)
3781
+ : (
3782
+ null === (r = S.ErrorMessage) || void 0 === r
3783
+ ? void 0
3784
+ : r.includes(ie)
3785
+ )
3786
+ ? (S.ErrorCode = o.SDK02)
3787
+ : (
3788
+ null === (s = S.ErrorMessage) || void 0 === s
3789
+ ? void 0
3790
+ : s.includes(re)
3791
+ )
3792
+ ? (S.ErrorCode = o.SDK03)
3793
+ : (
3794
+ null === (a = S.ErrorMessage) || void 0 === a
3795
+ ? void 0
3796
+ : a.includes(oe)
3797
+ )
3798
+ ? (S.ErrorCode = o.SDK04)
3799
+ : (
3800
+ null === (c = S.ErrorMessage) || void 0 === c
3801
+ ? void 0
3802
+ : c.includes(se)
3803
+ )
3804
+ ? (S.ErrorCode = o.SDK05)
3805
+ : (
3806
+ null === (u = S.ErrorMessage) || void 0 === u
3807
+ ? void 0
3808
+ : u.includes(ae)
3809
+ )
3810
+ ? (S.ErrorCode = o.SDK06)
3811
+ : (
3812
+ null === (l = S.ErrorMessage) || void 0 === l
3813
+ ? void 0
3814
+ : l.includes(ce)
3815
+ )
3816
+ ? (S.ErrorCode = o.SDK07)
3817
+ : (
3818
+ null === (h = S.ErrorMessage) || void 0 === h
3819
+ ? void 0
3820
+ : h.includes(ue)
3821
+ )
3822
+ ? (S.ErrorCode = o.SDK08)
3823
+ : (null === (f = S.ErrorMessage) || void 0 === f
3824
+ ? void 0
3825
+ : f.includes(q)) ||
3826
+ (null === (p = S.ErrorMessage) || void 0 === p ? void 0 : p.includes(z))
3827
+ ? (S.ErrorCode = o.AUTH01)
3828
+ : (null === (g = S.ErrorMessage) || void 0 === g ? void 0 : g.includes($))
3829
+ ? (S.ErrorCode = o.AUTH02)
3830
+ : (
3831
+ null === (v = S.ErrorMessage) || void 0 === v
3832
+ ? void 0
3833
+ : v.includes(le)
3834
+ )
3835
+ ? (S.ErrorCode = o.SDK12)
3836
+ : (
3837
+ null === (b = S.ErrorMessage) || void 0 === b
3838
+ ? void 0
3839
+ : b.includes(he)
3840
+ )
3841
+ ? (S.ErrorCode = o.SDK13)
3842
+ : (
3843
+ null === (m = S.ErrorMessage) || void 0 === m
3844
+ ? void 0
3845
+ : m.includes(de)
3846
+ )
3847
+ ? (S.ErrorCode = o.SDK14)
3848
+ : (null === (y = S.ErrorMessage) || void 0 === y
3849
+ ? void 0
3850
+ : y.includes(fe)) && (S.ErrorCode = o.SDK15),
3851
+ this.onError && this.onError(S);
3852
+ }
3853
+ onOtherResultsCallback(e) {
3854
+ this.onOtherResult && this.onOtherResult(e);
3855
+ }
3856
+ onIntensityCallback(e) {
3857
+ this.onIntensityValue && this.onIntensityValue(e);
3858
+ }
3859
+ onIdleMicCallback() {
3860
+ this.onIdleMic && this.onIdleMic();
3861
+ }
3862
+ onSpeechResponseCallback(e) {
3863
+ var t = JSON.parse(e);
3864
+ "note" === t.Type.toLowerCase() && this.onSoapNoteGenerated
3865
+ ? this.onSoapNoteGenerated(t.Data)
3866
+ : "transcript" === t.Type.toLowerCase() && this.onTranscriptGenerated
3867
+ ? this.onTranscriptGenerated(t.Data)
3868
+ : "codes" === t.Type.toLowerCase() &&
3869
+ this.onCodesGenerated &&
3870
+ this.onCodesGenerated(t.Data);
3871
+ }
3872
+ onJobStatusEventCallback(e) {
3873
+ this.onJobStatus && this.onJobStatus(e);
3874
+ }
3875
+ onMicRecoveredAfterUnpluggedCallback() {
3876
+ this.onMicRecoveredAfterUnplugged && this.onMicRecoveredAfterUnplugged();
3877
+ }
3878
+ onSessionEventCallback(e) {
3879
+ var t;
3880
+ if (!e) return;
3881
+ let n;
3882
+ try {
3883
+ n = "string" == typeof e ? JSON.parse(e) : e;
3884
+ } catch (e) {
3885
+ return void d.error(
3886
+ `Error parsing session event data: ${e}`,
3887
+ this._logTag,
3888
+ );
3889
+ }
3890
+ if (!n || !("Type" in n)) return;
3891
+ if (
3892
+ "meta" === n.Type.toLowerCase() &&
3893
+ (null === (t = this.config) || void 0 === t ? void 0 : t.onMetaEvent)
3894
+ ) {
3895
+ if (!n.JobID)
3896
+ return void d.error("JobID is missing in meta event", this._logTag);
3897
+ this.config.onMetaEvent(n.JobID);
3898
+ } else
3899
+ "error" === n.Type.toLowerCase() &&
3900
+ n.Data &&
3901
+ this.onErrorCallback(n.Data);
3902
+ if ("object" != typeof n.Event || null === n.Event) return;
3903
+ const { Type: i, Value: r } = n.Event;
3904
+ i &&
3905
+ ("SESSION_CREATED" === i && r
3906
+ ? d.log(`session Token ${r}`, this._logTag)
3907
+ : "SERVICE_DOWN" === i
3908
+ ? d.error(i, this._logTag)
3909
+ : "NO_DICTATION_STOP_MIC" === i
3910
+ ? (d.log("NO_DICTATION_STOP_MIC", this._logTag),
3911
+ this.onIdleMicCallback())
3912
+ : "INVALID_AUTH_CREDENTIALS" === i
3913
+ ? d.error("INVALID_AUTH_CREDENTIALS", this._logTag)
3914
+ : "LOW_BANDWIDTH" === i &&
3915
+ d.log("LOW_BANDWIDTH: Check internet connection", this._logTag));
3916
+ }
3917
+ validateConfig(e) {
3918
+ return (
3919
+ n.Against.NullOrEmpty(e.server, "Server"),
3920
+ n.Against.NullOrEmpty(e.subscriptionCode, "SubscriptionCode"),
3921
+ n.Against.NullOrEmpty(e.accessKey, "AccessKey"),
3922
+ n.Against.NullOrEmpty(e.userTag, "UserTag"),
3923
+ e
3924
+ );
3925
+ }
3926
+ createSocketConfig(e) {
3927
+ const n = new t(e);
3928
+ return (
3929
+ (n.onError = this.onErrorCallback.bind(this)),
3930
+ (n.onMetaEvent = this.onEventCallback.bind(this)),
3931
+ n
3932
+ );
3933
+ }
3934
+ }
3935
+ export {
3936
+ ge as AugnitoAmbient,
3937
+ o as ErrorCodes,
3938
+ c as HttpCodedError,
3939
+ a as NoteOutputStyleConfig,
3940
+ r as NoteTypeConfig,
3941
+ s as NoteVerbosityConfig,
3942
+ i as SettingsConfigType,
3943
+ };