react-sip-kit 0.2.3 โ†’ 0.3.62

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,105 +1,144 @@
1
- # react-sip-kit
2
-
3
- A modern, modular, and type-safe SIP (Session Initiation Protocol) provider for React applications.
4
- Built for real-time web telephony, this library offers a clean, scalable, and fully configurable SIP core, decoupled from UI and legacy global state.
5
-
6
- ---
7
-
8
- ## Features
9
-
10
- - ๐Ÿ“ž **SIP Core**: Register, make, receive, and manage SIP calls (audio & video)
11
- - ๐Ÿ”„ **Transfer & Conference**: Supports call transfer and conferencing
12
- - ๐ŸŽฅ **Video Call Support**: Video call features with device selection
13
- - ๐Ÿ”” **Ringtone & Notifications**: Customizable audio output for ringtones and notifications
14
- - ๐Ÿ‘ฅ **Buddy/Contact Management**: Manage contacts (buddies) and pass contact data across sessions
15
- - โš™๏ธ **Fully Configurable**: All settings (account, features, media, UI, etc.) are passed as propsโ€”no global state or localStorage dependencies
16
- - ๐Ÿงฉ **Type-Safe & Modular**: Strong TypeScript types, modular config, and easy to extend
17
- - ๐Ÿงช **Testable**: Stateless SIP core, easy to mock and test
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
- ## Usage
32
-
33
- ```tsx
34
- import { SipProvider } from 'react-sip-kit';
35
-
36
- <SipProvider
37
- configs={{
38
- account: {
39
- username: 'user',
40
- password: 'password',
41
- domain: 'sip.example.com',
42
- wssServer: 'wss.example.com',
43
- webSocketPort: 7443,
44
- serverPath: '/ws',
45
- },
46
- features: {
47
- enableVideo: true,
48
- enableRingtone: true,
49
- },
50
- // Add or override other config sections as needed
51
- }}
52
- >
53
- {/* Your app components */}
54
- </SipProvider>;
55
- ```
56
-
57
- ---
58
-
59
- ## Configuration
60
-
61
- All configuration is passed via the `configs` prop.
62
- See [`src/configs/types.ts`](src/configs/types.ts) for the full config structure.
63
-
64
- **Example config:**
65
-
66
- ```ts
67
- {
68
- account: { ... },
69
- features: { ... },
70
- media: { ... },
71
- // ...other sections
72
- }
73
- ```
74
-
75
- You can import and extend the default config:
76
-
77
- ```ts
78
- import { defaultSipConfigs } from 'react-sip-kit/configs';
79
- ```
80
-
81
- ---
82
-
83
- ## API
84
-
85
- - **`<SipProvider configs={...}>`**
86
- Provides SIP context and manages SIP sessions for your app.
87
-
88
- - **Context hooks**
89
- Use React context or custom hooks to access SIP state, session methods, and events.
90
-
91
- ---
92
-
93
- ## License
94
-
95
- MIT
96
-
97
- ---
98
-
99
- ## Author
100
-
101
- **Shervin Ghajar**
102
- [GitHub](https://github.com/shervin-ghajar)
103
- Email: ssghajar.work@gmail.com
104
-
105
- ---
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-line Support** โ€” handle multiple 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. Wrap your app with `SipProvider`
34
+
35
+ ```tsx
36
+ import { SipProvider } from 'react-sip-kit';
37
+
38
+ <SipProvider
39
+ configs={{
40
+ account: {
41
+ domain: 'your.sip.domain',
42
+ username: 'your-username',
43
+ password: 'your-password',
44
+ wssServer: 'your.sip.domain',
45
+ webSocketPort: '8089',
46
+ serverPath: '/ws',
47
+ },
48
+ }}
49
+ >
50
+ <App />
51
+ </SipProvider>
52
+ ```
53
+
54
+ ---
55
+
56
+ ### 2. Make calls with hooks
57
+
58
+ ```tsx
59
+ import { useSipProvider, useSessionMethods } from 'react-sip-kit';
60
+
61
+ function DialPad() {
62
+ const { status } = useSipProvider();
63
+ const { dialByNumber } = useSessionMethods();
64
+
65
+ return (
66
+ <>
67
+ <p>Status: {status}</p>
68
+ <button onClick={() => dialByNumber('audio', '1012')}>Call 1012</button>
69
+ <button onClick={() => dialByNumber('video', '1012')}>Video Call 1012</button>
70
+ </>
71
+ );
72
+ }
73
+ ```
74
+
75
+ ---
76
+
77
+ ### 3. Render media streams
78
+
79
+ ```tsx
80
+ import { VideoStream, AudioStream } from 'react-sip-kit';
81
+
82
+ <VideoStream type="local" lineNumber={1} />
83
+ <VideoStream type="remote" lineNumber={1} />
84
+ <AudioStream type="local" lineNumber={1} />
85
+ <AudioStream type="remote" lineNumber={1} />
86
+ ```
87
+
88
+ ---
89
+
90
+ ## โš™๏ธ Configuration
91
+
92
+ All SIP and media settings can be customized via the `configs` prop.
93
+ See [types.ts](https://github.com/shervin-ghajar/react-sip-kit/blob/main/src/configs/types.ts) for the full options.
94
+
95
+ ```ts
96
+ {
97
+ account: { ... },
98
+ features: { enableVideo: true },
99
+ media: { audioInputDeviceId: 'default' },
100
+ registration: { registerExpires: 3600 },
101
+ }
102
+ ```
103
+
104
+ ---
105
+
106
+ ## ๐Ÿ’ก Best Practices
107
+
108
+ * Use hooks (`useSipProvider`, `useSessionMethods`) for SIP state & actions.
109
+ * Render media components only for active calls.
110
+ * Handle device permissions and selection gracefully.
111
+ * Reinitialize streams with `initiateRemoteMediaStreams` or `initiateLocalMediaStreams` if `<video>`/`<audio>` is rendered after the call starts.
112
+ * Prefer TypeScript for better DX and safety.
113
+
114
+ ---
115
+
116
+ ## ๐Ÿง‘โ€๐Ÿ’ป Full Example
117
+
118
+ A full working demo (with call controls, transfer, hold, recording, etc.) is available in the
119
+ [`/example`](https://github.com/shervin-ghajar/react-sip-kit/tree/main/example) folder of this repo.
120
+
121
+ This example demonstrates:
122
+
123
+ * Multi-line SIP handling
124
+ * Answering/rejecting calls
125
+ * Call transfer, hold, mute
126
+ * Recording and screen sharing
127
+ * Local/remote audio & video streams
128
+
129
+ ---
130
+
131
+ ## ๐Ÿ“„ License
132
+
133
+ MIT License
134
+
135
+ ---
136
+
137
+ ## ๐Ÿ‘ค Author
138
+
139
+ **Shervin Ghajar**
140
+
141
+ * GitHub: [@shervin-ghajar](https://github.com/shervin-ghajar)
142
+ * NPM: [react-sip-kit](https://www.npmjs.com/package/react-sip-kit)
143
+ * Repository: [react-sip-kit](https://github.com/shervin-ghajar/react-sip-kit)
144
+
@@ -1,7 +1,15 @@
1
- import { AudioHTMLAttributes } from 'react';
2
- interface AudioProps extends AudioHTMLAttributes<HTMLAudioElement> {
1
+ import { AudioHTMLAttributes, HTMLAttributes } from 'react';
2
+ interface DefaultAudioProps {
3
3
  lineNumber: string | number;
4
- type?: 'transfer' | 'conference';
5
4
  }
6
- export declare const Audio: ({ lineNumber, type, ...rest }: AudioProps) => import("react/jsx-runtime").JSX.Element;
5
+ interface LocalAudioProps extends AudioHTMLAttributes<HTMLAudioElement>, DefaultAudioProps {
6
+ type: 'local';
7
+ id?: `line-${number}-${LocalAudioProps['type']}Audio`;
8
+ }
9
+ interface RemoteAudioProps extends HTMLAttributes<HTMLDivElement>, DefaultAudioProps {
10
+ type: 'remote';
11
+ id?: `line-${number}-remoteAudios`;
12
+ }
13
+ type AudioProps = LocalAudioProps | RemoteAudioProps;
14
+ export declare const Audio: ({ lineNumber, ...rest }: AudioProps) => import("react/jsx-runtime").JSX.Element;
7
15
  export {};
@@ -4,9 +4,11 @@ interface DefaultVideoProps {
4
4
  }
5
5
  interface LocalVideoProps extends VideoHTMLAttributes<HTMLVideoElement>, DefaultVideoProps {
6
6
  type: 'local';
7
+ id?: `line-${number}-${LocalVideoProps['type']}Video` | `line-${number}-remoteVideos`;
7
8
  }
8
9
  interface RemoteVidepProps extends HTMLAttributes<HTMLDivElement>, DefaultVideoProps {
9
10
  type: 'remote';
11
+ id?: `line-${number}-${RemoteVidepProps['type']}Video` | `line-${number}-remoteVideos`;
10
12
  }
11
13
  type VideoProps = LocalVideoProps | RemoteVidepProps;
12
14
  export declare const Video: ({ lineNumber, ...rest }: VideoProps) => import("react/jsx-runtime").JSX.Element;
@@ -36,8 +36,8 @@ export interface SipAdvancedConfig {
36
36
  chatEngine: string;
37
37
  }
38
38
  export interface SipRecordingConfig {
39
- videoResampleSize: string;
40
- recordingVideoSize: string;
39
+ videoResampleSize: 'HD' | 'FHD';
40
+ recordingVideoSize: 'HD' | 'FHD';
41
41
  recordingVideoFps: number;
42
42
  recordingLayout: string;
43
43
  }
@@ -1,10 +1,9 @@
1
1
  import { LineType, SipInvitationType } from '../store/types';
2
- export declare class Line<T extends Partial<object>> implements LineType<T> {
2
+ export declare class Line implements LineType {
3
3
  lineNumber: number;
4
4
  displayNumber: string;
5
- metaData: Partial<T>;
6
5
  sipSession: SipInvitationType | null;
7
6
  localSoundMeter: any;
8
7
  remoteSoundMeter: any;
9
- constructor(lineNumber: number, displayNumber: string, metaData: T);
8
+ constructor(lineNumber: number, displayNumber: string);
10
9
  }
@@ -1,5 +1,5 @@
1
1
  import { SipUserAgent } from '../../types';
2
- export declare function onTransportConnected(userAgent?: SipUserAgent): void;
3
- export declare function onTransportConnectError(error: any, userAgent?: SipUserAgent): void;
2
+ export declare function onTransportConnected(userAgent?: SipUserAgent | undefined): void;
3
+ export declare function onTransportConnectError(error: Error, userAgent?: SipUserAgent | undefined): void;
4
4
  export declare function onTransportDisconnected(userAgent: SipUserAgent): void;
5
- export declare function reconnectTransport(userAgent?: SipUserAgent): void;
5
+ export declare function reconnectTransport(userAgent?: SipUserAgent | undefined): void;
@@ -0,0 +1,10 @@
1
+ export declare const useGetMediaDevices: () => {
2
+ getDevices: () => Promise<{
3
+ hasAudioDevice: boolean;
4
+ audioInputDevices: MediaDeviceInfo[];
5
+ hasSpeakerDevice: boolean;
6
+ speakerDevices: MediaDeviceInfo[];
7
+ hasVideoDevice: boolean;
8
+ videoInputDevices: MediaDeviceInfo[];
9
+ }>;
10
+ };
@@ -4,7 +4,7 @@ import { Bye, Message } from 'sip.js';
4
4
  import { IncomingRequestMessage, IncomingResponse } from 'sip.js/lib/core';
5
5
  export declare const useSessionEvents: () => {
6
6
  onInviteCancel: (lineObj: LineType, response: IncomingRequestMessage, callback?: CallbackFunction<any>) => void;
7
- onInviteAccepted: (lineObj: LineType, includeVideo: boolean, response?: IncomingResponse) => void;
7
+ onInviteAccepted: (lineObj: LineType, videoEnabled: boolean, response?: IncomingResponse) => Promise<void>;
8
8
  onInviteTrying: (lineObj: LineType, response: IncomingResponse) => void;
9
9
  onInviteProgress: (lineObj: LineType, response: IncomingResponse) => void;
10
10
  onInviteRejected: (lineObj: LineType, response: IncomingResponse, callback?: CallbackFunction<any>) => void;
@@ -13,6 +13,6 @@ export declare const useSessionEvents: () => {
13
13
  onSessionReinvited: (lineObj: LineType, response: IncomingRequestMessage) => void;
14
14
  onSessionReceivedMessage: (lineObj: LineType, response: Message) => void;
15
15
  onSessionDescriptionHandlerCreated: (lineObj: LineType, sdh: SipSessionDescriptionHandler, provisional: boolean, includeVideo?: boolean) => void;
16
- onTrackAddedEvent: (lineObj: LineType, includeVideo?: boolean) => void;
16
+ onTrackAddedEvent: (lineObj: LineType, videoEnabled?: boolean) => Promise<void>;
17
17
  onTransferSessionDescriptionHandlerCreated: (lineObj: LineType, session: SipSessionType, sdh: SipSessionDescriptionHandler, includeVideo?: boolean) => void;
18
18
  };
@@ -1,17 +1,23 @@
1
1
  import { LineType, SipInvitationType } from '../../store/types';
2
+ import { CallType } from '../../types';
2
3
  export declare const useSessionMethods: () => {
3
- receiveCall: (session: SipInvitationType) => void;
4
+ receiveSession: (invitation: SipInvitationType) => void;
4
5
  answerAudioSession: (lineNumber: LineType["lineNumber"]) => void;
5
- answerVideoSession: (lineNumber: LineType["lineNumber"]) => void;
6
+ answerVideoSession: (lineNumber: LineType["lineNumber"], enableVideo?: boolean) => void;
6
7
  makeAudioSession: (lineObj: LineType, dialledNumber: string, extraHeaders?: Array<string>) => void;
7
8
  makeVideoSession: (lineObj: LineType, dialledNumber: string, extraHeaders?: Array<string>) => void;
8
- rejectCall: (lineNumber: LineType["lineNumber"]) => void;
9
- dialByLine: (type: "audio" | "video", dialNumber: string, metaData?: object, extraHeaders?: Array<string>) => void;
9
+ toggleLocalVideoTrack: (lineNumber: LineType["lineNumber"]) => Promise<void>;
10
+ toggleShareScreen: (lineNumber: LineType["lineNumber"]) => Promise<void>;
11
+ rejectSession: (lineNumber: LineType["lineNumber"]) => void;
12
+ dialByNumber: (type: Extract<CallType, "audio" | "video">, dialNumber: string, extraHeaders?: Array<string>) => void;
13
+ makeConferenceSession: (lineObj: LineType, extraHeaders?: Array<string>) => void;
10
14
  endSession: (lineNumber: LineType["lineNumber"]) => void;
11
- holdSession: (lineNumber: LineType["lineNumber"]) => void;
12
- unholdSession: (lineNumber: LineType["lineNumber"]) => void;
13
- muteSession: (lineNumber: LineType["lineNumber"]) => void;
14
- unmuteSession: (lineNumber: LineType["lineNumber"]) => void;
15
+ recordSession: (lineNumber: LineType["lineNumber"]) => {
16
+ start: () => Promise<void>;
17
+ stop: () => void;
18
+ };
19
+ toggleMuteSession: (lineNumber: LineType["lineNumber"]) => void;
20
+ toggleHoldSession: (lineNumber: LineType["lineNumber"], forcedValue?: boolean) => Promise<void>;
15
21
  cancelSession: (lineNumber: LineType["lineNumber"]) => void;
16
22
  startTransferSession: (lineNumber: LineType["lineNumber"]) => void;
17
23
  cancelTransferSession: (lineNumber: LineType["lineNumber"]) => void;