agrasya-voice-sdk 1.0.34 → 1.0.35

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/README.md CHANGED
@@ -33,6 +33,56 @@ const events = {
33
33
  const sdkWithEvents = new AgrasyaVoiceSDK({ apiKey: "your-api-key" }, events);
34
34
  ```
35
35
 
36
+ ## Methods
37
+
38
+ ### Constructor
39
+
40
+ ```typescript
41
+ constructor(config: AgrasyaSDKConfig, events: AgrasyaEvents = {});
42
+ ```
43
+
44
+ Initializes the SDK with the provided configuration and optional event handlers.
45
+
46
+ ### start()
47
+
48
+ ```typescript
49
+ async start(): Promise<void>
50
+ ```
51
+
52
+ Starts a voice session by establishing a connection with the backend and initializing WebRTC components.
53
+
54
+ ### stop()
55
+
56
+ ```typescript
57
+ async stop(): Promise<void>
58
+ ```
59
+
60
+ Stops the voice session, closes the WebRTC connection, and cleans up resources.
61
+
62
+ ### sendMessage()
63
+
64
+ ```typescript
65
+ sendMessage(message: string): void
66
+ ```
67
+
68
+ Sends a message through the data channel.
69
+
70
+ ### onStatusChange
71
+
72
+ ```typescript
73
+ onStatusChange(status: "idle" | "initializing" | "connecting" | "connected" | "error"): void
74
+ ```
75
+
76
+ Event handler for status changes.
77
+
78
+ ### onMessageReceived
79
+
80
+ ```typescript
81
+ onMessageReceived(message: string): void
82
+ ```
83
+
84
+ Event handler for incoming messages.
85
+
36
86
  ## Development
37
87
 
38
88
  ```bash
@@ -47,9 +97,6 @@ npm run dev
47
97
 
48
98
  # Run tests
49
99
  npm test
50
-
51
- # Run linting
52
- npm run lint
53
100
  ```
54
101
 
55
102
  ## Publishing
package/dist/index.d.mts CHANGED
@@ -32,6 +32,11 @@ interface AgrasyaEvents {
32
32
  onStatusChange?: (status: "idle" | "initializing" | "connecting" | "connected" | "error") => void;
33
33
  /** Emitted when the call duration updates */
34
34
  onCallDurationUpdate?: (duration: number) => void;
35
+ /** Emitted when the user's usage limit is reached */
36
+ onUsageLimitReached?: (data: {
37
+ success: boolean;
38
+ message: string;
39
+ }) => void;
35
40
  }
36
41
 
37
42
  /**
package/dist/index.d.ts CHANGED
@@ -32,6 +32,11 @@ interface AgrasyaEvents {
32
32
  onStatusChange?: (status: "idle" | "initializing" | "connecting" | "connected" | "error") => void;
33
33
  /** Emitted when the call duration updates */
34
34
  onCallDurationUpdate?: (duration: number) => void;
35
+ /** Emitted when the user's usage limit is reached */
36
+ onUsageLimitReached?: (data: {
37
+ success: boolean;
38
+ message: string;
39
+ }) => void;
35
40
  }
36
41
 
37
42
  /**
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';const a0_0x1ff248=a0_0x2f49;(function(_0x20a3b0,_0x3ffa6b){const _0x3c743d=a0_0x2f49,_0x29faff=_0x20a3b0();while(!![]){try{const _0x1a315a=-parseInt(_0x3c743d(0xca))/0x1*(parseInt(_0x3c743d(0xa0))/0x2)+parseInt(_0x3c743d(0xb6))/0x3+parseInt(_0x3c743d(0x85))/0x4*(parseInt(_0x3c743d(0xa2))/0x5)+parseInt(_0x3c743d(0x8f))/0x6*(-parseInt(_0x3c743d(0xa5))/0x7)+parseInt(_0x3c743d(0xd0))/0x8*(parseInt(_0x3c743d(0xb4))/0x9)+-parseInt(_0x3c743d(0x77))/0xa+-parseInt(_0x3c743d(0xc0))/0xb*(-parseInt(_0x3c743d(0xbe))/0xc);if(_0x1a315a===_0x3ffa6b)break;else _0x29faff['push'](_0x29faff['shift']());}catch(_0x10df87){_0x29faff['push'](_0x29faff['shift']());}}}(a0_0x1f99,0x9f441));function a0_0x2f49(_0x4f4c8d,_0x135501){_0x4f4c8d=_0x4f4c8d-0x73;const _0x1f99fa=a0_0x1f99();let _0x2f491a=_0x1f99fa[_0x4f4c8d];return _0x2f491a;}var __create=Object[a0_0x1ff248(0x8b)],__defProp=Object[a0_0x1ff248(0xcc)],__getOwnPropDesc=Object[a0_0x1ff248(0x9f)],__getOwnPropNames=Object['getOwnPropertyNames'],__getProtoOf=Object[a0_0x1ff248(0x83)],__hasOwnProp=Object[a0_0x1ff248(0xa3)]['hasOwnProperty'],__export=(_0x501bb5,_0x16146a)=>{for(var _0x289cf4 in _0x16146a)__defProp(_0x501bb5,_0x289cf4,{'get':_0x16146a[_0x289cf4],'enumerable':!![]});},__copyProps=(_0x154796,_0x1f50d2,_0x5536d8,_0x41ce3e)=>{const _0x4a748c=a0_0x1ff248;if(_0x1f50d2&&typeof _0x1f50d2===_0x4a748c(0x8d)||typeof _0x1f50d2===_0x4a748c(0xb8)){for(let _0x2bdb73 of __getOwnPropNames(_0x1f50d2))if(!__hasOwnProp[_0x4a748c(0xbb)](_0x154796,_0x2bdb73)&&_0x2bdb73!==_0x5536d8)__defProp(_0x154796,_0x2bdb73,{'get':()=>_0x1f50d2[_0x2bdb73],'enumerable':!(_0x41ce3e=__getOwnPropDesc(_0x1f50d2,_0x2bdb73))||_0x41ce3e['enumerable']});}return _0x154796;},__toESM=(_0x481e8b,_0xcb1016,_0x48ab3f)=>(_0x48ab3f=_0x481e8b!=null?__create(__getProtoOf(_0x481e8b)):{},__copyProps(_0xcb1016||!_0x481e8b||!_0x481e8b[a0_0x1ff248(0xa7)]?__defProp(_0x48ab3f,a0_0x1ff248(0xb9),{'value':_0x481e8b,'enumerable':!![]}):_0x48ab3f,_0x481e8b)),__toCommonJS=_0x3cca89=>__copyProps(__defProp({},a0_0x1ff248(0xa7),{'value':!![]}),_0x3cca89),index_exports={};function a0_0x1f99(){const _0x4b5f37=['application/json','cleanup','body','mediaDevices','Failed\x20to\x20initialize\x20session:\x20','setupWebRTC','18LLaCxz','initializing','2600271Xuqmxd','success','function','default','peerConnection','call','fetchMinutesUsage','events','12ZGQJhk','initializeBackendSession','7772831fAgLph','minutesLeft','close','idle','debug','getTracks','error','sdp','stopTimer','startVoiceSession','97YkESSJ','setStatus','defineProperty','connected','dataChannel','GET','1629056yTTkyA','config','log','Backend\x20initialization\x20failed','emit','5166050HsjFZW','onmessage','/v1/agrasya/connect','audio','session_ended','Minutes\x20left:\x20','socket.io-client','callDuration','disconnect','socket','ephKey','addTrack','getPrototypeOf','statusText','524012wIlluJ','baseUrl','/v1/agrasya/client-token?language=','forEach','audioStream','setLocalDescription','create','setRemoteDescription','object','onCallDurationUpdate','2896332qMuvig','exports','sessionId','srcObject','language','SDP\x20exchange\x20failed:\x20','getUserMedia','answer','setupSocketListeners','appendChild','message','catch','websocket','createDataChannel','model','durationInterval','getOwnPropertyDescriptor','14886ofNWvk','apiKey','15aLGKJs','prototype','ontrack','7zVKkwo','startTimer','__esModule','stop','createOffer','json','parse','data','stringify'];a0_0x1f99=function(){return _0x4b5f37;};return a0_0x1f99();}__export(index_exports,{'AgrasyaVoiceSDK':()=>AgrasyaVoiceSDK}),module[a0_0x1ff248(0x90)]=__toCommonJS(index_exports);var import_socket=__toESM(require(a0_0x1ff248(0x7d))),AgrasyaVoiceSDK=class{['config'];[a0_0x1ff248(0xbd)];['peerConnection']=null;['dataChannel']=null;[a0_0x1ff248(0x89)]=null;['socket']=null;[a0_0x1ff248(0x91)]=null;['ephKey']=null;['dataUrl']=null;[a0_0x1ff248(0x9d)]=null;[a0_0x1ff248(0x7e)]=0x0;['durationInterval']=null;constructor(_0x88fd03,_0x5c0fed={}){const _0x3896b6=a0_0x1ff248;this[_0x3896b6(0x73)]={'baseUrl':'http://localhost:4001','language':'','debug':![],..._0x88fd03},this['events']=_0x5c0fed;}[a0_0x1ff248(0x74)](..._0x30e3ee){const _0x23d357=a0_0x1ff248;this[_0x23d357(0x73)][_0x23d357(0xc4)]&&console[_0x23d357(0x74)]('[AgrasyaSDK]',..._0x30e3ee);}['setStatus'](_0xbf9460){const _0x4d4ad9=a0_0x1ff248;this[_0x4d4ad9(0xbd)]['onStatusChange']?.(_0xbf9460);}['startTimer'](){const _0x561c7d=a0_0x1ff248;this[_0x561c7d(0x7e)]=0x0,this[_0x561c7d(0x9e)]=setInterval(()=>{const _0xa449af=_0x561c7d;this['callDuration']+=0x1,this[_0xa449af(0xbd)][_0xa449af(0x8e)]?.(this['callDuration']);},0x3e8);}[a0_0x1ff248(0xc8)](){const _0x1ac606=a0_0x1ff248;this[_0x1ac606(0x9e)]&&(clearInterval(this[_0x1ac606(0x9e)]),this[_0x1ac606(0x9e)]=null);}async[a0_0x1ff248(0xbf)](){const _0x3fce5c=a0_0x1ff248,_0x26dab7=this[_0x3fce5c(0x73)]['baseUrl']+_0x3fce5c(0x87)+this[_0x3fce5c(0x73)][_0x3fce5c(0x93)],_0x3ccd0a=await fetch(_0x26dab7,{'method':_0x3fce5c(0xcf),'headers':{'x-agrasya-client-api-key':this[_0x3fce5c(0x73)][_0x3fce5c(0xa1)],'Content-Type':'application/json'}});if(!_0x3ccd0a['ok']){const _0x6de229=await _0x3ccd0a[_0x3fce5c(0xaa)]()[_0x3fce5c(0x9a)](()=>({'message':_0x3ccd0a[_0x3fce5c(0x84)]}));throw new Error(_0x3fce5c(0xb2)+(_0x6de229[_0x3fce5c(0x99)]||_0x3ccd0a[_0x3fce5c(0x84)]));}const _0x47eeb5=await _0x3ccd0a[_0x3fce5c(0xaa)]();if(!_0x47eeb5['success'])throw new Error(_0x47eeb5[_0x3fce5c(0x99)]||_0x3fce5c(0x75));return _0x47eeb5[_0x3fce5c(0xac)];}async[a0_0x1ff248(0xb3)](_0x352645){const _0x1359b1=a0_0x1ff248;this[_0x1359b1(0xba)]=new RTCPeerConnection(),this[_0x1359b1(0xce)]=this[_0x1359b1(0xba)][_0x1359b1(0x9c)]('oai-events');this[_0x1359b1(0xce)]&&(this[_0x1359b1(0xce)][_0x1359b1(0x78)]=_0x20b180=>{const _0x3774bc=_0x1359b1,_0xbc630a=JSON[_0x3774bc(0xab)](_0x20b180[_0x3774bc(0xac)]);this[_0x3774bc(0xbd)]['onTranscript']?.(_0xbc630a);});this[_0x1359b1(0xba)][_0x1359b1(0xa4)]=_0x3adc2f=>{const _0x44ec60=_0x1359b1,_0x5b0823=document['createElement'](_0x44ec60(0x7a));_0x5b0823[_0x44ec60(0x92)]=_0x3adc2f['streams'][0x0],_0x5b0823['autoplay']=!![],document[_0x44ec60(0xb0)][_0x44ec60(0x98)](_0x5b0823);},this[_0x1359b1(0x89)]=await navigator[_0x1359b1(0xb1)][_0x1359b1(0x95)]({'audio':!![]});if(this[_0x1359b1(0x89)]){const _0x3a4e5a=this[_0x1359b1(0x89)][_0x1359b1(0xc5)]()[0x0];this[_0x1359b1(0xba)][_0x1359b1(0x82)](_0x3a4e5a,this[_0x1359b1(0x89)]);}const _0x32d3fb=await this[_0x1359b1(0xba)][_0x1359b1(0xa9)]();await this[_0x1359b1(0xba)][_0x1359b1(0x8a)](_0x32d3fb);const _0x201f34=this[_0x1359b1(0x73)][_0x1359b1(0x86)]+_0x1359b1(0x79),_0x19c6b4=await fetch(_0x201f34,{'method':'POST','body':JSON[_0x1359b1(0xad)]({'sessionId':this['sessionId'],'sdp':_0x32d3fb['sdp']}),'headers':{'x-agrasya-client-api-key':this[_0x1359b1(0x73)][_0x1359b1(0xa1)],'Content-Type':_0x1359b1(0xae)}});if(!_0x19c6b4['ok'])throw new Error(_0x1359b1(0x94)+_0x19c6b4[_0x1359b1(0x84)]);const _0x2dbfaf=await _0x19c6b4['json'](),_0x3ddb8b=_0x2dbfaf['data'][_0x1359b1(0xc7)],_0x299531={'type':_0x1359b1(0x96),'sdp':_0x3ddb8b};await this[_0x1359b1(0xba)][_0x1359b1(0x8c)](_0x299531);}[a0_0x1ff248(0x97)](_0xa2b7fc){const _0x219cd7=a0_0x1ff248;_0xa2b7fc['on'](_0x219cd7(0x7f),()=>{this['cleanup']();}),_0xa2b7fc['on'](_0x219cd7(0x7b),()=>{this['cleanup']();});}async[a0_0x1ff248(0xc9)](_0x2e0006){const _0x39f487=a0_0x1ff248;try{this[_0x39f487(0xcb)](_0x39f487(0xb5));const _0x1c167c=await this['initializeBackendSession']();this[_0x39f487(0x91)]=_0x1c167c[_0x39f487(0x91)],this[_0x39f487(0x81)]=_0x1c167c['ephKey'];if(!this[_0x39f487(0x81)])throw new Error('key\x20is\x20null\x20or\x20undefined.');const _0x32bc41=await this[_0x39f487(0xbc)]();this[_0x39f487(0x74)](_0x39f487(0x7c)+_0x32bc41),await this[_0x39f487(0xb3)](this[_0x39f487(0x81)]),this[_0x39f487(0x80)]=(0x0,import_socket[_0x39f487(0xb9)])(this[_0x39f487(0x73)][_0x39f487(0x86)],{'transports':[_0x39f487(0x9b)]}),this[_0x39f487(0x80)][_0x39f487(0x76)]('join_session',{'sessionId':this[_0x39f487(0x91)]}),this[_0x39f487(0x97)](this[_0x39f487(0x80)]),this[_0x39f487(0xcb)](_0x39f487(0xcd)),this[_0x39f487(0xa6)]();}catch(_0x4e8c91){this[_0x39f487(0xcb)](_0x39f487(0xc6));throw _0x4e8c91;}}async['stopVoiceSession'](){const _0x185735=a0_0x1ff248;this[_0x185735(0xaf)]();}[a0_0x1ff248(0xaf)](){const _0x58c622=a0_0x1ff248;this['peerConnection']&&(this[_0x58c622(0xba)][_0x58c622(0xc2)](),this[_0x58c622(0xba)]=null),this['dataChannel']&&(this[_0x58c622(0xce)][_0x58c622(0xc2)](),this['dataChannel']=null),this['audioStream']&&(this[_0x58c622(0x89)]['getTracks']()[_0x58c622(0x88)](_0x1fe3a5=>_0x1fe3a5[_0x58c622(0xa8)]()),this['audioStream']=null),this['socket']&&(this[_0x58c622(0x80)][_0x58c622(0x7f)](),this[_0x58c622(0x80)]=null),this[_0x58c622(0xc8)](),this[_0x58c622(0xcb)](_0x58c622(0xc3));}async['fetchMinutesUsage'](){const _0x14fe4f=a0_0x1ff248,_0x8644b8=this[_0x14fe4f(0x73)][_0x14fe4f(0x86)]+'/v1/agrasya/usage',_0x308ad3=await fetch(_0x8644b8,{'method':_0x14fe4f(0xcf),'headers':{'x-agrasya-client-api-key':this[_0x14fe4f(0x73)][_0x14fe4f(0xa1)],'Content-Type':'application/json'}});if(!_0x308ad3['ok']){const _0x2d1976=await _0x308ad3[_0x14fe4f(0xaa)]()[_0x14fe4f(0x9a)](()=>({'message':_0x308ad3[_0x14fe4f(0x84)]}));throw new Error('Failed\x20to\x20fetch\x20minutes\x20usage:\x20'+(_0x2d1976['message']||_0x308ad3[_0x14fe4f(0x84)]));}const _0x3d5143=await _0x308ad3[_0x14fe4f(0xaa)]();if(!_0x3d5143[_0x14fe4f(0xb7)])throw new Error(_0x3d5143['message']||'Failed\x20to\x20fetch\x20minutes\x20usage');return _0x3d5143[_0x14fe4f(0xac)][_0x14fe4f(0xc1)];}};0x0&&(module['exports']={'AgrasyaVoiceSDK':AgrasyaVoiceSDK});
1
+ 'use strict';const a0_0x39dbfb=a0_0x1079;(function(_0x3dcbc2,_0x29d8c5){const _0x9244e=a0_0x1079,_0xe1cf1c=_0x3dcbc2();while(!![]){try{const _0x3a8dcd=-parseInt(_0x9244e(0x153))/0x1*(-parseInt(_0x9244e(0x16c))/0x2)+parseInt(_0x9244e(0x147))/0x3+-parseInt(_0x9244e(0x13d))/0x4+parseInt(_0x9244e(0x163))/0x5+parseInt(_0x9244e(0x134))/0x6+-parseInt(_0x9244e(0x16b))/0x7*(parseInt(_0x9244e(0x11e))/0x8)+-parseInt(_0x9244e(0x138))/0x9;if(_0x3a8dcd===_0x29d8c5)break;else _0xe1cf1c['push'](_0xe1cf1c['shift']());}catch(_0x17cac2){_0xe1cf1c['push'](_0xe1cf1c['shift']());}}}(a0_0x33b1,0xba685));function a0_0x1079(_0x81dc3f,_0x4edb73){_0x81dc3f=_0x81dc3f-0x115;const _0x33b145=a0_0x33b1();let _0x107910=_0x33b145[_0x81dc3f];return _0x107910;}var __create=Object['create'],__defProp=Object[a0_0x39dbfb(0x130)],__getOwnPropDesc=Object['getOwnPropertyDescriptor'],__getOwnPropNames=Object['getOwnPropertyNames'],__getProtoOf=Object[a0_0x39dbfb(0x149)],__hasOwnProp=Object[a0_0x39dbfb(0x12e)][a0_0x39dbfb(0x11f)],__export=(_0x54e6f0,_0x390849)=>{for(var _0x1c98cd in _0x390849)__defProp(_0x54e6f0,_0x1c98cd,{'get':_0x390849[_0x1c98cd],'enumerable':!![]});},__copyProps=(_0x233564,_0xc4fe84,_0x406175,_0x52ab44)=>{const _0x3f710c=a0_0x39dbfb;if(_0xc4fe84&&typeof _0xc4fe84===_0x3f710c(0x173)||typeof _0xc4fe84==='function'){for(let _0x111243 of __getOwnPropNames(_0xc4fe84))if(!__hasOwnProp['call'](_0x233564,_0x111243)&&_0x111243!==_0x406175)__defProp(_0x233564,_0x111243,{'get':()=>_0xc4fe84[_0x111243],'enumerable':!(_0x52ab44=__getOwnPropDesc(_0xc4fe84,_0x111243))||_0x52ab44[_0x3f710c(0x14f)]});}return _0x233564;},__toESM=(_0x104051,_0x4963ca,_0x5cd85e)=>(_0x5cd85e=_0x104051!=null?__create(__getProtoOf(_0x104051)):{},__copyProps(_0x4963ca||!_0x104051||!_0x104051[a0_0x39dbfb(0x14c)]?__defProp(_0x5cd85e,a0_0x39dbfb(0x145),{'value':_0x104051,'enumerable':!![]}):_0x5cd85e,_0x104051)),__toCommonJS=_0x46a37e=>__copyProps(__defProp({},a0_0x39dbfb(0x14c),{'value':!![]}),_0x46a37e),index_exports={};__export(index_exports,{'AgrasyaVoiceSDK':()=>AgrasyaVoiceSDK}),module[a0_0x39dbfb(0x152)]=__toCommonJS(index_exports);function a0_0x33b1(){const _0x5a8d63=['http://localhost:4001','mediaDevices','Failed\x20to\x20fetch\x20minutes\x20usage','onCallDurationUpdate','stop','baseUrl','77gmOxmF','596800IHOHRf','catch','setupSocketListeners','stopTimer','debug','oai-events','createElement','object','startVoiceSession','session_ended','setupWebRTC','Failed\x20to\x20initialize\x20session:\x20','onmessage','sdp','peerConnection','ontrack','setRemoteDescription','465584Hswaym','hasOwnProperty','initializeBackendSession','application/json','apiKey','durationInterval','callDuration','connected','socket.io-client','SDP\x20exchange\x20failed:\x20','json','audioStream','data','onStatusChange','dataUrl','update_start_time','prototype','body','defineProperty','usage_limit_reached','audio','model','3105882uFfaeb','stopVoiceSession','emit','idle','13690467ukzeul','statusText','error','disconnect','language','837408qSkLWy','key\x20is\x20null\x20or\x20undefined.','parse','cleanup','getUserMedia','dataChannel','stringify','events','default','close','3188370NBIWaU','createOffer','getPrototypeOf','success','srcObject','__esModule','config','createDataChannel','enumerable','fetchMinutesUsage','startTimer','exports','4gwIzHF','setStatus','Failed\x20to\x20fetch\x20minutes\x20usage:\x20','getTracks','/v1/agrasya/connect','ephKey','addTrack','/v1/agrasya/usage','log','message','socket','forEach','minutesLeft','/v1/agrasya/client-token?language=','websocket','sessionId','1800905kaLYDX','autoplay'];a0_0x33b1=function(){return _0x5a8d63;};return a0_0x33b1();}var import_socket=__toESM(require(a0_0x39dbfb(0x126))),AgrasyaVoiceSDK=class{[a0_0x39dbfb(0x14d)];[a0_0x39dbfb(0x144)];[a0_0x39dbfb(0x11b)]=null;[a0_0x39dbfb(0x142)]=null;[a0_0x39dbfb(0x129)]=null;[a0_0x39dbfb(0x15d)]=null;['sessionId']=null;[a0_0x39dbfb(0x158)]=null;[a0_0x39dbfb(0x12c)]=null;[a0_0x39dbfb(0x133)]=null;[a0_0x39dbfb(0x124)]=0x0;[a0_0x39dbfb(0x123)]=null;constructor(_0x31bcef,_0x293cad={}){const _0x4e5a0f=a0_0x39dbfb;this[_0x4e5a0f(0x14d)]={'baseUrl':_0x4e5a0f(0x165),'language':'','debug':![],..._0x31bcef},this[_0x4e5a0f(0x144)]=_0x293cad;}['log'](..._0x12d6d7){const _0x277725=a0_0x39dbfb;this['config'][_0x277725(0x170)]&&console[_0x277725(0x15b)]('[AgrasyaSDK]',..._0x12d6d7);}['setStatus'](_0x487266){const _0xa05fba=a0_0x39dbfb;this[_0xa05fba(0x144)][_0xa05fba(0x12b)]?.(_0x487266);}['startTimer'](){const _0x22bd7c=a0_0x39dbfb;this['callDuration']=0x0,this[_0x22bd7c(0x123)]=setInterval(()=>{const _0x4c1b9b=_0x22bd7c;this[_0x4c1b9b(0x124)]+=0x1,this[_0x4c1b9b(0x144)][_0x4c1b9b(0x168)]?.(this[_0x4c1b9b(0x124)]);},0x3e8);}[a0_0x39dbfb(0x16f)](){const _0x20c7f2=a0_0x39dbfb;this['durationInterval']&&(clearInterval(this['durationInterval']),this[_0x20c7f2(0x123)]=null);}async['initializeBackendSession'](){const _0x395c6b=a0_0x39dbfb,_0x3ccbaf=this[_0x395c6b(0x14d)][_0x395c6b(0x16a)]+_0x395c6b(0x160)+this[_0x395c6b(0x14d)][_0x395c6b(0x13c)],_0x3fde5b=await fetch(_0x3ccbaf,{'method':'GET','headers':{'x-agrasya-client-api-key':this[_0x395c6b(0x14d)][_0x395c6b(0x122)],'Content-Type':_0x395c6b(0x121)}});if(!_0x3fde5b['ok']){const _0x3b8da3=await _0x3fde5b[_0x395c6b(0x128)]()[_0x395c6b(0x16d)](()=>({'message':_0x3fde5b[_0x395c6b(0x139)]}));throw new Error(_0x395c6b(0x118)+(_0x3b8da3['message']||_0x3fde5b[_0x395c6b(0x139)]));}const _0x4107ff=await _0x3fde5b[_0x395c6b(0x128)]();if(!_0x4107ff['success'])throw new Error(_0x4107ff[_0x395c6b(0x15c)]||'Backend\x20initialization\x20failed');return _0x4107ff[_0x395c6b(0x12a)];}async[a0_0x39dbfb(0x117)](_0x52283a){const _0x471d42=a0_0x39dbfb;this[_0x471d42(0x11b)]=new RTCPeerConnection(),this[_0x471d42(0x142)]=this['peerConnection'][_0x471d42(0x14e)](_0x471d42(0x171));this[_0x471d42(0x142)]&&(this[_0x471d42(0x142)][_0x471d42(0x119)]=_0x348f5c=>{const _0x523c7b=_0x471d42,_0x23a188=JSON[_0x523c7b(0x13f)](_0x348f5c['data']);this[_0x523c7b(0x144)]['onTranscript']?.(_0x23a188);});this[_0x471d42(0x11b)][_0x471d42(0x11c)]=_0x4a4376=>{const _0x4e1825=_0x471d42,_0x21a897=document[_0x4e1825(0x172)](_0x4e1825(0x132));_0x21a897[_0x4e1825(0x14b)]=_0x4a4376['streams'][0x0],_0x21a897[_0x4e1825(0x164)]=!![],document[_0x4e1825(0x12f)]['appendChild'](_0x21a897);},this[_0x471d42(0x129)]=await navigator[_0x471d42(0x166)][_0x471d42(0x141)]({'audio':!![]});if(this[_0x471d42(0x129)]){const _0x233541=this['audioStream']['getTracks']()[0x0];this[_0x471d42(0x11b)][_0x471d42(0x159)](_0x233541,this[_0x471d42(0x129)]);}const _0x106d98=await this[_0x471d42(0x11b)][_0x471d42(0x148)]();await this[_0x471d42(0x11b)]['setLocalDescription'](_0x106d98);const _0x38b462=this[_0x471d42(0x14d)][_0x471d42(0x16a)]+_0x471d42(0x157),_0x161509=await fetch(_0x38b462,{'method':'POST','body':JSON[_0x471d42(0x143)]({'sessionId':this[_0x471d42(0x162)],'sdp':_0x106d98[_0x471d42(0x11a)]}),'headers':{'x-agrasya-client-api-key':this[_0x471d42(0x14d)]['apiKey'],'Content-Type':_0x471d42(0x121)}});if(!_0x161509['ok'])throw new Error(_0x471d42(0x127)+_0x161509[_0x471d42(0x139)]);const _0x22dcc6=await _0x161509[_0x471d42(0x128)](),_0xe1ef09=_0x22dcc6[_0x471d42(0x12a)][_0x471d42(0x11a)],_0x5a9b16={'type':'answer','sdp':_0xe1ef09};await this[_0x471d42(0x11b)][_0x471d42(0x11d)](_0x5a9b16);}[a0_0x39dbfb(0x16e)](_0x165faa){const _0xd7ad51=a0_0x39dbfb;_0x165faa['on']('disconnect',()=>{const _0x22142f=a0_0x1079;this[_0x22142f(0x140)]();}),_0x165faa['on'](_0xd7ad51(0x116),()=>{const _0x30ef0f=_0xd7ad51;this[_0x30ef0f(0x140)]();}),_0x165faa['on'](_0xd7ad51(0x131),_0x42beaa=>{this['events']['onUsageLimitReached']?.(_0x42beaa);});}async[a0_0x39dbfb(0x115)](_0x15e45b){const _0x2cd1dc=a0_0x39dbfb;try{this['setStatus']('initializing');const _0x1cc4d2=await this[_0x2cd1dc(0x120)]();this[_0x2cd1dc(0x162)]=_0x1cc4d2[_0x2cd1dc(0x162)],this['ephKey']=_0x1cc4d2[_0x2cd1dc(0x158)];if(!this[_0x2cd1dc(0x158)])throw new Error(_0x2cd1dc(0x13e));const _0x3c335b=await this[_0x2cd1dc(0x150)]();this[_0x2cd1dc(0x15b)]('Minutes\x20left:\x20'+_0x3c335b),await this[_0x2cd1dc(0x117)](this[_0x2cd1dc(0x158)]),this[_0x2cd1dc(0x15d)]=(0x0,import_socket[_0x2cd1dc(0x145)])(this[_0x2cd1dc(0x14d)]['baseUrl'],{'transports':[_0x2cd1dc(0x161)]}),this[_0x2cd1dc(0x15d)][_0x2cd1dc(0x136)]('join_session',{'sessionId':this['sessionId']}),this[_0x2cd1dc(0x15d)][_0x2cd1dc(0x136)](_0x2cd1dc(0x12d)),this['setupSocketListeners'](this['socket']),this[_0x2cd1dc(0x154)](_0x2cd1dc(0x125)),this[_0x2cd1dc(0x151)]();}catch(_0x5a8eca){this[_0x2cd1dc(0x154)](_0x2cd1dc(0x13a));throw _0x5a8eca;}}async[a0_0x39dbfb(0x135)](){this['cleanup']();}[a0_0x39dbfb(0x140)](){const _0x379c3f=a0_0x39dbfb;this[_0x379c3f(0x11b)]&&(this[_0x379c3f(0x11b)][_0x379c3f(0x146)](),this[_0x379c3f(0x11b)]=null),this[_0x379c3f(0x142)]&&(this[_0x379c3f(0x142)]['close'](),this[_0x379c3f(0x142)]=null),this['audioStream']&&(this[_0x379c3f(0x129)][_0x379c3f(0x156)]()[_0x379c3f(0x15e)](_0x1dc7e3=>_0x1dc7e3[_0x379c3f(0x169)]()),this['audioStream']=null),this[_0x379c3f(0x15d)]&&(this[_0x379c3f(0x15d)][_0x379c3f(0x13b)](),this[_0x379c3f(0x15d)]=null),this['stopTimer'](),this[_0x379c3f(0x154)](_0x379c3f(0x137));}async[a0_0x39dbfb(0x150)](){const _0x253473=a0_0x39dbfb,_0x3eb22e=this[_0x253473(0x14d)][_0x253473(0x16a)]+_0x253473(0x15a),_0x3c822b=await fetch(_0x3eb22e,{'method':'GET','headers':{'x-agrasya-client-api-key':this['config'][_0x253473(0x122)],'Content-Type':_0x253473(0x121)}});if(!_0x3c822b['ok']){const _0x442293=await _0x3c822b[_0x253473(0x128)]()[_0x253473(0x16d)](()=>({'message':_0x3c822b['statusText']}));throw new Error(_0x253473(0x155)+(_0x442293[_0x253473(0x15c)]||_0x3c822b[_0x253473(0x139)]));}const _0x4344c2=await _0x3c822b[_0x253473(0x128)]();if(!_0x4344c2[_0x253473(0x14a)])throw new Error(_0x4344c2[_0x253473(0x15c)]||_0x253473(0x167));return _0x4344c2[_0x253473(0x12a)][_0x253473(0x15f)];}};0x0&&(module[a0_0x39dbfb(0x152)]={'AgrasyaVoiceSDK':AgrasyaVoiceSDK});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const a1_0x10eb9d=a1_0x36f5;function a1_0x36f5(_0x57cc83,_0x4eed7b){_0x57cc83=_0x57cc83-0x18d;const _0x2e86b1=a1_0x2e86();let _0x36f5fb=_0x2e86b1[_0x57cc83];return _0x36f5fb;}(function(_0x19145e,_0x457c88){const _0x50db16=a1_0x36f5,_0x43fbbe=_0x19145e();while(!![]){try{const _0x262cb1=parseInt(_0x50db16(0x1c0))/0x1+-parseInt(_0x50db16(0x1d8))/0x2+-parseInt(_0x50db16(0x1cd))/0x3*(-parseInt(_0x50db16(0x1bd))/0x4)+-parseInt(_0x50db16(0x19a))/0x5*(parseInt(_0x50db16(0x1dc))/0x6)+parseInt(_0x50db16(0x1ca))/0x7+-parseInt(_0x50db16(0x1a2))/0x8*(parseInt(_0x50db16(0x1da))/0x9)+parseInt(_0x50db16(0x1a3))/0xa*(-parseInt(_0x50db16(0x1ac))/0xb);if(_0x262cb1===_0x457c88)break;else _0x43fbbe['push'](_0x43fbbe['shift']());}catch(_0x1c1b83){_0x43fbbe['push'](_0x43fbbe['shift']());}}}(a1_0x2e86,0x79e48));import a1_0x2e9fff from'socket.io-client';function a1_0x2e86(){const _0x58dd65=['SDP\x20exchange\x20failed:\x20','1431VGvrQB','http://localhost:4001','6ZtjSMe','stopTimer','statusText','setupWebRTC','cleanup','setRemoteDescription','peerConnection','[AgrasyaSDK]','sdp','onTranscript','srcObject','audioStream','emit','error','ephKey','getUserMedia','model','733765NZmfob','events','onmessage','mediaDevices','/v1/agrasya/usage','initializing','forEach','GET','49608umouKT','10ShsEbD','streams','/v1/agrasya/connect','join_session','catch','json','Failed\x20to\x20fetch\x20minutes\x20usage','success','data','1433839aSKRNn','language','setLocalDescription','session_ended','createElement','message','createOffer','appendChild','answer','minutesLeft','Backend\x20initialization\x20failed','parse','debug','fetchMinutesUsage','POST','dataUrl','startTimer','1254716nuTYPL','initializeBackendSession','audio','840928rhFqhR','connected','close','application/json','oai-events','log','apiKey','key\x20is\x20null\x20or\x20undefined.','socket','dataChannel','278782hwjnMK','onCallDurationUpdate','onStatusChange','9zkLzGL','setStatus','baseUrl','getTracks','sessionId','setupSocketListeners','durationInterval','Failed\x20to\x20initialize\x20session:\x20','config','callDuration','Minutes\x20left:\x20','118916VhYHeS'];a1_0x2e86=function(){return _0x58dd65;};return a1_0x2e86();}var AgrasyaVoiceSDK=class{[a1_0x10eb9d(0x1d5)];[a1_0x10eb9d(0x19b)];[a1_0x10eb9d(0x18f)]=null;[a1_0x10eb9d(0x1c9)]=null;[a1_0x10eb9d(0x194)]=null;[a1_0x10eb9d(0x1c8)]=null;[a1_0x10eb9d(0x1d1)]=null;[a1_0x10eb9d(0x197)]=null;[a1_0x10eb9d(0x1bb)]=null;[a1_0x10eb9d(0x199)]=null;[a1_0x10eb9d(0x1d6)]=0x0;['durationInterval']=null;constructor(_0x51c53a,_0x11182e={}){const _0x8dd2a4=a1_0x10eb9d;this[_0x8dd2a4(0x1d5)]={'baseUrl':_0x8dd2a4(0x1db),'language':'','debug':![],..._0x51c53a},this[_0x8dd2a4(0x19b)]=_0x11182e;}[a1_0x10eb9d(0x1c5)](..._0x42bed1){const _0x1fd153=a1_0x10eb9d;this['config'][_0x1fd153(0x1b8)]&&console[_0x1fd153(0x1c5)](_0x1fd153(0x190),..._0x42bed1);}[a1_0x10eb9d(0x1ce)](_0x4477cd){const _0x3511ff=a1_0x10eb9d;this[_0x3511ff(0x19b)][_0x3511ff(0x1cc)]?.(_0x4477cd);}[a1_0x10eb9d(0x1bc)](){const _0x19786a=a1_0x10eb9d;this[_0x19786a(0x1d6)]=0x0,this['durationInterval']=setInterval(()=>{const _0x4720d3=_0x19786a;this[_0x4720d3(0x1d6)]+=0x1,this[_0x4720d3(0x19b)][_0x4720d3(0x1cb)]?.(this[_0x4720d3(0x1d6)]);},0x3e8);}[a1_0x10eb9d(0x1dd)](){const _0x48d76a=a1_0x10eb9d;this[_0x48d76a(0x1d3)]&&(clearInterval(this[_0x48d76a(0x1d3)]),this[_0x48d76a(0x1d3)]=null);}async[a1_0x10eb9d(0x1be)](){const _0x47ff1c=a1_0x10eb9d,_0x4e579b=this['config'][_0x47ff1c(0x1cf)]+'/v1/agrasya/client-token?language='+this[_0x47ff1c(0x1d5)][_0x47ff1c(0x1ad)],_0x2d8a24=await fetch(_0x4e579b,{'method':'GET','headers':{'x-agrasya-client-api-key':this[_0x47ff1c(0x1d5)]['apiKey'],'Content-Type':_0x47ff1c(0x1c3)}});if(!_0x2d8a24['ok']){const _0xe70751=await _0x2d8a24[_0x47ff1c(0x1a8)]()[_0x47ff1c(0x1a7)](()=>({'message':_0x2d8a24['statusText']}));throw new Error(_0x47ff1c(0x1d4)+(_0xe70751['message']||_0x2d8a24[_0x47ff1c(0x1de)]));}const _0xb2d4a0=await _0x2d8a24[_0x47ff1c(0x1a8)]();if(!_0xb2d4a0[_0x47ff1c(0x1aa)])throw new Error(_0xb2d4a0[_0x47ff1c(0x1b1)]||_0x47ff1c(0x1b6));return _0xb2d4a0[_0x47ff1c(0x1ab)];}async[a1_0x10eb9d(0x1df)](_0xe6da4c){const _0x44b95b=a1_0x10eb9d;this[_0x44b95b(0x18f)]=new RTCPeerConnection(),this[_0x44b95b(0x1c9)]=this['peerConnection']['createDataChannel'](_0x44b95b(0x1c4));this['dataChannel']&&(this[_0x44b95b(0x1c9)][_0x44b95b(0x19c)]=_0x3751ef=>{const _0xb16233=_0x44b95b,_0x575022=JSON[_0xb16233(0x1b7)](_0x3751ef['data']);this[_0xb16233(0x19b)][_0xb16233(0x192)]?.(_0x575022);});this[_0x44b95b(0x18f)]['ontrack']=_0x82a043=>{const _0x20628a=_0x44b95b,_0x48f497=document[_0x20628a(0x1b0)](_0x20628a(0x1bf));_0x48f497[_0x20628a(0x193)]=_0x82a043[_0x20628a(0x1a4)][0x0],_0x48f497['autoplay']=!![],document['body'][_0x20628a(0x1b3)](_0x48f497);},this[_0x44b95b(0x194)]=await navigator[_0x44b95b(0x19d)][_0x44b95b(0x198)]({'audio':!![]});if(this['audioStream']){const _0x2cf0ee=this[_0x44b95b(0x194)][_0x44b95b(0x1d0)]()[0x0];this['peerConnection']['addTrack'](_0x2cf0ee,this['audioStream']);}const _0x38cff8=await this[_0x44b95b(0x18f)][_0x44b95b(0x1b2)]();await this[_0x44b95b(0x18f)][_0x44b95b(0x1ae)](_0x38cff8);const _0x50570=this['config'][_0x44b95b(0x1cf)]+_0x44b95b(0x1a5),_0x48ed03=await fetch(_0x50570,{'method':_0x44b95b(0x1ba),'body':JSON['stringify']({'sessionId':this[_0x44b95b(0x1d1)],'sdp':_0x38cff8['sdp']}),'headers':{'x-agrasya-client-api-key':this['config'][_0x44b95b(0x1c6)],'Content-Type':_0x44b95b(0x1c3)}});if(!_0x48ed03['ok'])throw new Error(_0x44b95b(0x1d9)+_0x48ed03[_0x44b95b(0x1de)]);const _0x5d3362=await _0x48ed03[_0x44b95b(0x1a8)](),_0x425cb1=_0x5d3362['data'][_0x44b95b(0x191)],_0x1f03fd={'type':_0x44b95b(0x1b4),'sdp':_0x425cb1};await this[_0x44b95b(0x18f)][_0x44b95b(0x18e)](_0x1f03fd);}[a1_0x10eb9d(0x1d2)](_0x47d7df){const _0x364aab=a1_0x10eb9d;_0x47d7df['on']('disconnect',()=>{this['cleanup']();}),_0x47d7df['on'](_0x364aab(0x1af),()=>{const _0xe9cc21=_0x364aab;this[_0xe9cc21(0x18d)]();});}async['startVoiceSession'](_0x310447){const _0x56fd3b=a1_0x10eb9d;try{this[_0x56fd3b(0x1ce)](_0x56fd3b(0x19f));const _0x28949b=await this[_0x56fd3b(0x1be)]();this['sessionId']=_0x28949b[_0x56fd3b(0x1d1)],this[_0x56fd3b(0x197)]=_0x28949b[_0x56fd3b(0x197)];if(!this[_0x56fd3b(0x197)])throw new Error(_0x56fd3b(0x1c7));const _0x5136ed=await this[_0x56fd3b(0x1b9)]();this[_0x56fd3b(0x1c5)](_0x56fd3b(0x1d7)+_0x5136ed),await this[_0x56fd3b(0x1df)](this[_0x56fd3b(0x197)]),this[_0x56fd3b(0x1c8)]=a1_0x2e9fff(this[_0x56fd3b(0x1d5)]['baseUrl'],{'transports':['websocket']}),this['socket'][_0x56fd3b(0x195)](_0x56fd3b(0x1a6),{'sessionId':this[_0x56fd3b(0x1d1)]}),this[_0x56fd3b(0x1d2)](this[_0x56fd3b(0x1c8)]),this[_0x56fd3b(0x1ce)](_0x56fd3b(0x1c1)),this[_0x56fd3b(0x1bc)]();}catch(_0x2953b6){this[_0x56fd3b(0x1ce)](_0x56fd3b(0x196));throw _0x2953b6;}}async['stopVoiceSession'](){this['cleanup']();}['cleanup'](){const _0xa02172=a1_0x10eb9d;this[_0xa02172(0x18f)]&&(this[_0xa02172(0x18f)][_0xa02172(0x1c2)](),this[_0xa02172(0x18f)]=null),this[_0xa02172(0x1c9)]&&(this[_0xa02172(0x1c9)][_0xa02172(0x1c2)](),this[_0xa02172(0x1c9)]=null),this[_0xa02172(0x194)]&&(this[_0xa02172(0x194)][_0xa02172(0x1d0)]()[_0xa02172(0x1a0)](_0x52a399=>_0x52a399['stop']()),this['audioStream']=null),this[_0xa02172(0x1c8)]&&(this[_0xa02172(0x1c8)]['disconnect'](),this[_0xa02172(0x1c8)]=null),this['stopTimer'](),this[_0xa02172(0x1ce)]('idle');}async['fetchMinutesUsage'](){const _0x4ec69e=a1_0x10eb9d,_0x5f4a0e=this[_0x4ec69e(0x1d5)][_0x4ec69e(0x1cf)]+_0x4ec69e(0x19e),_0xb70b88=await fetch(_0x5f4a0e,{'method':_0x4ec69e(0x1a1),'headers':{'x-agrasya-client-api-key':this['config'][_0x4ec69e(0x1c6)],'Content-Type':_0x4ec69e(0x1c3)}});if(!_0xb70b88['ok']){const _0x84476a=await _0xb70b88[_0x4ec69e(0x1a8)]()[_0x4ec69e(0x1a7)](()=>({'message':_0xb70b88[_0x4ec69e(0x1de)]}));throw new Error('Failed\x20to\x20fetch\x20minutes\x20usage:\x20'+(_0x84476a[_0x4ec69e(0x1b1)]||_0xb70b88[_0x4ec69e(0x1de)]));}const _0x19f5f6=await _0xb70b88[_0x4ec69e(0x1a8)]();if(!_0x19f5f6['success'])throw new Error(_0x19f5f6[_0x4ec69e(0x1b1)]||_0x4ec69e(0x1a9));return _0x19f5f6['data'][_0x4ec69e(0x1b5)];}};export{AgrasyaVoiceSDK};
1
+ const a1_0x4c6459=a1_0x2ac9;(function(_0x1813fe,_0x385a70){const _0x53e059=a1_0x2ac9,_0x33d500=_0x1813fe();while(!![]){try{const _0x27a249=parseInt(_0x53e059(0x120))/0x1+-parseInt(_0x53e059(0x150))/0x2*(-parseInt(_0x53e059(0x15b))/0x3)+parseInt(_0x53e059(0x12f))/0x4*(-parseInt(_0x53e059(0x119))/0x5)+-parseInt(_0x53e059(0x116))/0x6+-parseInt(_0x53e059(0x14d))/0x7*(parseInt(_0x53e059(0x14f))/0x8)+-parseInt(_0x53e059(0x145))/0x9+-parseInt(_0x53e059(0x134))/0xa*(-parseInt(_0x53e059(0x160))/0xb);if(_0x27a249===_0x385a70)break;else _0x33d500['push'](_0x33d500['shift']());}catch(_0x12dd38){_0x33d500['push'](_0x33d500['shift']());}}}(a1_0x5e82,0x7aeda));function a1_0x5e82(){const _0x217878=['Failed\x20to\x20fetch\x20minutes\x20usage:\x20','idle','[AgrasyaSDK]','audioStream','2321431HMIfDV','onUsageLimitReached','16dzSgvb','18lnLEPV','SDP\x20exchange\x20failed:\x20','Minutes\x20left:\x20','message','GET','forEach','error','sdp','emit','parse','getUserMedia','210054IsPhWI','Failed\x20to\x20fetch\x20minutes\x20usage','setStatus','createOffer','initializing','150502GQryfq','createDataChannel','update_start_time','socket','success','events','onStatusChange','292362DLTLRQ','fetchMinutesUsage','audio','170vHpICG','body','streams','sessionId','close','getTracks','POST','815912VWqhQM','http://localhost:4001','minutesLeft','config','dataChannel','connected','setRemoteDescription','json','callDuration','statusText','ephKey','startTimer','disconnect','autoplay','session_ended','21776uXwDdL','apiKey','mediaDevices','stopTimer','data','670erBarH','application/json','cleanup','durationInterval','setupSocketListeners','catch','Backend\x20initialization\x20failed','/v1/agrasya/usage','onmessage','model','baseUrl','peerConnection','/v1/agrasya/client-token?language=','websocket','oai-events','startVoiceSession','log','8659485uEKaYB','setLocalDescription','stop','language'];a1_0x5e82=function(){return _0x217878;};return a1_0x5e82();}import a1_0x5382ae from'socket.io-client';var AgrasyaVoiceSDK=class{[a1_0x4c6459(0x123)];['events'];['peerConnection']=null;['dataChannel']=null;['audioStream']=null;[a1_0x4c6459(0x163)]=null;[a1_0x4c6459(0x11c)]=null;[a1_0x4c6459(0x12a)]=null;['dataUrl']=null;[a1_0x4c6459(0x13d)]=null;['callDuration']=0x0;[a1_0x4c6459(0x137)]=null;constructor(_0x231307,_0x44ab09={}){const _0x534e3f=a1_0x4c6459;this[_0x534e3f(0x123)]={'baseUrl':_0x534e3f(0x121),'language':'','debug':![],..._0x231307},this[_0x534e3f(0x114)]=_0x44ab09;}['log'](..._0x26eb41){const _0x407cce=a1_0x4c6459;this[_0x407cce(0x123)]['debug']&&console[_0x407cce(0x144)](_0x407cce(0x14b),..._0x26eb41);}[a1_0x4c6459(0x15d)](_0x53fb86){const _0x24e91a=a1_0x4c6459;this[_0x24e91a(0x114)][_0x24e91a(0x115)]?.(_0x53fb86);}[a1_0x4c6459(0x12b)](){const _0x4483c6=a1_0x4c6459;this['callDuration']=0x0,this[_0x4483c6(0x137)]=setInterval(()=>{const _0xc93a6b=_0x4483c6;this[_0xc93a6b(0x128)]+=0x1,this[_0xc93a6b(0x114)]['onCallDurationUpdate']?.(this[_0xc93a6b(0x128)]);},0x3e8);}[a1_0x4c6459(0x132)](){const _0x1fad97=a1_0x4c6459;this[_0x1fad97(0x137)]&&(clearInterval(this[_0x1fad97(0x137)]),this[_0x1fad97(0x137)]=null);}async['initializeBackendSession'](){const _0x2a3ad6=a1_0x4c6459,_0x20f07c=this[_0x2a3ad6(0x123)]['baseUrl']+_0x2a3ad6(0x140)+this['config'][_0x2a3ad6(0x148)],_0x2ad278=await fetch(_0x20f07c,{'method':'GET','headers':{'x-agrasya-client-api-key':this[_0x2a3ad6(0x123)]['apiKey'],'Content-Type':_0x2a3ad6(0x135)}});if(!_0x2ad278['ok']){const _0x1a5cb7=await _0x2ad278[_0x2a3ad6(0x127)]()[_0x2a3ad6(0x139)](()=>({'message':_0x2ad278[_0x2a3ad6(0x129)]}));throw new Error('Failed\x20to\x20initialize\x20session:\x20'+(_0x1a5cb7[_0x2a3ad6(0x153)]||_0x2ad278[_0x2a3ad6(0x129)]));}const _0x1bf950=await _0x2ad278[_0x2a3ad6(0x127)]();if(!_0x1bf950['success'])throw new Error(_0x1bf950['message']||_0x2a3ad6(0x13a));return _0x1bf950[_0x2a3ad6(0x133)];}async['setupWebRTC'](_0x2d91de){const _0x1cb4d5=a1_0x4c6459;this['peerConnection']=new RTCPeerConnection(),this['dataChannel']=this[_0x1cb4d5(0x13f)][_0x1cb4d5(0x161)](_0x1cb4d5(0x142));this[_0x1cb4d5(0x124)]&&(this[_0x1cb4d5(0x124)][_0x1cb4d5(0x13c)]=_0x219162=>{const _0x380f0f=_0x1cb4d5,_0x498e6b=JSON[_0x380f0f(0x159)](_0x219162[_0x380f0f(0x133)]);this[_0x380f0f(0x114)]['onTranscript']?.(_0x498e6b);});this[_0x1cb4d5(0x13f)]['ontrack']=_0x32c71c=>{const _0x81a209=_0x1cb4d5,_0x6a9139=document['createElement'](_0x81a209(0x118));_0x6a9139['srcObject']=_0x32c71c[_0x81a209(0x11b)][0x0],_0x6a9139[_0x81a209(0x12d)]=!![],document[_0x81a209(0x11a)]['appendChild'](_0x6a9139);},this[_0x1cb4d5(0x14c)]=await navigator[_0x1cb4d5(0x131)][_0x1cb4d5(0x15a)]({'audio':!![]});if(this[_0x1cb4d5(0x14c)]){const _0x5c7a10=this[_0x1cb4d5(0x14c)][_0x1cb4d5(0x11e)]()[0x0];this[_0x1cb4d5(0x13f)]['addTrack'](_0x5c7a10,this[_0x1cb4d5(0x14c)]);}const _0x37876b=await this[_0x1cb4d5(0x13f)][_0x1cb4d5(0x15e)]();await this[_0x1cb4d5(0x13f)][_0x1cb4d5(0x146)](_0x37876b);const _0x329f73=this[_0x1cb4d5(0x123)]['baseUrl']+'/v1/agrasya/connect',_0x162ce9=await fetch(_0x329f73,{'method':_0x1cb4d5(0x11f),'body':JSON['stringify']({'sessionId':this[_0x1cb4d5(0x11c)],'sdp':_0x37876b[_0x1cb4d5(0x157)]}),'headers':{'x-agrasya-client-api-key':this[_0x1cb4d5(0x123)][_0x1cb4d5(0x130)],'Content-Type':_0x1cb4d5(0x135)}});if(!_0x162ce9['ok'])throw new Error(_0x1cb4d5(0x151)+_0x162ce9[_0x1cb4d5(0x129)]);const _0x314ddd=await _0x162ce9[_0x1cb4d5(0x127)](),_0x207367=_0x314ddd[_0x1cb4d5(0x133)][_0x1cb4d5(0x157)],_0x52a969={'type':'answer','sdp':_0x207367};await this[_0x1cb4d5(0x13f)][_0x1cb4d5(0x126)](_0x52a969);}['setupSocketListeners'](_0x1932a6){const _0x55cb38=a1_0x4c6459;_0x1932a6['on']('disconnect',()=>{this['cleanup']();}),_0x1932a6['on'](_0x55cb38(0x12e),()=>{this['cleanup']();}),_0x1932a6['on']('usage_limit_reached',_0x3fb25a=>{const _0x1513fd=_0x55cb38;this['events'][_0x1513fd(0x14e)]?.(_0x3fb25a);});}async[a1_0x4c6459(0x143)](_0x463e2f){const _0x370758=a1_0x4c6459;try{this[_0x370758(0x15d)](_0x370758(0x15f));const _0x4de461=await this['initializeBackendSession']();this[_0x370758(0x11c)]=_0x4de461['sessionId'],this[_0x370758(0x12a)]=_0x4de461[_0x370758(0x12a)];if(!this[_0x370758(0x12a)])throw new Error('key\x20is\x20null\x20or\x20undefined.');const _0x2533a7=await this[_0x370758(0x117)]();this['log'](_0x370758(0x152)+_0x2533a7),await this['setupWebRTC'](this[_0x370758(0x12a)]),this[_0x370758(0x163)]=a1_0x5382ae(this[_0x370758(0x123)][_0x370758(0x13e)],{'transports':[_0x370758(0x141)]}),this[_0x370758(0x163)][_0x370758(0x158)]('join_session',{'sessionId':this[_0x370758(0x11c)]}),this['socket']['emit'](_0x370758(0x162)),this[_0x370758(0x138)](this[_0x370758(0x163)]),this[_0x370758(0x15d)](_0x370758(0x125)),this[_0x370758(0x12b)]();}catch(_0x54d36a){this[_0x370758(0x15d)](_0x370758(0x156));throw _0x54d36a;}}async['stopVoiceSession'](){const _0x333a29=a1_0x4c6459;this[_0x333a29(0x136)]();}[a1_0x4c6459(0x136)](){const _0x2896ff=a1_0x4c6459;this['peerConnection']&&(this[_0x2896ff(0x13f)][_0x2896ff(0x11d)](),this[_0x2896ff(0x13f)]=null),this[_0x2896ff(0x124)]&&(this['dataChannel']['close'](),this[_0x2896ff(0x124)]=null),this[_0x2896ff(0x14c)]&&(this['audioStream'][_0x2896ff(0x11e)]()[_0x2896ff(0x155)](_0x25c35c=>_0x25c35c[_0x2896ff(0x147)]()),this[_0x2896ff(0x14c)]=null),this[_0x2896ff(0x163)]&&(this[_0x2896ff(0x163)][_0x2896ff(0x12c)](),this['socket']=null),this[_0x2896ff(0x132)](),this[_0x2896ff(0x15d)](_0x2896ff(0x14a));}async[a1_0x4c6459(0x117)](){const _0x1ba51a=a1_0x4c6459,_0x728fe5=this[_0x1ba51a(0x123)][_0x1ba51a(0x13e)]+_0x1ba51a(0x13b),_0x2f15a3=await fetch(_0x728fe5,{'method':_0x1ba51a(0x154),'headers':{'x-agrasya-client-api-key':this[_0x1ba51a(0x123)]['apiKey'],'Content-Type':'application/json'}});if(!_0x2f15a3['ok']){const _0x27411b=await _0x2f15a3[_0x1ba51a(0x127)]()['catch'](()=>({'message':_0x2f15a3[_0x1ba51a(0x129)]}));throw new Error(_0x1ba51a(0x149)+(_0x27411b[_0x1ba51a(0x153)]||_0x2f15a3[_0x1ba51a(0x129)]));}const _0x363734=await _0x2f15a3[_0x1ba51a(0x127)]();if(!_0x363734[_0x1ba51a(0x164)])throw new Error(_0x363734['message']||_0x1ba51a(0x15c));return _0x363734[_0x1ba51a(0x133)][_0x1ba51a(0x122)];}};function a1_0x2ac9(_0x581670,_0x2be819){_0x581670=_0x581670-0x114;const _0x5e8288=a1_0x5e82();let _0x2ac92b=_0x5e8288[_0x581670];return _0x2ac92b;}export{AgrasyaVoiceSDK};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrasya-voice-sdk",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",