agrasya-voice-sdk 1.0.34 → 1.0.36
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 +50 -3
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -1
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_0x5a7459=a0_0x2101;(function(_0x3426fa,_0x4184f9){const _0x1f5337=a0_0x2101,_0xcd2aa0=_0x3426fa();while(!![]){try{const _0x17a921=parseInt(_0x1f5337(0x176))/0x1*(parseInt(_0x1f5337(0x18a))/0x2)+parseInt(_0x1f5337(0x151))/0x3*(parseInt(_0x1f5337(0x17e))/0x4)+-parseInt(_0x1f5337(0x174))/0x5*(-parseInt(_0x1f5337(0x164))/0x6)+parseInt(_0x1f5337(0x145))/0x7+parseInt(_0x1f5337(0x167))/0x8+-parseInt(_0x1f5337(0x144))/0x9*(parseInt(_0x1f5337(0x199))/0xa)+-parseInt(_0x1f5337(0x190))/0xb;if(_0x17a921===_0x4184f9)break;else _0xcd2aa0['push'](_0xcd2aa0['shift']());}catch(_0x21f260){_0xcd2aa0['push'](_0xcd2aa0['shift']());}}}(a0_0x4cc0,0xa8014));function a0_0x4cc0(){const _0x1fc22c=['Backend\x20initialization\x20failed','onStatusChange','45GnomIh','5492361IHGZXK','join_session','POST','streams','Failed\x20to\x20fetch\x20minutes\x20usage','socket.io-client','srcObject','connected','debug','stopTimer','cleanup','audio','195867oWBIzu','GET','SDP\x20exchange\x20failed:\x20','[AgrasyaSDK]','getUserMedia','setupSocketListeners','stop','call','update_start_time','Failed\x20to\x20fetch\x20minutes\x20usage:\x20','sessionId','json','exports','close','startVoiceSession','hasOwnProperty','enumerable','minutesLeft','emit','3396EJToTr','setRemoteDescription','Minutes\x20left:\x20','5045632NvgtuE','http://localhost:4001','usage_limit_reached','dataUrl','create','durationInterval','/v1/agrasya/connect','object','fetchMinutesUsage','events','getOwnPropertyNames','log','data','2895FvuImS','__esModule','128434cPLjaW','application/json','setupWebRTC','idle','socket','autoplay','ontrack','ephKey','72bRFuJL','statusText','createElement','error','initializeBackendSession','answer','stringify','defineProperty','dataChannel','message','getPrototypeOf','mediaDevices','4lnQeam','sdp','/v1/agrasya/client-token?language=','startTimer','onUsageLimitReached','baseUrl','23475848xGYYBp','websocket','session_ended','language','success','getTracks','apiKey','callDuration','body','705590aMVOmG','default','config','onmessage','audioStream','addTrack','forEach','appendChild','disconnect','peerConnection','setStatus','onTranscript'];a0_0x4cc0=function(){return _0x1fc22c;};return a0_0x4cc0();}function a0_0x2101(_0x101fe4,_0x5cdc8e){_0x101fe4=_0x101fe4-0x144;const _0x4cc0c4=a0_0x4cc0();let _0x2101d0=_0x4cc0c4[_0x101fe4];return _0x2101d0;}var __create=Object[a0_0x5a7459(0x16b)],__defProp=Object[a0_0x5a7459(0x185)],__getOwnPropDesc=Object['getOwnPropertyDescriptor'],__getOwnPropNames=Object[a0_0x5a7459(0x171)],__getProtoOf=Object[a0_0x5a7459(0x188)],__hasOwnProp=Object['prototype'][a0_0x5a7459(0x160)],__export=(_0x11fd88,_0xccc541)=>{for(var _0x2e4e89 in _0xccc541)__defProp(_0x11fd88,_0x2e4e89,{'get':_0xccc541[_0x2e4e89],'enumerable':!![]});},__copyProps=(_0x292164,_0x7123a9,_0x2b4a0a,_0x4a0b8f)=>{const _0x13214f=a0_0x5a7459;if(_0x7123a9&&typeof _0x7123a9===_0x13214f(0x16e)||typeof _0x7123a9==='function'){for(let _0x30c68e of __getOwnPropNames(_0x7123a9))if(!__hasOwnProp[_0x13214f(0x158)](_0x292164,_0x30c68e)&&_0x30c68e!==_0x2b4a0a)__defProp(_0x292164,_0x30c68e,{'get':()=>_0x7123a9[_0x30c68e],'enumerable':!(_0x4a0b8f=__getOwnPropDesc(_0x7123a9,_0x30c68e))||_0x4a0b8f[_0x13214f(0x161)]});}return _0x292164;},__toESM=(_0x1123c4,_0x4958f5,_0x76455)=>(_0x76455=_0x1123c4!=null?__create(__getProtoOf(_0x1123c4)):{},__copyProps(_0x4958f5||!_0x1123c4||!_0x1123c4[a0_0x5a7459(0x175)]?__defProp(_0x76455,a0_0x5a7459(0x19a),{'value':_0x1123c4,'enumerable':!![]}):_0x76455,_0x1123c4)),__toCommonJS=_0x5ae1b=>__copyProps(__defProp({},a0_0x5a7459(0x175),{'value':!![]}),_0x5ae1b),index_exports={};__export(index_exports,{'AgrasyaVoiceSDK':()=>AgrasyaVoiceSDK}),module[a0_0x5a7459(0x15d)]=__toCommonJS(index_exports);var import_socket=__toESM(require(a0_0x5a7459(0x14a))),AgrasyaVoiceSDK=class{[a0_0x5a7459(0x19b)];[a0_0x5a7459(0x170)];['peerConnection']=null;[a0_0x5a7459(0x186)]=null;[a0_0x5a7459(0x19d)]=null;['socket']=null;[a0_0x5a7459(0x15b)]=null;[a0_0x5a7459(0x17d)]=null;[a0_0x5a7459(0x16a)]=null;['model']=null;[a0_0x5a7459(0x197)]=0x0;[a0_0x5a7459(0x16c)]=null;constructor(_0xefa1b5,_0x209693={}){const _0xdb7565=a0_0x5a7459;this[_0xdb7565(0x19b)]={'baseUrl':_0xdb7565(0x168),'language':'','debug':![],..._0xefa1b5},this[_0xdb7565(0x170)]=_0x209693;}['log'](..._0x303eb8){const _0x24f6c9=a0_0x5a7459;this[_0x24f6c9(0x19b)][_0x24f6c9(0x14d)]&&console[_0x24f6c9(0x172)](_0x24f6c9(0x154),..._0x303eb8);}['setStatus'](_0x551e7a){const _0x373e9f=a0_0x5a7459;this['events'][_0x373e9f(0x1a6)]?.(_0x551e7a);}[a0_0x5a7459(0x18d)](){const _0x3de51b=a0_0x5a7459;this[_0x3de51b(0x197)]=0x0,this[_0x3de51b(0x16c)]=setInterval(()=>{const _0x4d361d=_0x3de51b;this[_0x4d361d(0x197)]+=0x1,this[_0x4d361d(0x170)]['onCallDurationUpdate']?.(this[_0x4d361d(0x197)]);},0x3e8);}[a0_0x5a7459(0x14e)](){const _0x2fd6d8=a0_0x5a7459;this[_0x2fd6d8(0x16c)]&&(clearInterval(this[_0x2fd6d8(0x16c)]),this[_0x2fd6d8(0x16c)]=null);}async[a0_0x5a7459(0x182)](){const _0x37055c=a0_0x5a7459,_0x1337c1=this[_0x37055c(0x19b)][_0x37055c(0x18f)]+_0x37055c(0x18c)+this['config'][_0x37055c(0x193)],_0x350d79=await fetch(_0x1337c1,{'method':_0x37055c(0x152),'headers':{'x-agrasya-client-api-key':this['config'][_0x37055c(0x196)],'Content-Type':'application/json'}});if(!_0x350d79['ok']){const _0x232bad=await _0x350d79[_0x37055c(0x15c)]()['catch'](()=>({'message':_0x350d79[_0x37055c(0x17f)]}));throw new Error('Failed\x20to\x20initialize\x20session:\x20'+(_0x232bad[_0x37055c(0x187)]||_0x350d79[_0x37055c(0x17f)]));}const _0x2c67ad=await _0x350d79['json']();if(!_0x2c67ad[_0x37055c(0x194)])throw new Error(_0x2c67ad[_0x37055c(0x187)]||_0x37055c(0x1a5));return _0x2c67ad[_0x37055c(0x173)];}async[a0_0x5a7459(0x178)](_0x5e7d6e){const _0x5616af=a0_0x5a7459;this[_0x5616af(0x1a2)]=new RTCPeerConnection(),this[_0x5616af(0x186)]=this[_0x5616af(0x1a2)]['createDataChannel']('oai-events');this[_0x5616af(0x186)]&&(this['dataChannel'][_0x5616af(0x19c)]=_0x1bf020=>{const _0x5f2eb5=_0x5616af,_0x16cb2d=JSON['parse'](_0x1bf020[_0x5f2eb5(0x173)]);this[_0x5f2eb5(0x170)][_0x5f2eb5(0x1a4)]?.(_0x16cb2d);});this[_0x5616af(0x1a2)][_0x5616af(0x17c)]=_0x3a1830=>{const _0x394233=_0x5616af,_0x530cb5=document[_0x394233(0x180)](_0x394233(0x150));_0x530cb5[_0x394233(0x14b)]=_0x3a1830[_0x394233(0x148)][0x0],_0x530cb5[_0x394233(0x17b)]=!![],document[_0x394233(0x198)][_0x394233(0x1a0)](_0x530cb5);},this['audioStream']=await navigator[_0x5616af(0x189)][_0x5616af(0x155)]({'audio':!![]});if(this['audioStream']){const _0x9a7b8f=this[_0x5616af(0x19d)]['getTracks']()[0x0];this['peerConnection'][_0x5616af(0x19e)](_0x9a7b8f,this[_0x5616af(0x19d)]);}const _0x469dca=await this[_0x5616af(0x1a2)]['createOffer']();await this[_0x5616af(0x1a2)]['setLocalDescription'](_0x469dca);const _0x5346a6=this[_0x5616af(0x19b)][_0x5616af(0x18f)]+_0x5616af(0x16d),_0x54eb72=await fetch(_0x5346a6,{'method':_0x5616af(0x147),'body':JSON[_0x5616af(0x184)]({'sessionId':this['sessionId'],'sdp':_0x469dca[_0x5616af(0x18b)]}),'headers':{'x-agrasya-client-api-key':this[_0x5616af(0x19b)]['apiKey'],'Content-Type':'application/json'}});if(!_0x54eb72['ok'])throw new Error(_0x5616af(0x153)+_0x54eb72[_0x5616af(0x17f)]);const _0x3b1020=await _0x54eb72[_0x5616af(0x15c)](),_0x59036d=_0x3b1020[_0x5616af(0x173)][_0x5616af(0x18b)],_0x259567={'type':_0x5616af(0x183),'sdp':_0x59036d};await this[_0x5616af(0x1a2)][_0x5616af(0x165)](_0x259567);}[a0_0x5a7459(0x156)](_0x478c52){const _0x13eb3b=a0_0x5a7459;_0x478c52['on']('disconnect',()=>{const _0x363d0b=a0_0x2101;this[_0x363d0b(0x14f)]();}),_0x478c52['on'](_0x13eb3b(0x192),()=>{this['cleanup']();}),_0x478c52['on'](_0x13eb3b(0x169),_0x49ccf8=>{const _0x44ae85=_0x13eb3b;this[_0x44ae85(0x170)][_0x44ae85(0x18e)]?.(_0x49ccf8);});}async[a0_0x5a7459(0x15f)](_0x5129f5){const _0x43b218=a0_0x5a7459;try{this[_0x43b218(0x1a3)]('initializing');const _0xb8e587=await this[_0x43b218(0x182)]();this[_0x43b218(0x15b)]=_0xb8e587['sessionId'],this[_0x43b218(0x17d)]=_0xb8e587[_0x43b218(0x17d)];if(!this['ephKey'])throw new Error('key\x20is\x20null\x20or\x20undefined.');const _0x2c1b9d=await this[_0x43b218(0x16f)]();this[_0x43b218(0x172)](_0x43b218(0x166)+_0x2c1b9d),await this[_0x43b218(0x178)](this['ephKey']),this['socket']=(0x0,import_socket['default'])(this[_0x43b218(0x19b)]['baseUrl'],{'transports':[_0x43b218(0x191)]}),this[_0x43b218(0x17a)]['emit'](_0x43b218(0x146),{'sessionId':this[_0x43b218(0x15b)]}),this['socket'][_0x43b218(0x163)](_0x43b218(0x159)),this[_0x43b218(0x156)](this[_0x43b218(0x17a)]),this[_0x43b218(0x1a3)](_0x43b218(0x14c)),this[_0x43b218(0x18d)]();}catch(_0x5b3f8b){this[_0x43b218(0x1a3)](_0x43b218(0x181));throw _0x5b3f8b;}}async['stopVoiceSession'](){const _0x131584=a0_0x5a7459;this[_0x131584(0x14f)]();}['cleanup'](){const _0xf8f4e2=a0_0x5a7459;this[_0xf8f4e2(0x1a2)]&&(this[_0xf8f4e2(0x1a2)][_0xf8f4e2(0x15e)](),this[_0xf8f4e2(0x1a2)]=null),this[_0xf8f4e2(0x186)]&&(this[_0xf8f4e2(0x186)][_0xf8f4e2(0x15e)](),this[_0xf8f4e2(0x186)]=null),this['audioStream']&&(this['audioStream'][_0xf8f4e2(0x195)]()[_0xf8f4e2(0x19f)](_0x30c66f=>_0x30c66f[_0xf8f4e2(0x157)]()),this['audioStream']=null),this[_0xf8f4e2(0x17a)]&&(this['socket'][_0xf8f4e2(0x1a1)](),this[_0xf8f4e2(0x17a)]=null),this[_0xf8f4e2(0x14e)](),this['setStatus'](_0xf8f4e2(0x179));}async['fetchMinutesUsage'](){const _0xdd59a8=a0_0x5a7459,_0x26a084=this[_0xdd59a8(0x19b)][_0xdd59a8(0x18f)]+'/v1/agrasya/usage',_0x85273b=await fetch(_0x26a084,{'method':'GET','headers':{'x-agrasya-client-api-key':this[_0xdd59a8(0x19b)][_0xdd59a8(0x196)],'Content-Type':_0xdd59a8(0x177)}});if(!_0x85273b['ok']){const _0x2dcfb3=await _0x85273b['json']()['catch'](()=>({'message':_0x85273b[_0xdd59a8(0x17f)]}));throw new Error(_0xdd59a8(0x15a)+(_0x2dcfb3[_0xdd59a8(0x187)]||_0x85273b['statusText']));}const _0x307ca3=await _0x85273b[_0xdd59a8(0x15c)]();if(!_0x307ca3[_0xdd59a8(0x194)])throw new Error(_0x307ca3[_0xdd59a8(0x187)]||_0xdd59a8(0x149));return _0x307ca3[_0xdd59a8(0x173)][_0xdd59a8(0x162)];}};0x0&&(module[a0_0x5a7459(0x15d)]={'AgrasyaVoiceSDK':AgrasyaVoiceSDK});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const a1_0x226254=a1_0x5741;(function(_0x58271d,_0x2129ee){const _0x3d5089=a1_0x5741,_0x36f9b0=_0x58271d();while(!![]){try{const _0x23f0a2=parseInt(_0x3d5089(0x197))/0x1*(parseInt(_0x3d5089(0x186))/0x2)+-parseInt(_0x3d5089(0x18b))/0x3+parseInt(_0x3d5089(0x1c3))/0x4*(-parseInt(_0x3d5089(0x19d))/0x5)+parseInt(_0x3d5089(0x1cf))/0x6+parseInt(_0x3d5089(0x1a9))/0x7+-parseInt(_0x3d5089(0x1b9))/0x8*(parseInt(_0x3d5089(0x1bb))/0x9)+-parseInt(_0x3d5089(0x1b5))/0xa*(-parseInt(_0x3d5089(0x1a1))/0xb);if(_0x23f0a2===_0x2129ee)break;else _0x36f9b0['push'](_0x36f9b0['shift']());}catch(_0x440b04){_0x36f9b0['push'](_0x36f9b0['shift']());}}}(a1_0x4c3a,0x75595));import a1_0x3d1fdb from'socket.io-client';var AgrasyaVoiceSDK=class{['config'];[a1_0x226254(0x1d3)];[a1_0x226254(0x196)]=null;['dataChannel']=null;[a1_0x226254(0x1a5)]=null;['socket']=null;[a1_0x226254(0x19c)]=null;[a1_0x226254(0x193)]=null;[a1_0x226254(0x1ab)]=null;[a1_0x226254(0x192)]=null;['callDuration']=0x0;[a1_0x226254(0x1c6)]=null;constructor(_0x5d2155,_0x4c91d0={}){const _0x52a205=a1_0x226254;this['config']={'baseUrl':_0x52a205(0x1ce),'language':'','debug':![],..._0x5d2155},this[_0x52a205(0x1d3)]=_0x4c91d0;}[a1_0x226254(0x19a)](..._0x30f638){const _0x118af3=a1_0x226254;this[_0x118af3(0x199)]['debug']&&console[_0x118af3(0x19a)](_0x118af3(0x18a),..._0x30f638);}[a1_0x226254(0x1b3)](_0x4bf0f8){const _0x2bc615=a1_0x226254;this['events'][_0x2bc615(0x1cb)]?.(_0x4bf0f8);}[a1_0x226254(0x18e)](){const _0x2dd102=a1_0x226254;this[_0x2dd102(0x194)]=0x0,this[_0x2dd102(0x1c6)]=setInterval(()=>{const _0x161564=_0x2dd102;this['callDuration']+=0x1,this[_0x161564(0x1d3)][_0x161564(0x1a4)]?.(this[_0x161564(0x194)]);},0x3e8);}[a1_0x226254(0x1a7)](){const _0x30442c=a1_0x226254;this[_0x30442c(0x1c6)]&&(clearInterval(this[_0x30442c(0x1c6)]),this[_0x30442c(0x1c6)]=null);}async[a1_0x226254(0x1b6)](){const _0x3b466d=a1_0x226254,_0x509430=this[_0x3b466d(0x199)]['baseUrl']+_0x3b466d(0x18d)+this['config'][_0x3b466d(0x1c8)],_0x51bbed=await fetch(_0x509430,{'method':'GET','headers':{'x-agrasya-client-api-key':this['config'][_0x3b466d(0x1cc)],'Content-Type':_0x3b466d(0x198)}});if(!_0x51bbed['ok']){const _0x20b30b=await _0x51bbed['json']()[_0x3b466d(0x1be)](()=>({'message':_0x51bbed['statusText']}));throw new Error('Failed\x20to\x20initialize\x20session:\x20'+(_0x20b30b[_0x3b466d(0x1bf)]||_0x51bbed['statusText']));}const _0x9f3c31=await _0x51bbed[_0x3b466d(0x1d2)]();if(!_0x9f3c31[_0x3b466d(0x1c4)])throw new Error(_0x9f3c31[_0x3b466d(0x1bf)]||'Backend\x20initialization\x20failed');return _0x9f3c31['data'];}async[a1_0x226254(0x187)](_0x38b4fe){const _0x541497=a1_0x226254;this[_0x541497(0x196)]=new RTCPeerConnection(),this[_0x541497(0x1c1)]=this[_0x541497(0x196)][_0x541497(0x1ad)](_0x541497(0x1bd));this[_0x541497(0x1c1)]&&(this[_0x541497(0x1c1)][_0x541497(0x18c)]=_0x3fba43=>{const _0x39957c=_0x541497,_0x518875=JSON[_0x39957c(0x19b)](_0x3fba43[_0x39957c(0x19e)]);this[_0x39957c(0x1d3)][_0x39957c(0x1c0)]?.(_0x518875);});this[_0x541497(0x196)][_0x541497(0x1d4)]=_0x39987c=>{const _0x5e2daa=_0x541497,_0x50ebf8=document['createElement'](_0x5e2daa(0x1b7));_0x50ebf8[_0x5e2daa(0x1ae)]=_0x39987c[_0x5e2daa(0x1aa)][0x0],_0x50ebf8[_0x5e2daa(0x1ca)]=!![],document[_0x5e2daa(0x1d0)][_0x5e2daa(0x1a3)](_0x50ebf8);},this['audioStream']=await navigator[_0x541497(0x1b8)][_0x541497(0x1b1)]({'audio':!![]});if(this['audioStream']){const _0x208ba5=this[_0x541497(0x1a5)][_0x541497(0x1b0)]()[0x0];this[_0x541497(0x196)]['addTrack'](_0x208ba5,this[_0x541497(0x1a5)]);}const _0x5b6be0=await this['peerConnection']['createOffer']();await this[_0x541497(0x196)][_0x541497(0x1af)](_0x5b6be0);const _0x3e3c5f=this[_0x541497(0x199)][_0x541497(0x1b4)]+'/v1/agrasya/connect',_0x333249=await fetch(_0x3e3c5f,{'method':_0x541497(0x1c5),'body':JSON[_0x541497(0x1d1)]({'sessionId':this[_0x541497(0x19c)],'sdp':_0x5b6be0[_0x541497(0x190)]}),'headers':{'x-agrasya-client-api-key':this[_0x541497(0x199)][_0x541497(0x1cc)],'Content-Type':_0x541497(0x198)}});if(!_0x333249['ok'])throw new Error('SDP\x20exchange\x20failed:\x20'+_0x333249[_0x541497(0x185)]);const _0x13f538=await _0x333249[_0x541497(0x1d2)](),_0x4a1ed5=_0x13f538[_0x541497(0x19e)][_0x541497(0x190)],_0x2cbb3b={'type':'answer','sdp':_0x4a1ed5};await this[_0x541497(0x196)]['setRemoteDescription'](_0x2cbb3b);}[a1_0x226254(0x18f)](_0x38f39b){const _0x401dc8=a1_0x226254;_0x38f39b['on']('disconnect',()=>{this['cleanup']();}),_0x38f39b['on'](_0x401dc8(0x1a8),()=>{const _0x14f12f=_0x401dc8;this[_0x14f12f(0x1a0)]();}),_0x38f39b['on'](_0x401dc8(0x1a6),_0x388ec8=>{const _0x2cb814=_0x401dc8;this[_0x2cb814(0x1d3)][_0x2cb814(0x1d5)]?.(_0x388ec8);});}async['startVoiceSession'](_0x5807cb){const _0x4f780b=a1_0x226254;try{this[_0x4f780b(0x1b3)](_0x4f780b(0x1b2));const _0x11cc3e=await this[_0x4f780b(0x1b6)]();this[_0x4f780b(0x19c)]=_0x11cc3e[_0x4f780b(0x19c)],this[_0x4f780b(0x193)]=_0x11cc3e[_0x4f780b(0x193)];if(!this[_0x4f780b(0x193)])throw new Error(_0x4f780b(0x189));const _0x1e4e98=await this[_0x4f780b(0x1ac)]();this['log']('Minutes\x20left:\x20'+_0x1e4e98),await this[_0x4f780b(0x187)](this['ephKey']),this[_0x4f780b(0x1c7)]=a1_0x3d1fdb(this[_0x4f780b(0x199)][_0x4f780b(0x1b4)],{'transports':['websocket']}),this[_0x4f780b(0x1c7)]['emit'](_0x4f780b(0x1d6),{'sessionId':this[_0x4f780b(0x19c)]}),this['socket'][_0x4f780b(0x1ba)]('update_start_time'),this[_0x4f780b(0x18f)](this[_0x4f780b(0x1c7)]),this[_0x4f780b(0x1b3)]('connected'),this[_0x4f780b(0x18e)]();}catch(_0x51b1b7){this['setStatus']('error');throw _0x51b1b7;}}async[a1_0x226254(0x1a2)](){this['cleanup']();}[a1_0x226254(0x1a0)](){const _0x440bb4=a1_0x226254;this[_0x440bb4(0x196)]&&(this[_0x440bb4(0x196)]['close'](),this['peerConnection']=null),this['dataChannel']&&(this[_0x440bb4(0x1c1)][_0x440bb4(0x1bc)](),this['dataChannel']=null),this[_0x440bb4(0x1a5)]&&(this[_0x440bb4(0x1a5)][_0x440bb4(0x1b0)]()[_0x440bb4(0x1c9)](_0x5a37d2=>_0x5a37d2[_0x440bb4(0x191)]()),this[_0x440bb4(0x1a5)]=null),this[_0x440bb4(0x1c7)]&&(this['socket'][_0x440bb4(0x1c2)](),this[_0x440bb4(0x1c7)]=null),this[_0x440bb4(0x1a7)](),this[_0x440bb4(0x1b3)]('idle');}async['fetchMinutesUsage'](){const _0x4fe654=a1_0x226254,_0x229114=this[_0x4fe654(0x199)][_0x4fe654(0x1b4)]+_0x4fe654(0x188),_0x212346=await fetch(_0x229114,{'method':_0x4fe654(0x1cd),'headers':{'x-agrasya-client-api-key':this[_0x4fe654(0x199)][_0x4fe654(0x1cc)],'Content-Type':_0x4fe654(0x198)}});if(!_0x212346['ok']){const _0x56af6c=await _0x212346[_0x4fe654(0x1d2)]()[_0x4fe654(0x1be)](()=>({'message':_0x212346[_0x4fe654(0x185)]}));throw new Error(_0x4fe654(0x19f)+(_0x56af6c[_0x4fe654(0x1bf)]||_0x212346[_0x4fe654(0x185)]));}const _0x115fb2=await _0x212346['json']();if(!_0x115fb2['success'])throw new Error(_0x115fb2['message']||'Failed\x20to\x20fetch\x20minutes\x20usage');return _0x115fb2[_0x4fe654(0x19e)][_0x4fe654(0x195)];}};function a1_0x4c3a(){const _0x5448ca=['streams','dataUrl','fetchMinutesUsage','createDataChannel','srcObject','setLocalDescription','getTracks','getUserMedia','initializing','setStatus','baseUrl','49690BAEEKE','initializeBackendSession','audio','mediaDevices','168HCbTPW','emit','138519ddAOHZ','close','oai-events','catch','message','onTranscript','dataChannel','disconnect','67528rJOZIG','success','POST','durationInterval','socket','language','forEach','autoplay','onStatusChange','apiKey','GET','http://localhost:4001','4412934WTfFVw','body','stringify','json','events','ontrack','onUsageLimitReached','join_session','statusText','8528yJEoeU','setupWebRTC','/v1/agrasya/usage','key\x20is\x20null\x20or\x20undefined.','[AgrasyaSDK]','2319510NyeJNa','onmessage','/v1/agrasya/client-token?language=','startTimer','setupSocketListeners','sdp','stop','model','ephKey','callDuration','minutesLeft','peerConnection','205WtRunt','application/json','config','log','parse','sessionId','145FqbqLU','data','Failed\x20to\x20fetch\x20minutes\x20usage:\x20','cleanup','737pNkKrT','stopVoiceSession','appendChild','onCallDurationUpdate','audioStream','usage_limit_reached','stopTimer','session_ended','868616zlAPns'];a1_0x4c3a=function(){return _0x5448ca;};return a1_0x4c3a();}function a1_0x5741(_0xfb9e93,_0x217916){_0xfb9e93=_0xfb9e93-0x185;const _0x4c3afa=a1_0x4c3a();let _0x574120=_0x4c3afa[_0xfb9e93];return _0x574120;}export{AgrasyaVoiceSDK};
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agrasya-voice-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.36",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
|
+
"react-native": "dist/index.mjs",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
9
|
"dist"
|
|
@@ -31,3 +32,4 @@
|
|
|
31
32
|
"socket.io-client": "^4.8.3"
|
|
32
33
|
}
|
|
33
34
|
}
|
|
35
|
+
|