@callpromn/rtc-sdk 0.0.3
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/LICENSE.txt +32 -0
- package/README.md +173 -0
- package/dist/index.d.mts +244 -0
- package/dist/index.d.ts +244 -0
- package/dist/index.js +10 -0
- package/dist/index.mjs +10 -0
- package/package.json +57 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
SOFTWARE LICENSE AGREEMENT
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 CallPro LLC. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This Software License Agreement (“Agreement”) is a legal agreement between you (“Licensee”) and CallPro LLC (“Licensor”) for the use of the "rtc-sdk" software (“Software”). By installing, copying, or otherwise using the Software, you agree to be bound by the terms of this Agreement.
|
|
6
|
+
|
|
7
|
+
1. Grant of License
|
|
8
|
+
Licensor grants Licensee a non-exclusive, non-transferable, revocable license to use the Software solely for the purpose of developing applications that interact with or make use of the Software’s functionality.
|
|
9
|
+
|
|
10
|
+
2. Restrictions
|
|
11
|
+
Licensee shall not, directly or indirectly:
|
|
12
|
+
a. Copy, modify, adapt, translate, or create derivative works of the Software.
|
|
13
|
+
b. Reverse-engineer, decompile, disassemble, or otherwise attempt to discover the source code of the Software.
|
|
14
|
+
c. Distribute, sublicense, rent, lease, or sell the Software, in whole or in part, to any third party.
|
|
15
|
+
d. Remove or alter any proprietary notices, labels, or marks from the Software.
|
|
16
|
+
|
|
17
|
+
3. Ownership
|
|
18
|
+
The Software is licensed, not sold. Licensor retains all rights, title, and interest in and to the Software, including all intellectual property rights therein.
|
|
19
|
+
|
|
20
|
+
4. Termination
|
|
21
|
+
This Agreement is effective until terminated. Licensor may terminate this Agreement at any time if Licensee breaches any provision. Upon termination, Licensee must cease all use of the Software and destroy all copies in its possession.
|
|
22
|
+
|
|
23
|
+
5. Disclaimer of Warranty
|
|
24
|
+
The Software is provided “AS IS” without warranty of any kind, whether express, implied, or statutory, including but not limited to warranties of merchantability, fitness for a particular purpose, and non-infringement.
|
|
25
|
+
|
|
26
|
+
6. Limitation of Liability
|
|
27
|
+
In no event shall Licensor be liable for any indirect, incidental, consequential, special, or punitive damages arising out of or related to the use of the Software.
|
|
28
|
+
|
|
29
|
+
7. Governing Law
|
|
30
|
+
This Agreement shall be governed by and construed in accordance with the laws of Mongolia, without regard to conflict of law principles.
|
|
31
|
+
|
|
32
|
+
BY USING THE SOFTWARE, YOU ACKNOWLEDGE THAT YOU HAVE READ THIS AGREEMENT, UNDERSTOOD IT, AND AGREE TO BE BOUND BY ITS TERMS.
|
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# RTC-SDK
|
|
2
|
+
|
|
3
|
+
RTC-SDK нь CallPro компанийн боловсруулсан, дуудлагын үйлчилгээг хурдан, шууд нэгтгэх зориулалттай SDK юм.
|
|
4
|
+
|
|
5
|
+
Энэхүү санг ашигласнаар та өөрийн системд дэлхийн хаанаас ч үүрэн болон суурин утас руу дуудлага хийх, хүлээн авах боломжийг нэмэх боломжтой.
|
|
6
|
+
|
|
7
|
+
## Суулгах
|
|
8
|
+
|
|
9
|
+
RTC-SDK-ийг суулгах
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @callpromn/rtc-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Badges
|
|
16
|
+
|
|
17
|
+
[](https://www.npmjs.com/package/@callpromn/rtc-sdk)
|
|
18
|
+
[](https://www.npmjs.com/package/@callpromn/rtc-sdk)
|
|
19
|
+
[](https://choosealicense.com/licenses/mit/)
|
|
20
|
+
|
|
21
|
+
## 🚀 Quickstart
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import CallClient from '@callpromn/rtc-sdk';
|
|
25
|
+
|
|
26
|
+
// CallClient үүсгэх
|
|
27
|
+
const callClient = CallClient();
|
|
28
|
+
|
|
29
|
+
// Client-ын instance үүсгэх
|
|
30
|
+
const callClientInstance = await callClient.createClient(config);
|
|
31
|
+
|
|
32
|
+
// Гарах дуудлага хийх
|
|
33
|
+
await callClientInstance.createCall('12345678');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## ⚙️ Тохиргоо
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
const config = {
|
|
40
|
+
socketUrl: 'wss://example.callpro.mn',
|
|
41
|
+
socketToken: 'token',
|
|
42
|
+
socketConnectionOptions: {}, // (optional) socket.io холболтын тохиргоо
|
|
43
|
+
phoneNumber: '12345678', // таны утасны дугаар
|
|
44
|
+
outboundRoom: 'outboundRoom', // гарах дуудлагын өрөө
|
|
45
|
+
inboundRoom: 'inboundRoom', // орох дуудлагын өрөө
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## APIs
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
import CallClient from '@callpromn/rtc-sdk';
|
|
53
|
+
|
|
54
|
+
const callClient = CallClient();
|
|
55
|
+
const callClientInstance = await callClient.createClient(config);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 📤 Гарах дуудлага
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
await callClientInstance.createCall('утасны_дугаар'); // Залгах дугаараа оруулан залгах
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 📥 Орох дуудлага
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
await callClientInstance.acceptCall(); // Ирж буй дуудлагыг хүлээж авах
|
|
68
|
+
await callClientInstance.declineCall(); // Ирж буй дуудлагыг хүлээж авахгүй байх
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Бусад хийх боломжтой үйлдлүүд
|
|
72
|
+
|
|
73
|
+
#### isConnected()
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
await callClientInstance.isConnected();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Socket сервертэй холбогдсон эсэхийг шалгана.
|
|
80
|
+
|
|
81
|
+
#### endCall()
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
await callClientInstance.endCall();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Идэвхтэй явагдаж буй дуудлагыг дуусгана.
|
|
88
|
+
|
|
89
|
+
#### toggleMic()
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
await callClientInstance.toggleMic();
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Микрофоныг нээх/хаах (mute/unmute) үйлдэл хийнэ.
|
|
96
|
+
|
|
97
|
+
#### getInboundUserData()
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
await callClientInstance.getInboundUserData();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Залгаж буй хэрэглэгчийн мэдээллийг авах
|
|
104
|
+
|
|
105
|
+
## Эвентүүд
|
|
106
|
+
|
|
107
|
+
RTC-SDK нь хэрэглэгчид рүү бодит цагын(real-time) эвентүүд илгээдэг.
|
|
108
|
+
Эдгээр эвентүүдийг callClientInstance.on(eventName, callback) хэлбэрээр сонсож ашиглана.
|
|
109
|
+
|
|
110
|
+
| Эвент нэр | Параметр | Тайлбар |
|
|
111
|
+
| --------------- | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
112
|
+
| **`call_init`** | `"incoming"` эсвэл `"outbound"` | Дуудлага эхлэх үед үүснэ. `"incoming"` нь хэрэглэгч рүү орох дуудлага ирж байгааг, `"outbound"` нь хэрэглэгч гарах дуудлага хийж байгааг илэрхийлнэ. |
|
|
113
|
+
| **`ringing`** | - | Дуудлага холбогдох гэж байх үед (дуугарч байх үед) үүснэ. |
|
|
114
|
+
| **`answered`** | - | Нөгөө тал дуудлагыг хүлээж авсан үед үүснэ. |
|
|
115
|
+
| **`busy`** | - | Хүлээн авагчийн утас завгүй үед үүснэ. |
|
|
116
|
+
| **`hangup`** | - | Дуудлага дууссан үед (аль ч талаас тасалсан) үүснэ. |
|
|
117
|
+
|
|
118
|
+
### Жишээ
|
|
119
|
+
|
|
120
|
+
```javascript
|
|
121
|
+
callClientInstance.on('call_init', (direction) => {
|
|
122
|
+
if (direction === 'incoming') {
|
|
123
|
+
console.log('📥 Орох дуудлага ирлээ');
|
|
124
|
+
} else if (direction === 'outbound') {
|
|
125
|
+
console.log('📤 Гарах дуудлага эхэллээ');
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
callClientInstance.on('ringing', () => {
|
|
130
|
+
console.log('Дуудлага дугарч байна...');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
callClientInstance.on('answered', () => {
|
|
134
|
+
console.log('Дуудлага хүлээж авлаа');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
callClientInstance.on('busy', () => {
|
|
138
|
+
console.log('Хүлээн авагч завгүй байна');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
callClientInstance.on('hangup', () => {
|
|
142
|
+
console.log('Дуудлага дууслаа');
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Холбоотой төслүүд
|
|
147
|
+
|
|
148
|
+
RTC-SDK-ын Prebuild(UI) хувилбарууд
|
|
149
|
+
|
|
150
|
+
- [RTC-Kit](https://www.npmjs.com/package/@callpromn/rtc-kit)
|
|
151
|
+
- [RTC-Kit-React](https://www.npmjs.com/package/@callpromn/rtc-kit-react)
|
|
152
|
+
- [RTC-Kit-Angular](https://www.npmjs.com/package/@callpromn/rtc-kit-angular) (coming soon)
|
|
153
|
+
- [RTC-Kit-VueJS](https://www.npmjs.com/package/@callpromn/rtc-kit-vue) (coming soon)
|
|
154
|
+
- [RTC-Kit-Svelte](https://www.npmjs.com/package/@callpromn/rtc-kit-svelte) (coming soon)
|
|
155
|
+
|
|
156
|
+
RTC-SDK-ын No-Code хувилбар
|
|
157
|
+
|
|
158
|
+
- [No-Code хувилбар](https://callpro.mn) (coming soon)
|
|
159
|
+
|
|
160
|
+
RTC-SDK-ын бусад хувилбарууд
|
|
161
|
+
|
|
162
|
+
- [RTCKit-iOS](https://www.npmjs.com/package/@callpromn/rtc-sdk) (coming soon)
|
|
163
|
+
- [RTCKit-Android](https://www.npmjs.com/package/@callpromn/rtc-sdk) (coming soon)
|
|
164
|
+
|
|
165
|
+
## 🔗 Холбоосууд
|
|
166
|
+
|
|
167
|
+
- [Documentation](https://docs.callpro.mn)
|
|
168
|
+
- [Жишээ төсөл](https://github.com/callpromn/nextjs-quickstart)
|
|
169
|
+
|
|
170
|
+
## Холбоо барих, Тусламж
|
|
171
|
+
|
|
172
|
+
- Бидэнтэй холбоо барих: [CallPro](https://callpro.mn)
|
|
173
|
+
- Бүтээгдэхүүнтэй холбоотой асуулт, зөвлөгөө, тусламж авах: dev@callpro.mn
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { ManagerOptions, SocketOptions } from 'socket.io-client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration object for creating a CallClient instance.
|
|
5
|
+
*
|
|
6
|
+
* @interface CallClientConfig
|
|
7
|
+
* @property {string} socketUrl - WebSocket server URL for signaling (e.g., 'wss://signaling.example.com')
|
|
8
|
+
* @property {string} socketToken - Authentication token for signaling server connection
|
|
9
|
+
* @property {Partial<ManagerOptions & SocketOptions>} [socketConnectionOptions] - Optional Socket.IO connection configuration
|
|
10
|
+
* @property {string} phoneNumber - Tenant's phone number identifier (e.g., '+1234567890')
|
|
11
|
+
* @property {string} outboundRoom - Room identifier for outbound calls
|
|
12
|
+
* @property {string} inboundRoom - Room identifier for inbound calls
|
|
13
|
+
*/
|
|
14
|
+
type CallClientConfig = {
|
|
15
|
+
socketUrl: string;
|
|
16
|
+
socketToken: string;
|
|
17
|
+
socketConnectionOptions?: Partial<ManagerOptions & SocketOptions>;
|
|
18
|
+
phoneNumber: string;
|
|
19
|
+
outboundRoom: string;
|
|
20
|
+
inboundRoom: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Data structure containing information about an incoming call.
|
|
24
|
+
* This type represents the complete payload received when an inbound call is initiated.
|
|
25
|
+
*
|
|
26
|
+
* @interface InboundUserData
|
|
27
|
+
* @property {string} appId - Unique identifier for the calling application
|
|
28
|
+
* @property {string} callRoom - WebSocket room identifier for the specific call session
|
|
29
|
+
* @property {string} destNumber - Destination phone number (the number being called)
|
|
30
|
+
* @property {string} fromName - Display name of the caller
|
|
31
|
+
* @property {string} fromNumber - Phone number of the caller
|
|
32
|
+
* @property {string} method - Call method/action type (e.g., 'call_init', 'ringing', 'answered', 'hangup')
|
|
33
|
+
* @property {string} roomId - WebRTC room identifier for media communication
|
|
34
|
+
* @property {string} rtcToken - Authentication token for WebRTC server access
|
|
35
|
+
* @property {string} serverUrl - WebRTC server URL for media relay
|
|
36
|
+
* @property {number} tenantId - Unique identifier for the tenant/organization
|
|
37
|
+
* @property {string} userId - Unique identifier for the calling user
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const inboundData: InboundUserData = {
|
|
42
|
+
* appId: 'app_12345',
|
|
43
|
+
* callRoom: 'room_67890',
|
|
44
|
+
* destNumber: '+1234567890',
|
|
45
|
+
* fromName: 'John Doe',
|
|
46
|
+
* fromNumber: '+0987654321',
|
|
47
|
+
* method: 'call_init',
|
|
48
|
+
* roomId: 'rtc_room_abc123',
|
|
49
|
+
* rtcToken: 'rtc_token_xyz789',
|
|
50
|
+
* serverUrl: 'https://rtc.example.com',
|
|
51
|
+
* tenantId: 12345,
|
|
52
|
+
* userId: 'user_456'
|
|
53
|
+
* };
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
type InboundUserData = {
|
|
57
|
+
appId: string;
|
|
58
|
+
callRoom: string;
|
|
59
|
+
destNumber: string;
|
|
60
|
+
fromName: string;
|
|
61
|
+
fromNumber: string;
|
|
62
|
+
method: string;
|
|
63
|
+
roomId: string;
|
|
64
|
+
rtcToken: string;
|
|
65
|
+
serverUrl: string;
|
|
66
|
+
tenantId: number;
|
|
67
|
+
userId: string;
|
|
68
|
+
} | null;
|
|
69
|
+
/**
|
|
70
|
+
* Interface defining the public API for a CallClient instance.
|
|
71
|
+
* This represents the complete set of methods available for managing real-time voice calls.
|
|
72
|
+
*
|
|
73
|
+
* @interface CallClientInstance
|
|
74
|
+
* @property {Function} createCall - Initiates an outbound call to a specified phone number
|
|
75
|
+
* @property {Function} acceptCall - Accepts an incoming call that was previously initiated
|
|
76
|
+
* @property {Function} endCall - Terminates the currently active call session
|
|
77
|
+
* @property {Function} declineCall - Rejects an incoming call without establishing connection
|
|
78
|
+
* @property {Function} isConnected - Checks the current WebSocket signaling connection status
|
|
79
|
+
* @property {Function} toggleMic - Toggles microphone mute/unmute state during active calls
|
|
80
|
+
* @property {Function} getInboundUserData - Retrieves metadata about the current incoming call
|
|
81
|
+
* @property {Function} on - Registers event listeners for call-related events
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // Create a CallClient instance
|
|
86
|
+
* const callClient = CallClient();
|
|
87
|
+
* const client: CallClientInstance = await callClient.createClient(config);
|
|
88
|
+
*
|
|
89
|
+
* // Set up event listeners
|
|
90
|
+
* client.on('call_init', (direction: string) => {
|
|
91
|
+
* if (direction === 'incoming') {
|
|
92
|
+
* console.log('Incoming call received');
|
|
93
|
+
* // Optionally auto-accept or show UI
|
|
94
|
+
* await client.acceptCall();
|
|
95
|
+
* }
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* client.on('answered', () => {
|
|
99
|
+
* console.log('Call was answered');
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* client.on('hangup', () => {
|
|
103
|
+
* console.log('Call ended');
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // Make an outbound call
|
|
107
|
+
* await client.createCall('+1234567890');
|
|
108
|
+
*
|
|
109
|
+
* // Check connection status
|
|
110
|
+
* if (client.isConnected()) {
|
|
111
|
+
* console.log('Signaling server connected');
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* // Control microphone during call
|
|
115
|
+
* await client.toggleMic(); // Mute
|
|
116
|
+
* await client.toggleMic(); // Unmute
|
|
117
|
+
*
|
|
118
|
+
* // End the call
|
|
119
|
+
* await client.endCall();
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
type CallClientInstance = {
|
|
123
|
+
/**
|
|
124
|
+
* Initiates an outbound call to the specified phone number.
|
|
125
|
+
*
|
|
126
|
+
* @param {string} toPhoneNumber - The destination phone number (e.g., '+1234567890')
|
|
127
|
+
* @returns {Promise<void>} Promise that resolves when call initiation is complete
|
|
128
|
+
* @throws {Error} Throws if signaling server is disconnected or invalid phone number
|
|
129
|
+
*/
|
|
130
|
+
createCall: (toPhoneNumber: string) => Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Accepts an incoming call that was previously initiated.
|
|
133
|
+
* Must be called after receiving a 'call_init' event with direction 'incoming'.
|
|
134
|
+
*
|
|
135
|
+
* @returns {Promise<void>} Promise that resolves when call is successfully accepted
|
|
136
|
+
* @throws {Error} Throws if no incoming call is available or connection fails
|
|
137
|
+
*/
|
|
138
|
+
acceptCall: () => Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Terminates the currently active call session.
|
|
141
|
+
* Can be called during any active call state (incoming, outgoing, or established).
|
|
142
|
+
*
|
|
143
|
+
* @returns {Promise<void>} Promise that resolves when call is successfully ended
|
|
144
|
+
*/
|
|
145
|
+
endCall: () => Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Rejects an incoming call without establishing a connection.
|
|
148
|
+
* Must be called after receiving a 'call_init' event with direction 'incoming'.
|
|
149
|
+
*
|
|
150
|
+
* @returns {Promise<void>} Promise that resolves when call is successfully declined
|
|
151
|
+
*/
|
|
152
|
+
declineCall: () => Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Checks the current WebSocket signaling connection status.
|
|
155
|
+
*
|
|
156
|
+
* @returns {boolean} True if connected to signaling server, false otherwise
|
|
157
|
+
*/
|
|
158
|
+
isConnected: () => boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Toggles the microphone mute state during an active call.
|
|
161
|
+
* If currently muted, will unmute. If currently unmuted, will mute.
|
|
162
|
+
*
|
|
163
|
+
* @returns {Promise<void>} Promise that resolves when microphone state is changed
|
|
164
|
+
* @throws {Error} Throws if no active call or audio device access fails
|
|
165
|
+
*/
|
|
166
|
+
toggleMic: () => Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Retrieves metadata about the current incoming call.
|
|
169
|
+
* Returns null if no incoming call is available.
|
|
170
|
+
*
|
|
171
|
+
* @returns {Promise<InboundUserData>} Promise resolving to call metadata or null
|
|
172
|
+
*/
|
|
173
|
+
getInboundUserData: () => Promise<InboundUserData>;
|
|
174
|
+
/**
|
|
175
|
+
* Registers an event listener for call-related events.
|
|
176
|
+
*
|
|
177
|
+
* Available events:
|
|
178
|
+
* - 'call_init': Fired when call is initiated (payload: 'incoming' | 'outbound')
|
|
179
|
+
* - 'ringing': Fired when remote party is ringing
|
|
180
|
+
* - 'answered': Fired when call is answered by remote party
|
|
181
|
+
* - 'hangup': Fired when call is terminated
|
|
182
|
+
* - 'busy': Fired when remote party is busy
|
|
183
|
+
*
|
|
184
|
+
* @param {string} event - The event name to listen for
|
|
185
|
+
* @param {Function} handler - The callback function to execute when event fires
|
|
186
|
+
* @returns {void}
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* client.on('call_init', (direction: string) => {
|
|
191
|
+
* console.log(`Call initiated: ${direction}`);
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* client.on('answered', () => {
|
|
195
|
+
* console.log('Call answered - conversation started');
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
on: <T = string>(event: string, handler: (payload: T) => void) => void;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Creates a CallClient instance with real-time communication capabilities.
|
|
203
|
+
*
|
|
204
|
+
* This function initializes a complete calling system that handles both inbound and outbound calls,
|
|
205
|
+
* signaling through WebSocket connections, and audio/video communication through WebRTC.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const callClient = CallClient();
|
|
210
|
+
* const client = await callClient.createClient({
|
|
211
|
+
* socketUrl: 'wss://signaling.example.com',
|
|
212
|
+
* socketToken: 'your-auth-token',
|
|
213
|
+
* phoneNumber: '+1234567890',
|
|
214
|
+
* outboundRoom: 'outbound_room_id',
|
|
215
|
+
* inboundRoom: 'inbound_room_id',
|
|
216
|
+
* socketConnectionOptions: {
|
|
217
|
+
* timeout: 5000,
|
|
218
|
+
* autoConnect: true
|
|
219
|
+
* }
|
|
220
|
+
* });
|
|
221
|
+
*
|
|
222
|
+
* // Listen for incoming calls
|
|
223
|
+
* client.on('inbound-call', (callData) => {
|
|
224
|
+
* console.log('Incoming call:', callData);
|
|
225
|
+
* });
|
|
226
|
+
*
|
|
227
|
+
* // Make an outbound call
|
|
228
|
+
* await client.createCall('destination-number');
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
declare function CallClient(): {
|
|
232
|
+
createClient: (config: CallClientConfig) => Promise<{
|
|
233
|
+
createCall: (toPhoneNumber: string) => Promise<void>;
|
|
234
|
+
acceptCall: () => Promise<void>;
|
|
235
|
+
endCall: () => Promise<void>;
|
|
236
|
+
declineCall: () => Promise<void>;
|
|
237
|
+
isConnected: () => boolean;
|
|
238
|
+
toggleMic: () => Promise<void>;
|
|
239
|
+
getInboundUserData: () => Promise<any>;
|
|
240
|
+
on: <T = any>(event: string, handler: (payload: T) => void) => void;
|
|
241
|
+
}>;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export { CallClient, type CallClientConfig, type CallClientInstance, type InboundUserData };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { ManagerOptions, SocketOptions } from 'socket.io-client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration object for creating a CallClient instance.
|
|
5
|
+
*
|
|
6
|
+
* @interface CallClientConfig
|
|
7
|
+
* @property {string} socketUrl - WebSocket server URL for signaling (e.g., 'wss://signaling.example.com')
|
|
8
|
+
* @property {string} socketToken - Authentication token for signaling server connection
|
|
9
|
+
* @property {Partial<ManagerOptions & SocketOptions>} [socketConnectionOptions] - Optional Socket.IO connection configuration
|
|
10
|
+
* @property {string} phoneNumber - Tenant's phone number identifier (e.g., '+1234567890')
|
|
11
|
+
* @property {string} outboundRoom - Room identifier for outbound calls
|
|
12
|
+
* @property {string} inboundRoom - Room identifier for inbound calls
|
|
13
|
+
*/
|
|
14
|
+
type CallClientConfig = {
|
|
15
|
+
socketUrl: string;
|
|
16
|
+
socketToken: string;
|
|
17
|
+
socketConnectionOptions?: Partial<ManagerOptions & SocketOptions>;
|
|
18
|
+
phoneNumber: string;
|
|
19
|
+
outboundRoom: string;
|
|
20
|
+
inboundRoom: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Data structure containing information about an incoming call.
|
|
24
|
+
* This type represents the complete payload received when an inbound call is initiated.
|
|
25
|
+
*
|
|
26
|
+
* @interface InboundUserData
|
|
27
|
+
* @property {string} appId - Unique identifier for the calling application
|
|
28
|
+
* @property {string} callRoom - WebSocket room identifier for the specific call session
|
|
29
|
+
* @property {string} destNumber - Destination phone number (the number being called)
|
|
30
|
+
* @property {string} fromName - Display name of the caller
|
|
31
|
+
* @property {string} fromNumber - Phone number of the caller
|
|
32
|
+
* @property {string} method - Call method/action type (e.g., 'call_init', 'ringing', 'answered', 'hangup')
|
|
33
|
+
* @property {string} roomId - WebRTC room identifier for media communication
|
|
34
|
+
* @property {string} rtcToken - Authentication token for WebRTC server access
|
|
35
|
+
* @property {string} serverUrl - WebRTC server URL for media relay
|
|
36
|
+
* @property {number} tenantId - Unique identifier for the tenant/organization
|
|
37
|
+
* @property {string} userId - Unique identifier for the calling user
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const inboundData: InboundUserData = {
|
|
42
|
+
* appId: 'app_12345',
|
|
43
|
+
* callRoom: 'room_67890',
|
|
44
|
+
* destNumber: '+1234567890',
|
|
45
|
+
* fromName: 'John Doe',
|
|
46
|
+
* fromNumber: '+0987654321',
|
|
47
|
+
* method: 'call_init',
|
|
48
|
+
* roomId: 'rtc_room_abc123',
|
|
49
|
+
* rtcToken: 'rtc_token_xyz789',
|
|
50
|
+
* serverUrl: 'https://rtc.example.com',
|
|
51
|
+
* tenantId: 12345,
|
|
52
|
+
* userId: 'user_456'
|
|
53
|
+
* };
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
type InboundUserData = {
|
|
57
|
+
appId: string;
|
|
58
|
+
callRoom: string;
|
|
59
|
+
destNumber: string;
|
|
60
|
+
fromName: string;
|
|
61
|
+
fromNumber: string;
|
|
62
|
+
method: string;
|
|
63
|
+
roomId: string;
|
|
64
|
+
rtcToken: string;
|
|
65
|
+
serverUrl: string;
|
|
66
|
+
tenantId: number;
|
|
67
|
+
userId: string;
|
|
68
|
+
} | null;
|
|
69
|
+
/**
|
|
70
|
+
* Interface defining the public API for a CallClient instance.
|
|
71
|
+
* This represents the complete set of methods available for managing real-time voice calls.
|
|
72
|
+
*
|
|
73
|
+
* @interface CallClientInstance
|
|
74
|
+
* @property {Function} createCall - Initiates an outbound call to a specified phone number
|
|
75
|
+
* @property {Function} acceptCall - Accepts an incoming call that was previously initiated
|
|
76
|
+
* @property {Function} endCall - Terminates the currently active call session
|
|
77
|
+
* @property {Function} declineCall - Rejects an incoming call without establishing connection
|
|
78
|
+
* @property {Function} isConnected - Checks the current WebSocket signaling connection status
|
|
79
|
+
* @property {Function} toggleMic - Toggles microphone mute/unmute state during active calls
|
|
80
|
+
* @property {Function} getInboundUserData - Retrieves metadata about the current incoming call
|
|
81
|
+
* @property {Function} on - Registers event listeners for call-related events
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // Create a CallClient instance
|
|
86
|
+
* const callClient = CallClient();
|
|
87
|
+
* const client: CallClientInstance = await callClient.createClient(config);
|
|
88
|
+
*
|
|
89
|
+
* // Set up event listeners
|
|
90
|
+
* client.on('call_init', (direction: string) => {
|
|
91
|
+
* if (direction === 'incoming') {
|
|
92
|
+
* console.log('Incoming call received');
|
|
93
|
+
* // Optionally auto-accept or show UI
|
|
94
|
+
* await client.acceptCall();
|
|
95
|
+
* }
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* client.on('answered', () => {
|
|
99
|
+
* console.log('Call was answered');
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* client.on('hangup', () => {
|
|
103
|
+
* console.log('Call ended');
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // Make an outbound call
|
|
107
|
+
* await client.createCall('+1234567890');
|
|
108
|
+
*
|
|
109
|
+
* // Check connection status
|
|
110
|
+
* if (client.isConnected()) {
|
|
111
|
+
* console.log('Signaling server connected');
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* // Control microphone during call
|
|
115
|
+
* await client.toggleMic(); // Mute
|
|
116
|
+
* await client.toggleMic(); // Unmute
|
|
117
|
+
*
|
|
118
|
+
* // End the call
|
|
119
|
+
* await client.endCall();
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
type CallClientInstance = {
|
|
123
|
+
/**
|
|
124
|
+
* Initiates an outbound call to the specified phone number.
|
|
125
|
+
*
|
|
126
|
+
* @param {string} toPhoneNumber - The destination phone number (e.g., '+1234567890')
|
|
127
|
+
* @returns {Promise<void>} Promise that resolves when call initiation is complete
|
|
128
|
+
* @throws {Error} Throws if signaling server is disconnected or invalid phone number
|
|
129
|
+
*/
|
|
130
|
+
createCall: (toPhoneNumber: string) => Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Accepts an incoming call that was previously initiated.
|
|
133
|
+
* Must be called after receiving a 'call_init' event with direction 'incoming'.
|
|
134
|
+
*
|
|
135
|
+
* @returns {Promise<void>} Promise that resolves when call is successfully accepted
|
|
136
|
+
* @throws {Error} Throws if no incoming call is available or connection fails
|
|
137
|
+
*/
|
|
138
|
+
acceptCall: () => Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Terminates the currently active call session.
|
|
141
|
+
* Can be called during any active call state (incoming, outgoing, or established).
|
|
142
|
+
*
|
|
143
|
+
* @returns {Promise<void>} Promise that resolves when call is successfully ended
|
|
144
|
+
*/
|
|
145
|
+
endCall: () => Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Rejects an incoming call without establishing a connection.
|
|
148
|
+
* Must be called after receiving a 'call_init' event with direction 'incoming'.
|
|
149
|
+
*
|
|
150
|
+
* @returns {Promise<void>} Promise that resolves when call is successfully declined
|
|
151
|
+
*/
|
|
152
|
+
declineCall: () => Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Checks the current WebSocket signaling connection status.
|
|
155
|
+
*
|
|
156
|
+
* @returns {boolean} True if connected to signaling server, false otherwise
|
|
157
|
+
*/
|
|
158
|
+
isConnected: () => boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Toggles the microphone mute state during an active call.
|
|
161
|
+
* If currently muted, will unmute. If currently unmuted, will mute.
|
|
162
|
+
*
|
|
163
|
+
* @returns {Promise<void>} Promise that resolves when microphone state is changed
|
|
164
|
+
* @throws {Error} Throws if no active call or audio device access fails
|
|
165
|
+
*/
|
|
166
|
+
toggleMic: () => Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Retrieves metadata about the current incoming call.
|
|
169
|
+
* Returns null if no incoming call is available.
|
|
170
|
+
*
|
|
171
|
+
* @returns {Promise<InboundUserData>} Promise resolving to call metadata or null
|
|
172
|
+
*/
|
|
173
|
+
getInboundUserData: () => Promise<InboundUserData>;
|
|
174
|
+
/**
|
|
175
|
+
* Registers an event listener for call-related events.
|
|
176
|
+
*
|
|
177
|
+
* Available events:
|
|
178
|
+
* - 'call_init': Fired when call is initiated (payload: 'incoming' | 'outbound')
|
|
179
|
+
* - 'ringing': Fired when remote party is ringing
|
|
180
|
+
* - 'answered': Fired when call is answered by remote party
|
|
181
|
+
* - 'hangup': Fired when call is terminated
|
|
182
|
+
* - 'busy': Fired when remote party is busy
|
|
183
|
+
*
|
|
184
|
+
* @param {string} event - The event name to listen for
|
|
185
|
+
* @param {Function} handler - The callback function to execute when event fires
|
|
186
|
+
* @returns {void}
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* client.on('call_init', (direction: string) => {
|
|
191
|
+
* console.log(`Call initiated: ${direction}`);
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* client.on('answered', () => {
|
|
195
|
+
* console.log('Call answered - conversation started');
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
on: <T = string>(event: string, handler: (payload: T) => void) => void;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Creates a CallClient instance with real-time communication capabilities.
|
|
203
|
+
*
|
|
204
|
+
* This function initializes a complete calling system that handles both inbound and outbound calls,
|
|
205
|
+
* signaling through WebSocket connections, and audio/video communication through WebRTC.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const callClient = CallClient();
|
|
210
|
+
* const client = await callClient.createClient({
|
|
211
|
+
* socketUrl: 'wss://signaling.example.com',
|
|
212
|
+
* socketToken: 'your-auth-token',
|
|
213
|
+
* phoneNumber: '+1234567890',
|
|
214
|
+
* outboundRoom: 'outbound_room_id',
|
|
215
|
+
* inboundRoom: 'inbound_room_id',
|
|
216
|
+
* socketConnectionOptions: {
|
|
217
|
+
* timeout: 5000,
|
|
218
|
+
* autoConnect: true
|
|
219
|
+
* }
|
|
220
|
+
* });
|
|
221
|
+
*
|
|
222
|
+
* // Listen for incoming calls
|
|
223
|
+
* client.on('inbound-call', (callData) => {
|
|
224
|
+
* console.log('Incoming call:', callData);
|
|
225
|
+
* });
|
|
226
|
+
*
|
|
227
|
+
* // Make an outbound call
|
|
228
|
+
* await client.createCall('destination-number');
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
declare function CallClient(): {
|
|
232
|
+
createClient: (config: CallClientConfig) => Promise<{
|
|
233
|
+
createCall: (toPhoneNumber: string) => Promise<void>;
|
|
234
|
+
acceptCall: () => Promise<void>;
|
|
235
|
+
endCall: () => Promise<void>;
|
|
236
|
+
declineCall: () => Promise<void>;
|
|
237
|
+
isConnected: () => boolean;
|
|
238
|
+
toggleMic: () => Promise<void>;
|
|
239
|
+
getInboundUserData: () => Promise<any>;
|
|
240
|
+
on: <T = any>(event: string, handler: (payload: T) => void) => void;
|
|
241
|
+
}>;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export { CallClient, type CallClientConfig, type CallClientInstance, type InboundUserData };
|