agrasya-voice-sdk 1.0.25 → 1.0.27

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.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';const a0_0x3b6f92=a0_0x1e74;(function(_0x3de9b7,_0x560fa3){const _0xa2d58e=a0_0x1e74,_0x39ce37=_0x3de9b7();while(!![]){try{const _0xe005ec=-parseInt(_0xa2d58e(0xeb))/0x1+-parseInt(_0xa2d58e(0xbf))/0x2+-parseInt(_0xa2d58e(0x9c))/0x3+parseInt(_0xa2d58e(0xe0))/0x4+-parseInt(_0xa2d58e(0xae))/0x5*(parseInt(_0xa2d58e(0xc6))/0x6)+-parseInt(_0xa2d58e(0x9b))/0x7*(-parseInt(_0xa2d58e(0xa0))/0x8)+parseInt(_0xa2d58e(0xce))/0x9*(parseInt(_0xa2d58e(0xc1))/0xa);if(_0xe005ec===_0x560fa3)break;else _0x39ce37['push'](_0x39ce37['shift']());}catch(_0x587d7a){_0x39ce37['push'](_0x39ce37['shift']());}}}(a0_0x9a99,0xa5a11));var __create=Object[a0_0x3b6f92(0xd4)],__defProp=Object[a0_0x3b6f92(0xb1)],__getOwnPropDesc=Object[a0_0x3b6f92(0xab)],__getOwnPropNames=Object[a0_0x3b6f92(0xef)],__getProtoOf=Object[a0_0x3b6f92(0xe3)],__hasOwnProp=Object[a0_0x3b6f92(0xad)]['hasOwnProperty'],__export=(_0x15afb9,_0x4a8ed8)=>{for(var _0x19f786 in _0x4a8ed8)__defProp(_0x15afb9,_0x19f786,{'get':_0x4a8ed8[_0x19f786],'enumerable':!![]});},__copyProps=(_0x1e24ba,_0x345b5,_0x2b6160,_0x13f857)=>{const _0x26a3c9=a0_0x3b6f92;if(_0x345b5&&typeof _0x345b5===_0x26a3c9(0xf5)||typeof _0x345b5===_0x26a3c9(0xb3)){for(let _0xb489ba of __getOwnPropNames(_0x345b5))if(!__hasOwnProp['call'](_0x1e24ba,_0xb489ba)&&_0xb489ba!==_0x2b6160)__defProp(_0x1e24ba,_0xb489ba,{'get':()=>_0x345b5[_0xb489ba],'enumerable':!(_0x13f857=__getOwnPropDesc(_0x345b5,_0xb489ba))||_0x13f857[_0x26a3c9(0xf2)]});}return _0x1e24ba;},__toESM=(_0x47d9de,_0x349d3e,_0x215ae3)=>(_0x215ae3=_0x47d9de!=null?__create(__getProtoOf(_0x47d9de)):{},__copyProps(_0x349d3e||!_0x47d9de||!_0x47d9de[a0_0x3b6f92(0xda)]?__defProp(_0x215ae3,a0_0x3b6f92(0xbd),{'value':_0x47d9de,'enumerable':!![]}):_0x215ae3,_0x47d9de)),__toCommonJS=_0x3a1ad3=>__copyProps(__defProp({},a0_0x3b6f92(0xda),{'value':!![]}),_0x3a1ad3),index_exports={};function a0_0x9a99(){const _0x4ebde9=['stopVoiceSession','application/json','onTranscript','cleanSDP','audioStream','onmessage','appendChild','initializing','GET','callDuration','/v1/agrasya/usage','getTracks','durationInterval','168NFYAyT','3522639SuAsix','createDataChannel','socket','addTrack','1304OZcKTS','setupSocketListeners','mediaDevices','a=fmtp','audio','setRemoteDescription','session_ended','message','initializeBackendSession','srcObject','websocket','getOwnPropertyDescriptor','statusText','prototype','5YfteoK','stop','events','defineProperty','idle','function','connected','forEach','startVoiceSession','Invalid\x20SDP\x20received:\x20Missing\x20or\x20malformed\x20\x27v=\x27\x20line.','setupWebRTC','success','disconnect','setStatus','sdp','default','SDP\x20is\x20missing\x20in\x20the\x20response\x20from\x20the\x20backend.','819004cfVkSt','apiKey','10040oJBjar','join','cleanup','log','createOffer','2095812BaWRdt','json','model','socket.io-client','Failed\x20to\x20fetch\x20minutes\x20usage','o=-','fetchMinutesUsage','streams','22482OkhaCs','dataChannel','v=0','SDP\x20exchange\x20failed:\x20','Failed\x20to\x20initialize\x20session:\x20','debug','create','peerConnection','key\x20is\x20null\x20or\x20undefined.','stringify','onCallDurationUpdate','Response\x20from\x20/agrasya/connect:','__esModule','body','split','startsWith','catch','ontrack','3859944BKAjti','Backend\x20initialization\x20failed','error','getPrototypeOf','config','sessionId','emit','/v1/agrasya/client-token?language=','/v1/agrasya/connect','has','startTimer','865456ksseQZ','http://localhost:4001','stopTimer','ephKey','getOwnPropertyNames','dataUrl','getUserMedia','enumerable','data','Minutes\x20left:\x20','object','[AgrasyaSDK]','close','baseUrl'];a0_0x9a99=function(){return _0x4ebde9;};return a0_0x9a99();}__export(index_exports,{'AgrasyaVoiceSDK':()=>AgrasyaVoiceSDK}),module['exports']=__toCommonJS(index_exports);var import_socket=__toESM(require(a0_0x3b6f92(0xc9))),AgrasyaVoiceSDK=class{['config'];[a0_0x3b6f92(0xb0)];[a0_0x3b6f92(0xd5)]=null;['dataChannel']=null;[a0_0x3b6f92(0xfd)]=null;['socket']=null;['sessionId']=null;[a0_0x3b6f92(0xee)]=null;[a0_0x3b6f92(0xf0)]=null;['model']=null;[a0_0x3b6f92(0x102)]=0x0;[a0_0x3b6f92(0x9a)]=null;constructor(_0x248667,_0xda1b1d={}){const _0x12d8d3=a0_0x3b6f92;this[_0x12d8d3(0xe4)]={'baseUrl':_0x12d8d3(0xec),'language':'','debug':![],..._0x248667},this['events']=_0xda1b1d;}[a0_0x3b6f92(0xc4)](..._0x3ea964){const _0x2da689=a0_0x3b6f92;this[_0x2da689(0xe4)][_0x2da689(0xd3)]&&console[_0x2da689(0xc4)](_0x2da689(0xf6),..._0x3ea964);}[a0_0x3b6f92(0xbb)](_0x15070e){const _0x1e89d8=a0_0x3b6f92;this[_0x1e89d8(0xb0)]['onStatusChange']?.(_0x15070e);}[a0_0x3b6f92(0xea)](){const _0x31b603=a0_0x3b6f92;this[_0x31b603(0x102)]=0x0,this['durationInterval']=setInterval(()=>{const _0x36c653=_0x31b603;this[_0x36c653(0x102)]+=0x1,this[_0x36c653(0xb0)][_0x36c653(0xd8)]?.(this[_0x36c653(0x102)]);},0x3e8);}[a0_0x3b6f92(0xed)](){const _0x3a373b=a0_0x3b6f92;this[_0x3a373b(0x9a)]&&(clearInterval(this[_0x3a373b(0x9a)]),this[_0x3a373b(0x9a)]=null);}async[a0_0x3b6f92(0xa8)](){const _0x139711=a0_0x3b6f92,_0x557d4c=this[_0x139711(0xe4)][_0x139711(0xf8)]+_0x139711(0xe7)+this[_0x139711(0xe4)]['language'],_0x44c654=await fetch(_0x557d4c,{'method':_0x139711(0x101),'headers':{'x-agrasya-client-api-key':this[_0x139711(0xe4)][_0x139711(0xc0)],'Content-Type':_0x139711(0xfa)}});if(!_0x44c654['ok']){const _0x523b88=await _0x44c654[_0x139711(0xc7)]()[_0x139711(0xde)](()=>({'message':_0x44c654[_0x139711(0xac)]}));throw new Error(_0x139711(0xd2)+(_0x523b88[_0x139711(0xa7)]||_0x44c654[_0x139711(0xac)]));}const _0x377b13=await _0x44c654[_0x139711(0xc7)]();if(!_0x377b13[_0x139711(0xb9)])throw new Error(_0x377b13[_0x139711(0xa7)]||_0x139711(0xe1));return this['dataUrl']=_0x377b13[_0x139711(0xf3)]['DataUrl'],this[_0x139711(0xc8)]=_0x377b13['data'][_0x139711(0xc8)],_0x377b13[_0x139711(0xf3)];}async['setupWebRTC'](_0x548a83){const _0x53bd19=a0_0x3b6f92;this[_0x53bd19(0xd5)]=new RTCPeerConnection(),this['dataChannel']=this[_0x53bd19(0xd5)][_0x53bd19(0x9d)]('oai-events');this[_0x53bd19(0xcf)]&&(this['dataChannel'][_0x53bd19(0xfe)]=_0xea7158=>{const _0x4c6ef5=_0x53bd19,_0x53f0c7=JSON['parse'](_0xea7158[_0x4c6ef5(0xf3)]);this[_0x4c6ef5(0xb0)][_0x4c6ef5(0xfb)]?.(_0x53f0c7);});this['peerConnection'][_0x53bd19(0xdf)]=_0x2390dd=>{const _0x12ec6c=_0x53bd19,_0x56e42b=document['createElement'](_0x12ec6c(0xa4));_0x56e42b[_0x12ec6c(0xa9)]=_0x2390dd[_0x12ec6c(0xcd)][0x0],_0x56e42b['autoplay']=!![],document[_0x12ec6c(0xdb)][_0x12ec6c(0xff)](_0x56e42b);},this[_0x53bd19(0xfd)]=await navigator[_0x53bd19(0xa2)][_0x53bd19(0xf1)]({'audio':!![]});if(this[_0x53bd19(0xfd)]){const _0x148f1a=this['audioStream']['getTracks']()[0x0];this[_0x53bd19(0xd5)][_0x53bd19(0x9f)](_0x148f1a,this['audioStream']);}const _0x2ccb2a=await this[_0x53bd19(0xd5)][_0x53bd19(0xc5)]();await this[_0x53bd19(0xd5)]['setLocalDescription'](_0x2ccb2a);const _0x4bdf64=this['config'][_0x53bd19(0xf8)]+_0x53bd19(0xe8),_0x9ede68=await fetch(_0x4bdf64,{'method':'POST','body':JSON[_0x53bd19(0xd7)]({'sessionId':this[_0x53bd19(0xe5)],'sdp':_0x2ccb2a['sdp'],'model':this[_0x53bd19(0xc8)]}),'headers':{'x-agrasya-client-api-key':this[_0x53bd19(0xe4)][_0x53bd19(0xc0)],'Content-Type':'application/json'}});if(!_0x9ede68['ok']){const _0x571f93=await _0x9ede68[_0x53bd19(0xc7)]()[_0x53bd19(0xde)](()=>({'message':_0x9ede68[_0x53bd19(0xac)]}));throw new Error(_0x53bd19(0xd1)+(_0x571f93[_0x53bd19(0xa7)]||_0x9ede68[_0x53bd19(0xac)]));}const _0x569cba=await _0x9ede68['json']();this[_0x53bd19(0xc4)](_0x53bd19(0xd9),_0x569cba);let _0x5353b4=_0x569cba[_0x53bd19(0xbc)];if(!_0x5353b4)throw new Error(_0x53bd19(0xbe));_0x5353b4=this['cleanSDP'](_0x5353b4);if(!_0x5353b4['startsWith'](_0x53bd19(0xd0)))throw new Error(_0x53bd19(0xb7));this['log']('Cleaned\x20SDP:',_0x5353b4);const _0x1e16d2={'type':'answer','sdp':_0x5353b4};await this[_0x53bd19(0xd5)][_0x53bd19(0xa5)](_0x1e16d2);}[a0_0x3b6f92(0xa1)](_0x2ad505){const _0x21e4f4=a0_0x3b6f92;_0x2ad505['on'](_0x21e4f4(0xba),()=>{this['cleanup']();}),_0x2ad505['on'](_0x21e4f4(0xa6),()=>{const _0x590940=_0x21e4f4;this[_0x590940(0xc3)]();});}async[a0_0x3b6f92(0xb6)](_0x18a7e5){const _0x32c192=a0_0x3b6f92;try{this[_0x32c192(0xbb)](_0x32c192(0x100));const _0x2250fa=await this[_0x32c192(0xa8)]();this[_0x32c192(0xe5)]=_0x2250fa[_0x32c192(0xe5)],this[_0x32c192(0xee)]=_0x2250fa[_0x32c192(0xee)];if(!this[_0x32c192(0xee)])throw new Error(_0x32c192(0xd6));const _0x3b9458=await this[_0x32c192(0xcc)]();this[_0x32c192(0xc4)](_0x32c192(0xf4)+_0x3b9458),await this[_0x32c192(0xb8)](this[_0x32c192(0xee)]),this['socket']=(0x0,import_socket[_0x32c192(0xbd)])(this[_0x32c192(0xe4)][_0x32c192(0xf8)],{'transports':[_0x32c192(0xaa)]}),this[_0x32c192(0x9e)][_0x32c192(0xe6)]('join_session',{'sessionId':this[_0x32c192(0xe5)]}),this[_0x32c192(0xa1)](this[_0x32c192(0x9e)]),this[_0x32c192(0xbb)](_0x32c192(0xb4)),this[_0x32c192(0xea)]();}catch(_0x2c4667){this[_0x32c192(0xbb)](_0x32c192(0xe2));throw _0x2c4667;}}async[a0_0x3b6f92(0xf9)](){const _0x59da35=a0_0x3b6f92;this[_0x59da35(0xc3)]();}[a0_0x3b6f92(0xc3)](){const _0x4011a5=a0_0x3b6f92;this[_0x4011a5(0xd5)]&&(this[_0x4011a5(0xd5)][_0x4011a5(0xf7)](),this[_0x4011a5(0xd5)]=null),this[_0x4011a5(0xcf)]&&(this[_0x4011a5(0xcf)][_0x4011a5(0xf7)](),this[_0x4011a5(0xcf)]=null),this[_0x4011a5(0xfd)]&&(this[_0x4011a5(0xfd)][_0x4011a5(0x104)]()[_0x4011a5(0xb5)](_0x5da4a1=>_0x5da4a1[_0x4011a5(0xaf)]()),this['audioStream']=null),this['socket']&&(this['socket'][_0x4011a5(0xba)](),this[_0x4011a5(0x9e)]=null),this[_0x4011a5(0xed)](),this[_0x4011a5(0xbb)](_0x4011a5(0xb2));}async[a0_0x3b6f92(0xcc)](){const _0x3cdf27=a0_0x3b6f92,_0x264506=this[_0x3cdf27(0xe4)]['baseUrl']+_0x3cdf27(0x103),_0x1dcc64=await fetch(_0x264506,{'method':_0x3cdf27(0x101),'headers':{'x-agrasya-client-api-key':this[_0x3cdf27(0xe4)][_0x3cdf27(0xc0)],'Content-Type':_0x3cdf27(0xfa)}});if(!_0x1dcc64['ok']){const _0x1b1f3f=await _0x1dcc64[_0x3cdf27(0xc7)]()[_0x3cdf27(0xde)](()=>({'message':_0x1dcc64[_0x3cdf27(0xac)]}));throw new Error('Failed\x20to\x20fetch\x20minutes\x20usage:\x20'+(_0x1b1f3f['message']||_0x1dcc64[_0x3cdf27(0xac)]));}const _0x388a64=await _0x1dcc64[_0x3cdf27(0xc7)]();if(!_0x388a64[_0x3cdf27(0xb9)])throw new Error(_0x388a64[_0x3cdf27(0xa7)]||_0x3cdf27(0xca));return _0x388a64[_0x3cdf27(0xf3)]['minutesLeft'];}[a0_0x3b6f92(0xfc)](_0x2e575c){const _0x1cdb49=a0_0x3b6f92,_0x447e5a=_0x2e575c[_0x1cdb49(0xdc)]('\x0d\x0a'),_0x1c7d66=new Set(),_0x56275c=_0x447e5a['filter'](_0x128474=>{const _0x5db0f6=_0x1cdb49;if(_0x128474['startsWith'](_0x5db0f6(0xcb)))return![];if(_0x128474['startsWith']('a=rtpmap')||_0x128474[_0x5db0f6(0xdd)](_0x5db0f6(0xa3))){if(_0x1c7d66[_0x5db0f6(0xe9)](_0x128474))return![];_0x1c7d66['add'](_0x128474);}return!![];});return _0x56275c[_0x1cdb49(0xc2)]('\x0d\x0a');}};function a0_0x1e74(_0x14d5d0,_0x8c4dd2){_0x14d5d0=_0x14d5d0-0x9a;const _0x9a9975=a0_0x9a99();let _0x1e7451=_0x9a9975[_0x14d5d0];return _0x1e7451;}0x0&&(module['exports']={'AgrasyaVoiceSDK':AgrasyaVoiceSDK});
1
+ 'use strict';const a0_0x251f4b=a0_0x34aa;(function(_0x89599d,_0x4ae75b){const _0x55d2fd=a0_0x34aa,_0xfdd3e3=_0x89599d();while(!![]){try{const _0x20d4b3=-parseInt(_0x55d2fd(0xf0))/0x1+-parseInt(_0x55d2fd(0xbb))/0x2*(parseInt(_0x55d2fd(0xcd))/0x3)+parseInt(_0x55d2fd(0xa4))/0x4+parseInt(_0x55d2fd(0xe3))/0x5+parseInt(_0x55d2fd(0xd0))/0x6+-parseInt(_0x55d2fd(0xb0))/0x7+parseInt(_0x55d2fd(0xd6))/0x8;if(_0x20d4b3===_0x4ae75b)break;else _0xfdd3e3['push'](_0xfdd3e3['shift']());}catch(_0x9072f9){_0xfdd3e3['push'](_0xfdd3e3['shift']());}}}(a0_0x1ab6,0xe15bf));var __create=Object[a0_0x251f4b(0xc5)],__defProp=Object[a0_0x251f4b(0xfc)],__getOwnPropDesc=Object[a0_0x251f4b(0xc2)],__getOwnPropNames=Object[a0_0x251f4b(0xf2)],__getProtoOf=Object[a0_0x251f4b(0xdc)],__hasOwnProp=Object[a0_0x251f4b(0x9b)][a0_0x251f4b(0xf8)],__export=(_0x1928f7,_0x1d4aa4)=>{for(var _0x3fa4f4 in _0x1d4aa4)__defProp(_0x1928f7,_0x3fa4f4,{'get':_0x1d4aa4[_0x3fa4f4],'enumerable':!![]});},__copyProps=(_0x30c564,_0x18ccf2,_0x46040d,_0x44c0d3)=>{const _0xa68e8=a0_0x251f4b;if(_0x18ccf2&&typeof _0x18ccf2===_0xa68e8(0xb6)||typeof _0x18ccf2===_0xa68e8(0xdf)){for(let _0x238d02 of __getOwnPropNames(_0x18ccf2))if(!__hasOwnProp[_0xa68e8(0xbc)](_0x30c564,_0x238d02)&&_0x238d02!==_0x46040d)__defProp(_0x30c564,_0x238d02,{'get':()=>_0x18ccf2[_0x238d02],'enumerable':!(_0x44c0d3=__getOwnPropDesc(_0x18ccf2,_0x238d02))||_0x44c0d3['enumerable']});}return _0x30c564;},__toESM=(_0x475911,_0x673257,_0x44f5e6)=>(_0x44f5e6=_0x475911!=null?__create(__getProtoOf(_0x475911)):{},__copyProps(_0x673257||!_0x475911||!_0x475911[a0_0x251f4b(0x92)]?__defProp(_0x44f5e6,a0_0x251f4b(0xaf),{'value':_0x475911,'enumerable':!![]}):_0x44f5e6,_0x475911)),__toCommonJS=_0x3fbd95=>__copyProps(__defProp({},'__esModule',{'value':!![]}),_0x3fbd95),index_exports={};function a0_0x34aa(_0x47231b,_0x58ff8f){_0x47231b=_0x47231b-0x8e;const _0x1ab6e5=a0_0x1ab6();let _0x34aa10=_0x1ab6e5[_0x47231b];return _0x34aa10;}function a0_0x1ab6(){const _0x4892b2=['Minutes\x20left:\x20','split','idle','forEach','emit','DataUrl','dataChannel','27975PfAjvQ','stopTimer','addTrack','4013202UGSqCW','setupSocketListeners','onCallDurationUpdate','body','session_ended','onStatusChange','9421528dtygNL','model','add','startVoiceSession','language','parse','getPrototypeOf','success','catch','function','websocket','onTranscript','Invalid\x20SDP\x20received:\x20Missing\x20or\x20malformed\x20\x27v=\x27\x20line.','7364445IhqeGf','exports','json','Backend\x20initialization\x20failed','createElement','answer','socket.io-client','streams','connected','setStatus','createDataChannel','data','events','1744454pwNCIJ','dataUrl','getOwnPropertyNames','/v1/agrasya/client-token?language=','ontrack','Failed\x20to\x20fetch\x20minutes\x20usage:\x20','application/json','sessionId','hasOwnProperty','a=rtpmap','minutesLeft','log','defineProperty','audio','getTracks','a=fmtp','audioStream','v=0','stopVoiceSession','join_session','filter','join','__esModule','POST','Response\x20from\x20/agrasya/connect:','statusText','close','baseUrl','callDuration','Cleaned\x20SDP:','peerConnection','prototype','message','disconnect','debug','sdp','[AgrasyaSDK]','/v1/agrasya/usage','key\x20is\x20null\x20or\x20undefined.','getUserMedia','4727760AWbZcC','config','initializeBackendSession','http://localhost:4001','cleanup','appendChild','socket','o=-','error','setRemoteDescription','has','default','11335709NchsTd','initializing','mediaDevices','fetchMinutesUsage','stop','durationInterval','object','/v1/agrasya/connect','cleanSDP','setupWebRTC','stringify','46tWHPYO','call','Failed\x20to\x20fetch\x20minutes\x20usage','ephKey','oai-events','onmessage','apiKey','getOwnPropertyDescriptor','startsWith','Failed\x20to\x20initialize\x20session:\x20','create'];a0_0x1ab6=function(){return _0x4892b2;};return a0_0x1ab6();}__export(index_exports,{'AgrasyaVoiceSDK':()=>AgrasyaVoiceSDK}),module['exports']=__toCommonJS(index_exports);var import_socket=__toESM(require(a0_0x251f4b(0xe9))),AgrasyaVoiceSDK=class{[a0_0x251f4b(0xa5)];['events'];['peerConnection']=null;[a0_0x251f4b(0xcc)]=null;[a0_0x251f4b(0x100)]=null;[a0_0x251f4b(0xaa)]=null;[a0_0x251f4b(0xf7)]=null;[a0_0x251f4b(0xbe)]=null;['dataUrl']=null;[a0_0x251f4b(0xd7)]=null;[a0_0x251f4b(0x98)]=0x0;[a0_0x251f4b(0xb5)]=null;constructor(_0x145054,_0x18960b={}){const _0x36e090=a0_0x251f4b;this['config']={'baseUrl':_0x36e090(0xa7),'language':'','debug':![],..._0x145054},this[_0x36e090(0xef)]=_0x18960b;}[a0_0x251f4b(0xfb)](..._0x2929a3){const _0x400de8=a0_0x251f4b;this[_0x400de8(0xa5)][_0x400de8(0x9e)]&&console[_0x400de8(0xfb)](_0x400de8(0xa0),..._0x2929a3);}[a0_0x251f4b(0xec)](_0x151771){const _0x1b3cad=a0_0x251f4b;this[_0x1b3cad(0xef)][_0x1b3cad(0xd5)]?.(_0x151771);}['startTimer'](){const _0x50f4ce=a0_0x251f4b;this['callDuration']=0x0,this[_0x50f4ce(0xb5)]=setInterval(()=>{const _0x41704d=_0x50f4ce;this[_0x41704d(0x98)]+=0x1,this[_0x41704d(0xef)][_0x41704d(0xd2)]?.(this[_0x41704d(0x98)]);},0x3e8);}[a0_0x251f4b(0xce)](){const _0x499c08=a0_0x251f4b;this[_0x499c08(0xb5)]&&(clearInterval(this['durationInterval']),this[_0x499c08(0xb5)]=null);}async[a0_0x251f4b(0xa6)](){const _0x1397e3=a0_0x251f4b,_0xb8ddc5=this[_0x1397e3(0xa5)][_0x1397e3(0x97)]+_0x1397e3(0xf3)+this[_0x1397e3(0xa5)][_0x1397e3(0xda)],_0x48eb41=await fetch(_0xb8ddc5,{'method':'GET','headers':{'x-agrasya-client-api-key':this[_0x1397e3(0xa5)]['apiKey'],'Content-Type':_0x1397e3(0xf6)}});if(!_0x48eb41['ok']){const _0x2c4e35=await _0x48eb41[_0x1397e3(0xe5)]()[_0x1397e3(0xde)](()=>({'message':_0x48eb41[_0x1397e3(0x95)]}));throw new Error(_0x1397e3(0xc4)+(_0x2c4e35[_0x1397e3(0x9c)]||_0x48eb41[_0x1397e3(0x95)]));}const _0x269f1b=await _0x48eb41[_0x1397e3(0xe5)]();if(!_0x269f1b[_0x1397e3(0xdd)])throw new Error(_0x269f1b[_0x1397e3(0x9c)]||_0x1397e3(0xe6));return this[_0x1397e3(0xf1)]=_0x269f1b[_0x1397e3(0xee)][_0x1397e3(0xcb)],this[_0x1397e3(0xd7)]=_0x269f1b['data'][_0x1397e3(0xd7)],_0x269f1b[_0x1397e3(0xee)];}async[a0_0x251f4b(0xb9)](_0xc8bd91){const _0x11df09=a0_0x251f4b;this['peerConnection']=new RTCPeerConnection(),this[_0x11df09(0xcc)]=this[_0x11df09(0x9a)][_0x11df09(0xed)](_0x11df09(0xbf));this['dataChannel']&&(this[_0x11df09(0xcc)][_0x11df09(0xc0)]=_0x219fd5=>{const _0x56a9e9=_0x11df09,_0x2c5253=JSON[_0x56a9e9(0xdb)](_0x219fd5[_0x56a9e9(0xee)]);this[_0x56a9e9(0xef)][_0x56a9e9(0xe1)]?.(_0x2c5253);});this[_0x11df09(0x9a)][_0x11df09(0xf4)]=_0x3b632f=>{const _0x32133d=_0x11df09,_0x1acec0=document[_0x32133d(0xe7)](_0x32133d(0xfd));_0x1acec0['srcObject']=_0x3b632f[_0x32133d(0xea)][0x0],_0x1acec0['autoplay']=!![],document[_0x32133d(0xd3)][_0x32133d(0xa9)](_0x1acec0);},this[_0x11df09(0x100)]=await navigator[_0x11df09(0xb2)][_0x11df09(0xa3)]({'audio':!![]});if(this[_0x11df09(0x100)]){const _0x42dc48=this[_0x11df09(0x100)]['getTracks']()[0x0];this[_0x11df09(0x9a)][_0x11df09(0xcf)](_0x42dc48,this[_0x11df09(0x100)]);}const _0x377f86=await this[_0x11df09(0x9a)]['createOffer']();await this[_0x11df09(0x9a)]['setLocalDescription'](_0x377f86);const _0x214f2d=this[_0x11df09(0xa5)][_0x11df09(0x97)]+_0x11df09(0xb7),_0x51f6bc=await fetch(_0x214f2d,{'method':_0x11df09(0x93),'body':JSON[_0x11df09(0xba)]({'sessionId':this[_0x11df09(0xf7)],'sdp':_0x377f86[_0x11df09(0x9f)],'model':this[_0x11df09(0xd7)]}),'headers':{'x-agrasya-client-api-key':this[_0x11df09(0xa5)][_0x11df09(0xc1)],'Content-Type':'application/json'}});if(!_0x51f6bc['ok']){const _0x583666=await _0x51f6bc[_0x11df09(0xe5)]()['catch'](()=>({'message':_0x51f6bc['statusText']}));throw new Error('SDP\x20exchange\x20failed:\x20'+(_0x583666['message']||_0x51f6bc['statusText']));}const _0x39b713=await _0x51f6bc[_0x11df09(0xe5)]();this[_0x11df09(0xfb)](_0x11df09(0x94),_0x39b713);let _0x1114fd=_0x39b713[_0x11df09(0x9f)];_0x1114fd=this['cleanSDP'](_0x1114fd);if(!_0x1114fd[_0x11df09(0xc3)](_0x11df09(0x101)))throw new Error(_0x11df09(0xe2));this[_0x11df09(0xfb)](_0x11df09(0x99),_0x1114fd);const _0xa3966a={'type':_0x11df09(0xe8),'sdp':_0x1114fd};await this[_0x11df09(0x9a)][_0x11df09(0xad)](_0xa3966a);}[a0_0x251f4b(0xd1)](_0x53760c){const _0x143cc5=a0_0x251f4b;_0x53760c['on'](_0x143cc5(0x9d),()=>{const _0xf37630=_0x143cc5;this[_0xf37630(0xa8)]();}),_0x53760c['on'](_0x143cc5(0xd4),()=>{const _0x41b525=_0x143cc5;this[_0x41b525(0xa8)]();});}async[a0_0x251f4b(0xd9)](_0x4f34ae){const _0x3f8dfa=a0_0x251f4b;try{this[_0x3f8dfa(0xec)](_0x3f8dfa(0xb1));const _0x5385e3=await this['initializeBackendSession']();this[_0x3f8dfa(0xf7)]=_0x5385e3[_0x3f8dfa(0xf7)],this[_0x3f8dfa(0xbe)]=_0x5385e3['ephKey'];if(!this[_0x3f8dfa(0xbe)])throw new Error(_0x3f8dfa(0xa2));const _0x501502=await this[_0x3f8dfa(0xb3)]();this[_0x3f8dfa(0xfb)](_0x3f8dfa(0xc6)+_0x501502),await this[_0x3f8dfa(0xb9)](this[_0x3f8dfa(0xbe)]),this[_0x3f8dfa(0xaa)]=(0x0,import_socket[_0x3f8dfa(0xaf)])(this[_0x3f8dfa(0xa5)][_0x3f8dfa(0x97)],{'transports':[_0x3f8dfa(0xe0)]}),this[_0x3f8dfa(0xaa)][_0x3f8dfa(0xca)](_0x3f8dfa(0x8f),{'sessionId':this[_0x3f8dfa(0xf7)]}),this['setupSocketListeners'](this[_0x3f8dfa(0xaa)]),this['setStatus'](_0x3f8dfa(0xeb)),this['startTimer']();}catch(_0x5aca3d){this[_0x3f8dfa(0xec)](_0x3f8dfa(0xac));throw _0x5aca3d;}}async[a0_0x251f4b(0x8e)](){const _0x1c656e=a0_0x251f4b;this[_0x1c656e(0xa8)]();}['cleanup'](){const _0x423eb3=a0_0x251f4b;this[_0x423eb3(0x9a)]&&(this[_0x423eb3(0x9a)][_0x423eb3(0x96)](),this[_0x423eb3(0x9a)]=null),this[_0x423eb3(0xcc)]&&(this[_0x423eb3(0xcc)][_0x423eb3(0x96)](),this['dataChannel']=null),this[_0x423eb3(0x100)]&&(this['audioStream'][_0x423eb3(0xfe)]()[_0x423eb3(0xc9)](_0x353fc5=>_0x353fc5[_0x423eb3(0xb4)]()),this[_0x423eb3(0x100)]=null),this[_0x423eb3(0xaa)]&&(this[_0x423eb3(0xaa)]['disconnect'](),this[_0x423eb3(0xaa)]=null),this[_0x423eb3(0xce)](),this[_0x423eb3(0xec)](_0x423eb3(0xc8));}async['fetchMinutesUsage'](){const _0x348d88=a0_0x251f4b,_0x1fdd58=this[_0x348d88(0xa5)][_0x348d88(0x97)]+_0x348d88(0xa1),_0x35c435=await fetch(_0x1fdd58,{'method':'GET','headers':{'x-agrasya-client-api-key':this[_0x348d88(0xa5)][_0x348d88(0xc1)],'Content-Type':_0x348d88(0xf6)}});if(!_0x35c435['ok']){const _0x3dde1a=await _0x35c435[_0x348d88(0xe5)]()['catch'](()=>({'message':_0x35c435['statusText']}));throw new Error(_0x348d88(0xf5)+(_0x3dde1a[_0x348d88(0x9c)]||_0x35c435[_0x348d88(0x95)]));}const _0xb0a43f=await _0x35c435[_0x348d88(0xe5)]();if(!_0xb0a43f[_0x348d88(0xdd)])throw new Error(_0xb0a43f[_0x348d88(0x9c)]||_0x348d88(0xbd));return _0xb0a43f[_0x348d88(0xee)][_0x348d88(0xfa)];}[a0_0x251f4b(0xb8)](_0x51b900){const _0x29d918=a0_0x251f4b,_0x5d61b9=_0x51b900[_0x29d918(0xc7)]('\x0d\x0a'),_0x1bb585=new Set(),_0x3c4eb4=_0x5d61b9[_0x29d918(0x90)](_0x343b50=>{const _0x1801d5=_0x29d918;if(_0x343b50[_0x1801d5(0xc3)](_0x1801d5(0xab)))return![];if(_0x343b50[_0x1801d5(0xc3)](_0x1801d5(0xf9))||_0x343b50[_0x1801d5(0xc3)](_0x1801d5(0xff))){if(_0x1bb585[_0x1801d5(0xae)](_0x343b50))return![];_0x1bb585[_0x1801d5(0xd8)](_0x343b50);}return!![];});return _0x3c4eb4[_0x29d918(0x91)]('\x0d\x0a');}};0x0&&(module[a0_0x251f4b(0xe4)]={'AgrasyaVoiceSDK':AgrasyaVoiceSDK});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- function a1_0x24ab(){const _0xf21cc4=['config','add','SDP\x20exchange\x20failed:\x20','createElement','events','audioStream','getTracks','startsWith','split','createOffer','callDuration','session_ended','/v1/agrasya/client-token?language=','30GEcalT','streams','audio','stop','142Ihjdfp','forEach','idle','peerConnection','sessionId','a=fmtp','success','setStatus','cleanSDP','39708jfbwpe','socket','language','65930gSrAUi','disconnect','sdp','Failed\x20to\x20fetch\x20minutes\x20usage','4372wBmgCe','Cleaned\x20SDP:','setupWebRTC','onCallDurationUpdate','join','Backend\x20initialization\x20failed','baseUrl','log','oai-events','fetchMinutesUsage','connected','ephKey','516220BQOZrn','durationInterval','createDataChannel','8092700DhQqWP','statusText','cleanup','parse','9057294jWlSvQ','Failed\x20to\x20initialize\x20session:\x20','filter','onStatusChange','error','message','ontrack','application/json','dataUrl','setLocalDescription','SDP\x20is\x20missing\x20in\x20the\x20response\x20from\x20the\x20backend.','join_session','startTimer','Minutes\x20left:\x20','getUserMedia','http://localhost:4001','data','dataChannel','[AgrasyaSDK]','initializing','model','initializeBackendSession','1133zfGstt','/v1/agrasya/usage','mediaDevices','2286474EseNrZ','minutesLeft','apiKey','o=-','close','GET','websocket','544bqPGaq','onTranscript','json','setRemoteDescription','/v1/agrasya/connect','setupSocketListeners','debug','Invalid\x20SDP\x20received:\x20Missing\x20or\x20malformed\x20\x27v=\x27\x20line.','addTrack','catch'];a1_0x24ab=function(){return _0xf21cc4;};return a1_0x24ab();}const a1_0x536618=a1_0x46ed;(function(_0x51e7be,_0x396439){const _0x165cd0=a1_0x46ed,_0x404059=_0x51e7be();while(!![]){try{const _0x3f01af=-parseInt(_0x165cd0(0xc8))/0x1*(-parseInt(_0x165cd0(0xb8))/0x2)+parseInt(_0x165cd0(0xf4))/0x3+parseInt(_0x165cd0(0xd4))/0x4*(-parseInt(_0x165cd0(0xb4))/0x5)+-parseInt(_0x165cd0(0xdb))/0x6+parseInt(_0x165cd0(0xd7))/0x7+-parseInt(_0x165cd0(0xfb))/0x8*(-parseInt(_0x165cd0(0xc1))/0x9)+-parseInt(_0x165cd0(0xc4))/0xa*(-parseInt(_0x165cd0(0xf1))/0xb);if(_0x3f01af===_0x396439)break;else _0x404059['push'](_0x404059['shift']());}catch(_0xa188f7){_0x404059['push'](_0x404059['shift']());}}}(a1_0x24ab,0xe18ee));import a1_0x2ef91d from'socket.io-client';var AgrasyaVoiceSDK=class{['config'];[a1_0x536618(0xab)];[a1_0x536618(0xbb)]=null;['dataChannel']=null;[a1_0x536618(0xac)]=null;[a1_0x536618(0xc2)]=null;[a1_0x536618(0xbc)]=null;[a1_0x536618(0xd3)]=null;['dataUrl']=null;[a1_0x536618(0xef)]=null;['callDuration']=0x0;[a1_0x536618(0xd5)]=null;constructor(_0x23536e,_0x427900={}){const _0x372e49=a1_0x536618;this[_0x372e49(0xa7)]={'baseUrl':_0x372e49(0xea),'language':'','debug':![],..._0x23536e},this[_0x372e49(0xab)]=_0x427900;}[a1_0x536618(0xcf)](..._0x25c891){const _0x4a3925=a1_0x536618;this[_0x4a3925(0xa7)][_0x4a3925(0x101)]&&console[_0x4a3925(0xcf)](_0x4a3925(0xed),..._0x25c891);}[a1_0x536618(0xbf)](_0x2cf1e6){const _0x114b28=a1_0x536618;this[_0x114b28(0xab)][_0x114b28(0xde)]?.(_0x2cf1e6);}[a1_0x536618(0xe7)](){const _0x58bd08=a1_0x536618;this[_0x58bd08(0xb1)]=0x0,this[_0x58bd08(0xd5)]=setInterval(()=>{const _0x3ce193=_0x58bd08;this['callDuration']+=0x1,this[_0x3ce193(0xab)][_0x3ce193(0xcb)]?.(this[_0x3ce193(0xb1)]);},0x3e8);}['stopTimer'](){const _0x391865=a1_0x536618;this['durationInterval']&&(clearInterval(this['durationInterval']),this[_0x391865(0xd5)]=null);}async[a1_0x536618(0xf0)](){const _0x1365bf=a1_0x536618,_0x5daf1a=this[_0x1365bf(0xa7)]['baseUrl']+_0x1365bf(0xb3)+this[_0x1365bf(0xa7)][_0x1365bf(0xc3)],_0x582d62=await fetch(_0x5daf1a,{'method':_0x1365bf(0xf9),'headers':{'x-agrasya-client-api-key':this['config'][_0x1365bf(0xf6)],'Content-Type':_0x1365bf(0xe2)}});if(!_0x582d62['ok']){const _0x20c392=await _0x582d62[_0x1365bf(0xfd)]()[_0x1365bf(0xa6)](()=>({'message':_0x582d62[_0x1365bf(0xd8)]}));throw new Error(_0x1365bf(0xdc)+(_0x20c392[_0x1365bf(0xe0)]||_0x582d62[_0x1365bf(0xd8)]));}const _0xc9b4bb=await _0x582d62[_0x1365bf(0xfd)]();if(!_0xc9b4bb['success'])throw new Error(_0xc9b4bb['message']||_0x1365bf(0xcd));return this[_0x1365bf(0xe3)]=_0xc9b4bb[_0x1365bf(0xeb)]['DataUrl'],this[_0x1365bf(0xef)]=_0xc9b4bb[_0x1365bf(0xeb)][_0x1365bf(0xef)],_0xc9b4bb['data'];}async[a1_0x536618(0xca)](_0x13cf76){const _0x372179=a1_0x536618;this[_0x372179(0xbb)]=new RTCPeerConnection(),this['dataChannel']=this[_0x372179(0xbb)][_0x372179(0xd6)](_0x372179(0xd0));this[_0x372179(0xec)]&&(this['dataChannel']['onmessage']=_0x35eddf=>{const _0x397b0b=_0x372179,_0x4b2a9d=JSON[_0x397b0b(0xda)](_0x35eddf['data']);this[_0x397b0b(0xab)][_0x397b0b(0xfc)]?.(_0x4b2a9d);});this['peerConnection'][_0x372179(0xe1)]=_0x537e00=>{const _0x3c668c=_0x372179,_0x58a789=document[_0x3c668c(0xaa)](_0x3c668c(0xb6));_0x58a789['srcObject']=_0x537e00[_0x3c668c(0xb5)][0x0],_0x58a789['autoplay']=!![],document['body']['appendChild'](_0x58a789);},this[_0x372179(0xac)]=await navigator[_0x372179(0xf3)][_0x372179(0xe9)]({'audio':!![]});if(this[_0x372179(0xac)]){const _0x41df5a=this['audioStream'][_0x372179(0xad)]()[0x0];this[_0x372179(0xbb)][_0x372179(0x103)](_0x41df5a,this[_0x372179(0xac)]);}const _0x1e73c2=await this[_0x372179(0xbb)][_0x372179(0xb0)]();await this[_0x372179(0xbb)][_0x372179(0xe4)](_0x1e73c2);const _0x2de812=this[_0x372179(0xa7)][_0x372179(0xce)]+_0x372179(0xff),_0x320e85=await fetch(_0x2de812,{'method':'POST','body':JSON['stringify']({'sessionId':this[_0x372179(0xbc)],'sdp':_0x1e73c2[_0x372179(0xc6)],'model':this['model']}),'headers':{'x-agrasya-client-api-key':this['config'][_0x372179(0xf6)],'Content-Type':'application/json'}});if(!_0x320e85['ok']){const _0x5b7ea1=await _0x320e85['json']()['catch'](()=>({'message':_0x320e85[_0x372179(0xd8)]}));throw new Error(_0x372179(0xa9)+(_0x5b7ea1[_0x372179(0xe0)]||_0x320e85[_0x372179(0xd8)]));}const _0x3239c8=await _0x320e85[_0x372179(0xfd)]();this[_0x372179(0xcf)]('Response\x20from\x20/agrasya/connect:',_0x3239c8);let _0x53ac5d=_0x3239c8[_0x372179(0xc6)];if(!_0x53ac5d)throw new Error(_0x372179(0xe5));_0x53ac5d=this[_0x372179(0xc0)](_0x53ac5d);if(!_0x53ac5d[_0x372179(0xae)]('v=0'))throw new Error(_0x372179(0x102));this[_0x372179(0xcf)](_0x372179(0xc9),_0x53ac5d);const _0x27846e={'type':'answer','sdp':_0x53ac5d};await this[_0x372179(0xbb)][_0x372179(0xfe)](_0x27846e);}[a1_0x536618(0x100)](_0x3c4052){const _0x258fea=a1_0x536618;_0x3c4052['on'](_0x258fea(0xc5),()=>{const _0x4c0a3e=_0x258fea;this[_0x4c0a3e(0xd9)]();}),_0x3c4052['on'](_0x258fea(0xb2),()=>{const _0x494bba=_0x258fea;this[_0x494bba(0xd9)]();});}async['startVoiceSession'](_0x215dd4){const _0x3efbde=a1_0x536618;try{this['setStatus'](_0x3efbde(0xee));const _0x404128=await this[_0x3efbde(0xf0)]();this[_0x3efbde(0xbc)]=_0x404128[_0x3efbde(0xbc)],this[_0x3efbde(0xd3)]=_0x404128[_0x3efbde(0xd3)];if(!this[_0x3efbde(0xd3)])throw new Error('key\x20is\x20null\x20or\x20undefined.');const _0x46c035=await this[_0x3efbde(0xd1)]();this[_0x3efbde(0xcf)](_0x3efbde(0xe8)+_0x46c035),await this[_0x3efbde(0xca)](this[_0x3efbde(0xd3)]),this[_0x3efbde(0xc2)]=a1_0x2ef91d(this[_0x3efbde(0xa7)][_0x3efbde(0xce)],{'transports':[_0x3efbde(0xfa)]}),this['socket']['emit'](_0x3efbde(0xe6),{'sessionId':this[_0x3efbde(0xbc)]}),this[_0x3efbde(0x100)](this[_0x3efbde(0xc2)]),this[_0x3efbde(0xbf)](_0x3efbde(0xd2)),this[_0x3efbde(0xe7)]();}catch(_0x1d0775){this[_0x3efbde(0xbf)](_0x3efbde(0xdf));throw _0x1d0775;}}async['stopVoiceSession'](){const _0x52a5f0=a1_0x536618;this[_0x52a5f0(0xd9)]();}[a1_0x536618(0xd9)](){const _0x48973d=a1_0x536618;this[_0x48973d(0xbb)]&&(this[_0x48973d(0xbb)][_0x48973d(0xf8)](),this[_0x48973d(0xbb)]=null),this['dataChannel']&&(this['dataChannel'][_0x48973d(0xf8)](),this['dataChannel']=null),this[_0x48973d(0xac)]&&(this['audioStream'][_0x48973d(0xad)]()[_0x48973d(0xb9)](_0x4d9898=>_0x4d9898[_0x48973d(0xb7)]()),this[_0x48973d(0xac)]=null),this[_0x48973d(0xc2)]&&(this[_0x48973d(0xc2)]['disconnect'](),this['socket']=null),this['stopTimer'](),this[_0x48973d(0xbf)](_0x48973d(0xba));}async[a1_0x536618(0xd1)](){const _0x364ef6=a1_0x536618,_0x52f2eb=this['config'][_0x364ef6(0xce)]+_0x364ef6(0xf2),_0x1f03ac=await fetch(_0x52f2eb,{'method':'GET','headers':{'x-agrasya-client-api-key':this[_0x364ef6(0xa7)][_0x364ef6(0xf6)],'Content-Type':_0x364ef6(0xe2)}});if(!_0x1f03ac['ok']){const _0xeed24=await _0x1f03ac['json']()[_0x364ef6(0xa6)](()=>({'message':_0x1f03ac[_0x364ef6(0xd8)]}));throw new Error('Failed\x20to\x20fetch\x20minutes\x20usage:\x20'+(_0xeed24[_0x364ef6(0xe0)]||_0x1f03ac[_0x364ef6(0xd8)]));}const _0x16b1cf=await _0x1f03ac[_0x364ef6(0xfd)]();if(!_0x16b1cf[_0x364ef6(0xbe)])throw new Error(_0x16b1cf['message']||_0x364ef6(0xc7));return _0x16b1cf[_0x364ef6(0xeb)][_0x364ef6(0xf5)];}['cleanSDP'](_0x30c5c9){const _0x11939d=a1_0x536618,_0x1c2265=_0x30c5c9[_0x11939d(0xaf)]('\x0d\x0a'),_0x3a9911=new Set(),_0x47db0c=_0x1c2265[_0x11939d(0xdd)](_0x3aefdb=>{const _0x46427=_0x11939d;if(_0x3aefdb[_0x46427(0xae)](_0x46427(0xf7)))return![];if(_0x3aefdb[_0x46427(0xae)]('a=rtpmap')||_0x3aefdb['startsWith'](_0x46427(0xbd))){if(_0x3a9911['has'](_0x3aefdb))return![];_0x3a9911[_0x46427(0xa8)](_0x3aefdb);}return!![];});return _0x47db0c[_0x11939d(0xcc)]('\x0d\x0a');}};function a1_0x46ed(_0xfd4de9,_0x1ffda8){_0xfd4de9=_0xfd4de9-0xa6;const _0x24ab7a=a1_0x24ab();let _0x46edf9=_0x24ab7a[_0xfd4de9];return _0x46edf9;}export{AgrasyaVoiceSDK};
1
+ const a1_0xd67632=a1_0x3674;function a1_0x3674(_0x586bd0,_0x57f272){_0x586bd0=_0x586bd0-0xc8;const _0x58bdf1=a1_0x58bd();let _0x3674e0=_0x58bdf1[_0x586bd0];return _0x3674e0;}(function(_0x43f1dd,_0x1230f8){const _0x541ad9=a1_0x3674,_0x108127=_0x43f1dd();while(!![]){try{const _0x20c679=parseInt(_0x541ad9(0xd1))/0x1*(parseInt(_0x541ad9(0xcb))/0x2)+-parseInt(_0x541ad9(0x10f))/0x3+-parseInt(_0x541ad9(0x121))/0x4*(parseInt(_0x541ad9(0xe8))/0x5)+-parseInt(_0x541ad9(0xf1))/0x6*(-parseInt(_0x541ad9(0xd2))/0x7)+-parseInt(_0x541ad9(0xd5))/0x8+-parseInt(_0x541ad9(0x106))/0x9*(-parseInt(_0x541ad9(0x11c))/0xa)+parseInt(_0x541ad9(0xe6))/0xb;if(_0x20c679===_0x1230f8)break;else _0x108127['push'](_0x108127['shift']());}catch(_0x455b83){_0x108127['push'](_0x108127['shift']());}}}(a1_0x58bd,0x443e6));function a1_0x58bd(){const _0xd6b02e=['json','catch','socket','sdp','callDuration','cleanSDP','2334dbapzq','srcObject','setRemoteDescription','onCallDurationUpdate','body','apiKey','374inHcLF','2916809TUCmhL','cleanup','GET','614176AElPWe','message','stopTimer','startsWith','setStatus','language','oai-events','createOffer','join','idle','session_ended','startTimer','stringify','has','sessionId','/v1/agrasya/client-token?language=','filter','890494uAWCKM','audio','359915hkfbMP','createDataChannel','statusText','DataUrl','Backend\x20initialization\x20failed','startVoiceSession','audioStream','initializeBackendSession','parse','6ELJabR','POST','key\x20is\x20null\x20or\x20undefined.','disconnect','getUserMedia','setupSocketListeners','onmessage','log','/v1/agrasya/usage','config','dataChannel','durationInterval','Invalid\x20SDP\x20received:\x20Missing\x20or\x20malformed\x20\x27v=\x27\x20line.','onStatusChange','split','close','websocket','error','Cleaned\x20SDP:','v=0','o=-','153diRHar','minutesLeft','events','add','Response\x20from\x20/agrasya/connect:','getTracks','streams','success','Failed\x20to\x20initialize\x20session:\x20','1310619sJhXph','dataUrl','data','baseUrl','Failed\x20to\x20fetch\x20minutes\x20usage','fetchMinutesUsage','stop','model','Failed\x20to\x20fetch\x20minutes\x20usage:\x20','Minutes\x20left:\x20','mediaDevices','a=rtpmap','setupWebRTC','44130MigZth','peerConnection','[AgrasyaSDK]','stopVoiceSession','SDP\x20exchange\x20failed:\x20','12gMaDTv','application/json','initializing','ontrack','ephKey','/v1/agrasya/connect'];a1_0x58bd=function(){return _0xd6b02e;};return a1_0x58bd();}import a1_0x5412c5 from'socket.io-client';var AgrasyaVoiceSDK=class{[a1_0xd67632(0xfa)];['events'];['peerConnection']=null;['dataChannel']=null;[a1_0xd67632(0xee)]=null;[a1_0xd67632(0x129)]=null;[a1_0xd67632(0xe3)]=null;[a1_0xd67632(0x125)]=null;[a1_0xd67632(0x110)]=null;['model']=null;[a1_0xd67632(0xc9)]=0x0;[a1_0xd67632(0xfc)]=null;constructor(_0x21405c,_0x353c2b={}){const _0x14a617=a1_0xd67632;this[_0x14a617(0xfa)]={'baseUrl':'http://localhost:4001','language':'','debug':![],..._0x21405c},this[_0x14a617(0x108)]=_0x353c2b;}[a1_0xd67632(0xf8)](..._0x36d16d){const _0x48ab15=a1_0xd67632;this[_0x48ab15(0xfa)]['debug']&&console['log'](_0x48ab15(0x11e),..._0x36d16d);}['setStatus'](_0x480791){const _0x25c36b=a1_0xd67632;this[_0x25c36b(0x108)][_0x25c36b(0xfe)]?.(_0x480791);}[a1_0xd67632(0xe0)](){const _0x2fcb0d=a1_0xd67632;this[_0x2fcb0d(0xc9)]=0x0,this[_0x2fcb0d(0xfc)]=setInterval(()=>{const _0x20e301=_0x2fcb0d;this['callDuration']+=0x1,this['events'][_0x20e301(0xce)]?.(this['callDuration']);},0x3e8);}[a1_0xd67632(0xd7)](){const _0xf69e74=a1_0xd67632;this[_0xf69e74(0xfc)]&&(clearInterval(this[_0xf69e74(0xfc)]),this[_0xf69e74(0xfc)]=null);}async[a1_0xd67632(0xef)](){const _0x4c716f=a1_0xd67632,_0x45b0d3=this[_0x4c716f(0xfa)][_0x4c716f(0x112)]+_0x4c716f(0xe4)+this['config'][_0x4c716f(0xda)],_0xb6e633=await fetch(_0x45b0d3,{'method':_0x4c716f(0xd4),'headers':{'x-agrasya-client-api-key':this[_0x4c716f(0xfa)][_0x4c716f(0xd0)],'Content-Type':'application/json'}});if(!_0xb6e633['ok']){const _0x1c22e6=await _0xb6e633[_0x4c716f(0x127)]()['catch'](()=>({'message':_0xb6e633[_0x4c716f(0xea)]}));throw new Error(_0x4c716f(0x10e)+(_0x1c22e6['message']||_0xb6e633['statusText']));}const _0x4ce9d8=await _0xb6e633['json']();if(!_0x4ce9d8['success'])throw new Error(_0x4ce9d8['message']||_0x4c716f(0xec));return this[_0x4c716f(0x110)]=_0x4ce9d8[_0x4c716f(0x111)][_0x4c716f(0xeb)],this[_0x4c716f(0x116)]=_0x4ce9d8[_0x4c716f(0x111)]['model'],_0x4ce9d8[_0x4c716f(0x111)];}async[a1_0xd67632(0x11b)](_0x200811){const _0x44ba61=a1_0xd67632;this[_0x44ba61(0x11d)]=new RTCPeerConnection(),this['dataChannel']=this[_0x44ba61(0x11d)][_0x44ba61(0xe9)](_0x44ba61(0xdb));this[_0x44ba61(0xfb)]&&(this['dataChannel'][_0x44ba61(0xf7)]=_0x208bc2=>{const _0x5ceeb4=_0x44ba61,_0x460471=JSON[_0x5ceeb4(0xf0)](_0x208bc2[_0x5ceeb4(0x111)]);this[_0x5ceeb4(0x108)]['onTranscript']?.(_0x460471);});this['peerConnection'][_0x44ba61(0x124)]=_0x548247=>{const _0x54dab7=_0x44ba61,_0x4f7ddd=document['createElement'](_0x54dab7(0xe7));_0x4f7ddd[_0x54dab7(0xcc)]=_0x548247[_0x54dab7(0x10c)][0x0],_0x4f7ddd['autoplay']=!![],document[_0x54dab7(0xcf)]['appendChild'](_0x4f7ddd);},this['audioStream']=await navigator[_0x44ba61(0x119)][_0x44ba61(0xf5)]({'audio':!![]});if(this[_0x44ba61(0xee)]){const _0x3f37a6=this['audioStream'][_0x44ba61(0x10b)]()[0x0];this[_0x44ba61(0x11d)]['addTrack'](_0x3f37a6,this[_0x44ba61(0xee)]);}const _0x548bd8=await this['peerConnection'][_0x44ba61(0xdc)]();await this[_0x44ba61(0x11d)]['setLocalDescription'](_0x548bd8);const _0xe42d45=this[_0x44ba61(0xfa)][_0x44ba61(0x112)]+_0x44ba61(0x126),_0x30a9e1=await fetch(_0xe42d45,{'method':_0x44ba61(0xf2),'body':JSON[_0x44ba61(0xe1)]({'sessionId':this[_0x44ba61(0xe3)],'sdp':_0x548bd8[_0x44ba61(0xc8)],'model':this[_0x44ba61(0x116)]}),'headers':{'x-agrasya-client-api-key':this[_0x44ba61(0xfa)][_0x44ba61(0xd0)],'Content-Type':_0x44ba61(0x122)}});if(!_0x30a9e1['ok']){const _0x4324dd=await _0x30a9e1[_0x44ba61(0x127)]()['catch'](()=>({'message':_0x30a9e1[_0x44ba61(0xea)]}));throw new Error(_0x44ba61(0x120)+(_0x4324dd['message']||_0x30a9e1[_0x44ba61(0xea)]));}const _0x401002=await _0x30a9e1[_0x44ba61(0x127)]();this[_0x44ba61(0xf8)](_0x44ba61(0x10a),_0x401002);let _0x3255c2=_0x401002['sdp'];_0x3255c2=this[_0x44ba61(0xca)](_0x3255c2);if(!_0x3255c2[_0x44ba61(0xd8)](_0x44ba61(0x104)))throw new Error(_0x44ba61(0xfd));this[_0x44ba61(0xf8)](_0x44ba61(0x103),_0x3255c2);const _0x1f3daa={'type':'answer','sdp':_0x3255c2};await this['peerConnection'][_0x44ba61(0xcd)](_0x1f3daa);}['setupSocketListeners'](_0x32fe2c){const _0x6cf36=a1_0xd67632;_0x32fe2c['on'](_0x6cf36(0xf4),()=>{this['cleanup']();}),_0x32fe2c['on'](_0x6cf36(0xdf),()=>{this['cleanup']();});}async[a1_0xd67632(0xed)](_0x5924e5){const _0x1fb8c2=a1_0xd67632;try{this['setStatus'](_0x1fb8c2(0x123));const _0x2482b3=await this['initializeBackendSession']();this[_0x1fb8c2(0xe3)]=_0x2482b3[_0x1fb8c2(0xe3)],this[_0x1fb8c2(0x125)]=_0x2482b3[_0x1fb8c2(0x125)];if(!this['ephKey'])throw new Error(_0x1fb8c2(0xf3));const _0x25db82=await this[_0x1fb8c2(0x114)]();this[_0x1fb8c2(0xf8)](_0x1fb8c2(0x118)+_0x25db82),await this['setupWebRTC'](this[_0x1fb8c2(0x125)]),this[_0x1fb8c2(0x129)]=a1_0x5412c5(this[_0x1fb8c2(0xfa)]['baseUrl'],{'transports':[_0x1fb8c2(0x101)]}),this[_0x1fb8c2(0x129)]['emit']('join_session',{'sessionId':this['sessionId']}),this[_0x1fb8c2(0xf6)](this[_0x1fb8c2(0x129)]),this[_0x1fb8c2(0xd9)]('connected'),this[_0x1fb8c2(0xe0)]();}catch(_0x4f2622){this[_0x1fb8c2(0xd9)](_0x1fb8c2(0x102));throw _0x4f2622;}}async[a1_0xd67632(0x11f)](){const _0x49d3ec=a1_0xd67632;this[_0x49d3ec(0xd3)]();}[a1_0xd67632(0xd3)](){const _0x4a6c92=a1_0xd67632;this['peerConnection']&&(this['peerConnection']['close'](),this[_0x4a6c92(0x11d)]=null),this[_0x4a6c92(0xfb)]&&(this['dataChannel'][_0x4a6c92(0x100)](),this[_0x4a6c92(0xfb)]=null),this['audioStream']&&(this[_0x4a6c92(0xee)]['getTracks']()['forEach'](_0x3a1253=>_0x3a1253[_0x4a6c92(0x115)]()),this[_0x4a6c92(0xee)]=null),this[_0x4a6c92(0x129)]&&(this[_0x4a6c92(0x129)][_0x4a6c92(0xf4)](),this[_0x4a6c92(0x129)]=null),this['stopTimer'](),this[_0x4a6c92(0xd9)](_0x4a6c92(0xde));}async['fetchMinutesUsage'](){const _0x1e45fe=a1_0xd67632,_0x122103=this[_0x1e45fe(0xfa)]['baseUrl']+_0x1e45fe(0xf9),_0x529f18=await fetch(_0x122103,{'method':_0x1e45fe(0xd4),'headers':{'x-agrasya-client-api-key':this[_0x1e45fe(0xfa)][_0x1e45fe(0xd0)],'Content-Type':'application/json'}});if(!_0x529f18['ok']){const _0x4c4080=await _0x529f18[_0x1e45fe(0x127)]()[_0x1e45fe(0x128)](()=>({'message':_0x529f18[_0x1e45fe(0xea)]}));throw new Error(_0x1e45fe(0x117)+(_0x4c4080['message']||_0x529f18[_0x1e45fe(0xea)]));}const _0xf4371f=await _0x529f18[_0x1e45fe(0x127)]();if(!_0xf4371f[_0x1e45fe(0x10d)])throw new Error(_0xf4371f[_0x1e45fe(0xd6)]||_0x1e45fe(0x113));return _0xf4371f[_0x1e45fe(0x111)][_0x1e45fe(0x107)];}[a1_0xd67632(0xca)](_0xc7bff3){const _0x5a0b78=a1_0xd67632,_0x379282=_0xc7bff3[_0x5a0b78(0xff)]('\x0d\x0a'),_0x3e953d=new Set(),_0x65eedb=_0x379282[_0x5a0b78(0xe5)](_0x256956=>{const _0x1ce09a=_0x5a0b78;if(_0x256956['startsWith'](_0x1ce09a(0x105)))return![];if(_0x256956['startsWith'](_0x1ce09a(0x11a))||_0x256956[_0x1ce09a(0xd8)]('a=fmtp')){if(_0x3e953d[_0x1ce09a(0xe2)](_0x256956))return![];_0x3e953d[_0x1ce09a(0x109)](_0x256956);}return!![];});return _0x65eedb[_0x5a0b78(0xdd)]('\x0d\x0a');}};export{AgrasyaVoiceSDK};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrasya-voice-sdk",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",