react-sip-kit 0.5.16 → 0.5.20

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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Shervin Ghajar
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Shervin Ghajar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,212 +1,212 @@
1
- # react-sip-kit
2
-
3
- A modern **React SIP.js toolkit** for building web-based softphones and SIP clients.
4
- Supports **audio/video calls**, **recording**, **screen sharing**, and **device management** — all with a clean, extensible architecture.
5
-
6
- ---
7
-
8
- ## ✨ Features
9
-
10
- * 📞 **Audio & Video Calls** — with automatic device detection
11
- * 🎥 **Video Support** — manage local & remote streams seamlessly
12
- * 🔴 **Call Recording** — audio and video recording out of the box
13
- * 🖥️ **Screen Sharing** — during video calls
14
- * 🎧 **Device Management** — select audio/video input & output devices
15
- * 🔄 **Multi-account & Multi-line Support** — handle multiple SIP accounts and concurrent calls
16
- * ⚡ **TypeScript-first** — fast, modular, type-safe APIs
17
- * 🛠️ **Configurable & Extensible** — tailor to your SIP setup
18
-
19
- ---
20
-
21
- ## 📦 Installation
22
-
23
- ```bash
24
- npm install react-sip-kit
25
- # or
26
- yarn add react-sip-kit
27
- ```
28
-
29
- ---
30
-
31
- ## 🚀 Basic Usage
32
-
33
- ### 1. Initialize a global `SipManager`
34
-
35
- Instead of wrapping your app with a provider, you now create a single `SipManager` instance and add accounts dynamically.
36
-
37
- ```tsx
38
- // main.ts
39
- import App from './App';
40
- import { SipManager } from 'react-sip-kit';
41
- import { StrictMode, useEffect, useState } from 'react';
42
- import { createRoot } from 'react-dom/client';
43
- ------------------------------------------------------------
44
- export const SipConnection = new SipManager(); // Initilizing SipManager
45
- ------------------------------------------------------------
46
- const Providers = () => {
47
- const configs = [{
48
- account: {
49
- domain: 'sip.example.com',
50
- username: '1010',
51
- password: 'password',
52
- wssServer: 'sip.example.com',
53
- webSocketPort: '8089',
54
- serverPath: '/ws',
55
- },
56
- // ...(other configs)
57
- }]
58
-
59
- useEffect(() => {
60
- // Add new configs dynamically
61
- configs.forEach((config) => {
62
- SipConnection.add(config);
63
- });
64
- }, [configs]);
65
-
66
- return (
67
- <StrictMode>
68
- {configs.map((config) => (
69
- <App key={config.account.username} username={config.account.username} />
70
- ))}
71
- </StrictMode>
72
- );
73
- };
74
-
75
- createRoot(document.getElementById('root')!).render(<Providers />);
76
- ```
77
-
78
- ---
79
-
80
- ### 2. Access SIP state and methods (per account)
81
-
82
- Each account is keyed by its **username**.
83
- You can fetch **methods** and **watch state** like this:
84
-
85
- ```tsx
86
- // App.tsx
87
- import { SipConnection } from './main';
88
-
89
- function DialPad({ username }: { username: string }) {
90
- const { dialByNumber } = SipConnection.methods(username);
91
- const { watch } = SipConnection.get(username);
92
- const { lines, status } = watch();
93
-
94
- return (
95
- <>
96
- <h2>
97
- Web Phone {username} — {status}
98
- </h2>
99
- <button onClick={() => dialByNumber('audio', '1012')}>Call 1012</button>
100
- <button onClick={() => dialByNumber('video', '1012')}>Video Call 1012</button>
101
- </>
102
- );
103
- }
104
- ```
105
-
106
- ---
107
-
108
- ### 3. Watch line/session data with `useWatchSessionData`
109
-
110
- For fine-grained updates, subscribe to session fields:
111
-
112
- ```tsx
113
- import { useWatchSessionData } from 'react-sip-kit';
114
-
115
- function RecordingStatus({ lineNumber }: { lineNumber: number }) {
116
- const isRecording = useWatchSessionData({
117
- lineNumber,
118
- name: 'recordMedia.recording',
119
- });
120
-
121
- return <p>Recording: {isRecording ? 'Yes' : 'No'}</p>;
122
- }
123
- ```
124
-
125
- You can also watch multiple fields:
126
-
127
- ```tsx
128
- const [localMediaStreamStatus, isRecording] = useWatchSessionData({
129
- lineNumber: 1,
130
- name: ['localMediaStreamStatus', 'recordMedia.recording'],
131
- });
132
- ```
133
-
134
- ---
135
-
136
- ### 4. Render media streams
137
-
138
- Media components (`<Video/>` & `<Audio/>`) are bound per line:
139
-
140
- ```tsx
141
- import { VideoStream, AudioStream } from 'react-sip-kit';
142
-
143
- <VideoStream type="local" lineNumber={1} />
144
- <VideoStream type="remote" lineNumber={1} />
145
- <AudioStream type="local" lineNumber={1} />
146
- <AudioStream type="remote" lineNumber={1} />
147
- ```
148
-
149
- ---
150
-
151
- ## ⚙️ Configuration
152
-
153
- Each account supports SIP and media options:
154
-
155
- ```ts
156
- {
157
- account: {
158
- domain: 'your.sip.domain',
159
- username: 'user',
160
- password: 'secret',
161
- wssServer: 'your.sip.domain',
162
- webSocketPort: '8089',
163
- serverPath: '/ws',
164
- },
165
- features: { enableVideo: true },
166
- media: {
167
- audioInputDeviceId: 'default',
168
- audioOutputDeviceId: 'default',
169
- videoInputDeviceId: 'default',
170
- },
171
- registration: { registerExpires: 3600 },
172
- }
173
- ```
174
-
175
- ---
176
-
177
- ## 💡 Best Practices
178
-
179
- * Always pass the `username` when calling `SipConnection.methods(username)` or `SipConnection.get(username)`.
180
- * Use `.watch()` for reactive state (`lines`, `status`).
181
- * Use `useWatchSessionData` for **line-specific** updates (mute, hold, video state, recording, etc.).
182
- * Render `<VideoStream>` and `<AudioStream>` **only for active calls**.
183
- * Manage device permissions (mic/camera) upfront.
184
- * If adding accounts dynamically, call `SipConnection.add(config)` for each.
185
-
186
- ---
187
-
188
- ## 🧑‍💻 Full Example
189
-
190
- See the [`/example`](https://github.com/shervin-ghajar/react-sip-kit/tree/main/example) folder for:
191
-
192
- * Multiple SIP accounts in one UI
193
- * Audio & video calls
194
- * Hold, mute, attended transfer
195
- * Call recording & screen sharing
196
- * Local & remote media rendering
197
-
198
- ---
199
-
200
- ## 📄 License
201
-
202
- MIT License
203
-
204
- ---
205
-
206
- ## 👤 Author
207
-
208
- **Shervin Ghajar**
209
-
210
- * GitHub: [@shervin-ghajar](https://github.com/shervin-ghajar)
211
- * NPM: [react-sip-kit](https://www.npmjs.com/package/react-sip-kit)
1
+ # react-sip-kit
2
+
3
+ A modern **React SIP.js toolkit** for building web-based softphones and SIP clients.
4
+ Supports **audio/video calls**, **recording**, **screen sharing**, and **device management** — all with a clean, extensible architecture.
5
+
6
+ ---
7
+
8
+ ## ✨ Features
9
+
10
+ * 📞 **Audio & Video Calls** — with automatic device detection
11
+ * 🎥 **Video Support** — manage local & remote streams seamlessly
12
+ * 🔴 **Call Recording** — audio and video recording out of the box
13
+ * 🖥️ **Screen Sharing** — during video calls
14
+ * 🎧 **Device Management** — select audio/video input & output devices
15
+ * 🔄 **Multi-account & Multi-line Support** — handle multiple SIP accounts and concurrent calls
16
+ * ⚡ **TypeScript-first** — fast, modular, type-safe APIs
17
+ * 🛠️ **Configurable & Extensible** — tailor to your SIP setup
18
+
19
+ ---
20
+
21
+ ## 📦 Installation
22
+
23
+ ```bash
24
+ npm install react-sip-kit
25
+ # or
26
+ yarn add react-sip-kit
27
+ ```
28
+
29
+ ---
30
+
31
+ ## 🚀 Basic Usage
32
+
33
+ ### 1. Initialize a global `SipManager`
34
+
35
+ Instead of wrapping your app with a provider, you now create a single `SipManager` instance and add accounts dynamically.
36
+
37
+ ```tsx
38
+ // main.ts
39
+ import App from './App';
40
+ import { SipManager } from 'react-sip-kit';
41
+ import { StrictMode, useEffect, useState } from 'react';
42
+ import { createRoot } from 'react-dom/client';
43
+ ------------------------------------------------------------
44
+ export const SipConnection = new SipManager(); // Initilizing SipManager
45
+ ------------------------------------------------------------
46
+ const Providers = () => {
47
+ const configs = [{
48
+ account: {
49
+ domain: 'sip.example.com',
50
+ username: '1010',
51
+ password: 'password',
52
+ wssServer: 'sip.example.com',
53
+ webSocketPort: '8089',
54
+ serverPath: '/ws',
55
+ },
56
+ // ...(other configs)
57
+ }]
58
+
59
+ useEffect(() => {
60
+ // Add new configs dynamically
61
+ configs.forEach((config) => {
62
+ SipConnection.add(config);
63
+ });
64
+ }, [configs]);
65
+
66
+ return (
67
+ <StrictMode>
68
+ {configs.map((config) => (
69
+ <App key={config.account.username} username={config.account.username} />
70
+ ))}
71
+ </StrictMode>
72
+ );
73
+ };
74
+
75
+ createRoot(document.getElementById('root')!).render(<Providers />);
76
+ ```
77
+
78
+ ---
79
+
80
+ ### 2. Access SIP state and methods (per account)
81
+
82
+ Each account is keyed by its **username**.
83
+ You can fetch **methods** and **watch state** like this:
84
+
85
+ ```tsx
86
+ // App.tsx
87
+ import { SipConnection } from './main';
88
+
89
+ function App({ username }: { username: string }) {
90
+ const { dialByNumber } = SipConnection.methods(username);
91
+ const { watch } = SipConnection.get(username);
92
+ const { lines, status } = watch();
93
+
94
+ return (
95
+ <>
96
+ <h2>
97
+ Web Phone {username} — {status}
98
+ </h2>
99
+ <button onClick={() => dialByNumber('audio', '1012')}>Call 1012</button>
100
+ <button onClick={() => dialByNumber('video', '1012')}>Video Call 1012</button>
101
+ </>
102
+ );
103
+ }
104
+ ```
105
+
106
+ ---
107
+
108
+ ### 3. Watch line/session data with `useWatchSessionData`
109
+
110
+ For fine-grained updates, subscribe to session fields:
111
+
112
+ ```tsx
113
+ import { useWatchSessionData } from 'react-sip-kit';
114
+
115
+ function RecordingStatus({ lineNumber }: { lineNumber: number }) {
116
+ const isRecording = useWatchSessionData({
117
+ lineNumber,
118
+ name: 'recordMedia.recording',
119
+ });
120
+
121
+ return <p>Recording: {isRecording ? 'Yes' : 'No'}</p>;
122
+ }
123
+ ```
124
+
125
+ You can also watch multiple fields:
126
+
127
+ ```tsx
128
+ const [localMediaStreamStatus, isRecording] = useWatchSessionData({
129
+ lineNumber: 1,
130
+ name: ['localMediaStreamStatus', 'recordMedia.recording'],
131
+ });
132
+ ```
133
+
134
+ ---
135
+
136
+ ### 4. Render media streams
137
+
138
+ Media components (`<Video/>` & `<Audio/>`) are bound per line:
139
+
140
+ ```tsx
141
+ import { VideoStream, AudioStream } from 'react-sip-kit';
142
+
143
+ <VideoStream type="local" lineNumber={1} />
144
+ <VideoStream type="remote" lineNumber={1} />
145
+ <AudioStream type="local" lineNumber={1} />
146
+ <AudioStream type="remote" lineNumber={1} />
147
+ ```
148
+
149
+ ---
150
+
151
+ ## ⚙️ Configuration
152
+
153
+ Each account supports SIP and media options:
154
+
155
+ ```ts
156
+ {
157
+ account: {
158
+ domain: 'your.sip.domain',
159
+ username: 'user',
160
+ password: 'secret',
161
+ wssServer: 'your.sip.domain',
162
+ webSocketPort: '8089',
163
+ serverPath: '/ws',
164
+ },
165
+ features: { enableVideo: true },
166
+ media: {
167
+ audioInputDeviceId: 'default',
168
+ audioOutputDeviceId: 'default',
169
+ videoInputDeviceId: 'default',
170
+ },
171
+ registration: { registerExpires: 3600 },
172
+ }
173
+ ```
174
+
175
+ ---
176
+
177
+ ## 💡 Best Practices
178
+
179
+ * Always pass the `username` when calling `SipConnection.methods(username)` or `SipConnection.get(username)`.
180
+ * Use `.watch()` for reactive state (`lines`, `status`).
181
+ * Use `useWatchSessionData` for **line-specific** updates (mute, hold, video state, recording, etc.).
182
+ * Render `<VideoStream>` and `<AudioStream>` **only for active calls**.
183
+ * Manage device permissions (mic/camera) upfront.
184
+ * If adding accounts dynamically, call `SipConnection.add(config)` for each.
185
+
186
+ ---
187
+
188
+ ## 🧑‍💻 Full Example
189
+
190
+ See the [`/example`](https://github.com/shervin-ghajar/react-sip-kit/tree/main/example) folder for:
191
+
192
+ * Multiple SIP accounts in one UI
193
+ * Audio & video calls
194
+ * Hold, mute, attended transfer
195
+ * Call recording & screen sharing
196
+ * Local & remote media rendering
197
+
198
+ ---
199
+
200
+ ## 📄 License
201
+
202
+ MIT License
203
+
204
+ ---
205
+
206
+ ## 👤 Author
207
+
208
+ **Shervin Ghajar**
209
+
210
+ * GitHub: [@shervin-ghajar](https://github.com/shervin-ghajar)
211
+ * NPM: [react-sip-kit](https://www.npmjs.com/package/react-sip-kit)
212
212
  * Repository: [react-sip-kit](https://github.com/shervin-ghajar/react-sip-kit)