@dora-cell/sdk-react 0.1.1-beta.3 → 0.1.1-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,10 +5,9 @@ React hooks and components for the Dora Cell VoIP SDK.
5
5
  ## Features
6
6
 
7
7
  ✅ **React Hooks** - Easy-to-use hooks for call management
8
- ✅ **Context Provider** - Simple setup with DoraCellProvider
9
- ✅ **TypeScript support** - Full type definitions included
10
- ✅ **Auto state management** - Automatic call state and connection tracking
11
- ✅ **React 18 & 19 compatible** - Works with latest React versions
8
+ ✅ **Context Provider** - Simple setup with `DoraCellProvider`
9
+ ✅ **Pre-built UI** - Includes `Dialpad` and `CallInterface` components
10
+ ✅ **Auto state management** - Automatic call state and connection tracking
12
11
 
13
12
  ## Installation
14
13
 
@@ -25,284 +24,117 @@ pnpm add @dora-cell/sdk @dora-cell/sdk-react jssip
25
24
  ### 1. Wrap your app with DoraCellProvider
26
25
 
27
26
  ```tsx
28
- import { DoraCellProvider } from '@dora-cell/sdk-react';
27
+ import { DoraCellProvider } from "@dora-cell/sdk-react";
29
28
 
30
29
  function App() {
31
30
  return (
32
31
  <DoraCellProvider
33
32
  config={{
34
33
  auth: {
35
- type: 'api-token',
36
- apiToken: 'your-api-token-here',
37
- apiBaseUrl: 'https://api.usedora.com'
34
+ type: "extension",
35
+ extension: "1001",
38
36
  },
39
- debug: true
37
+ debug: true,
40
38
  }}
39
+ autoInitialize={true}
41
40
  >
42
- <YourApp />
41
+ <MainApp />
43
42
  </DoraCellProvider>
44
43
  );
45
44
  }
46
45
  ```
47
46
 
48
- ### 2. Use hooks in your components
47
+ ### 2. Use Hooks in your components
49
48
 
50
49
  ```tsx
51
- import { useCall, useConnectionStatus } from '@dora-cell/sdk-react';
52
-
53
- function CallInterface() {
54
- const {
55
- call,
56
- hangup,
57
- toggleMute,
58
- callStatus,
59
- callDuration,
60
- isMuted,
61
- currentCall
62
- } = useCall();
63
-
64
- const { isConnected, status } = useConnectionStatus();
65
- const [number, setNumber] = useState('');
66
-
67
- const handleCall = async () => {
68
- try {
69
- await call(number);
70
- } catch (error) {
71
- console.error('Call failed:', error);
72
- }
73
- };
50
+ import { useCall, useConnectionStatus } from "@dora-cell/sdk-react";
51
+
52
+ function CallManager() {
53
+ const { call, callStatus, callDuration } = useCall();
54
+ const { isConnected } = useConnectionStatus();
74
55
 
75
56
  return (
76
57
  <div>
77
- <p>Status: {isConnected ? 'Connected' : 'Disconnected'}</p>
78
-
79
- {callStatus === 'idle' && (
80
- <>
81
- <input
82
- value={number}
83
- onChange={(e) => setNumber(e.target.value)}
84
- placeholder="Enter phone number"
85
- />
86
- <button onClick={handleCall} disabled={!isConnected}>
87
- Call
88
- </button>
89
- </>
90
- )}
91
-
92
- {callStatus === 'ongoing' && (
93
- <>
94
- <p>Call with: {currentCall?.remoteNumber}</p>
95
- <p>Duration: {callDuration}</p>
96
- <button onClick={toggleMute}>
97
- {isMuted ? 'Unmute' : 'Mute'}
98
- </button>
99
- <button onClick={hangup}>Hang Up</button>
100
- </>
101
- )}
102
-
103
- {callStatus === 'ringing' && (
104
- <p>Ringing...</p>
105
- )}
58
+ <p>Status: {isConnected ? "Ready" : "Connecting..."}</p>
59
+ {callStatus === "ongoing" && <p>Talking: {callDuration}</p>}
60
+ <button onClick={() => call("08012345678")} disabled={!isConnected}>
61
+ Call Now
62
+ </button>
106
63
  </div>
107
64
  );
108
65
  }
109
66
  ```
110
67
 
111
- ## API Reference
112
-
113
- ### DoraCellProvider
114
-
115
- Wrap your app with this provider to enable SDK functionality.
116
-
117
- ```tsx
118
- <DoraCellProvider
119
- config={{
120
- auth: {
121
- type: 'api-token',
122
- apiToken: string,
123
- apiBaseUrl?: string
124
- },
125
- turnServers?: RTCIceServer[],
126
- debug?: boolean,
127
- autoSelectExtension?: boolean
128
- }}
129
- >
130
- {children}
131
- </DoraCellProvider>
132
- ```
133
-
134
- ### useCall()
135
-
136
- Hook for managing calls.
137
-
138
- ```typescript
139
- const {
140
- // Methods
141
- call: (phoneNumber: string) => Promise<void>,
142
- hangup: () => void,
143
- answerCall: () => void,
144
- toggleMute: () => void,
145
-
146
- // State
147
- callStatus: 'idle' | 'ringing' | 'ongoing',
148
- callDuration: string, // Formatted as "MM:SS"
149
- isMuted: boolean,
150
- currentCall: Call | null,
151
- error: Error | null
152
- } = useCall();
153
- ```
154
-
155
- **Methods:**
156
- - `call(phoneNumber)` - Make an outbound call
157
- - `hangup()` - End the current call
158
- - `answerCall()` - Answer an incoming call
159
- - `toggleMute()` - Toggle mute/unmute
160
-
161
- **State:**
162
- - `callStatus` - Current call status
163
- - `callDuration` - Formatted call duration (e.g., "01:23")
164
- - `isMuted` - Whether the call is muted
165
- - `currentCall` - Current call object with details
166
- - `error` - Any call-related errors
167
-
168
- ### useConnectionStatus()
169
-
170
- Hook for monitoring connection status.
171
-
172
- ```typescript
173
- const {
174
- isConnected: boolean,
175
- status: 'disconnected' | 'connecting' | 'connected' | 'error',
176
- error: Error | null
177
- } = useConnectionStatus();
178
- ```
179
-
180
- ### useDoraCell()
181
-
182
- Access the underlying SDK instance directly.
183
-
184
- ```typescript
185
- const sdk = useDoraCell();
186
-
187
- // Use SDK methods directly
188
- sdk.getExtensions();
189
- sdk.on('call:incoming', (call) => {
190
- console.log('Incoming call from:', call.remoteNumber);
191
- });
192
- ```
193
-
194
- ## Advanced Usage
68
+ ## UI Components
195
69
 
196
- ### Handling Incoming Calls
70
+ We provide high-level components that match the Dora Cell design language.
197
71
 
198
- ```tsx
199
- function IncomingCallHandler() {
200
- const { currentCall, answerCall, hangup, callStatus } = useCall();
201
- const sdk = useDoraCell();
202
-
203
- useEffect(() => {
204
- const handleIncoming = (call) => {
205
- // Show notification or UI for incoming call
206
- console.log('Incoming call from:', call.remoteNumber);
207
- };
208
-
209
- sdk.on('call:incoming', handleIncoming);
210
- return () => sdk.off('call:incoming', handleIncoming);
211
- }, [sdk]);
212
-
213
- if (callStatus === 'ringing' && currentCall?.direction === 'inbound') {
214
- return (
215
- <div>
216
- <p>Incoming call from {currentCall.remoteNumber}</p>
217
- <button onClick={answerCall}>Answer</button>
218
- <button onClick={hangup}>Decline</button>
219
- </div>
220
- );
221
- }
222
-
223
- return null;
224
- }
225
- ```
72
+ ### `CallInterface`
226
73
 
227
- ### Custom Extension Selection
74
+ A slide-over interface that handles the entire call lifecycle (Ringing, Connecting, Ongoing, Mute controls).
228
75
 
229
76
  ```tsx
230
- function CallWithExtension() {
231
- const sdk = useDoraCell();
232
- const [selectedExtension, setSelectedExtension] = useState('');
77
+ import { CallInterface } from "@dora-cell/sdk-react";
233
78
 
234
- const extensions = sdk.getExtensions();
235
-
236
- const makeCall = async (number: string) => {
237
- await sdk.call(number, { extension: selectedExtension });
238
- };
79
+ function Dashboard() {
80
+ const [isOpen, setIsOpen] = useState(false);
239
81
 
240
82
  return (
241
- <div>
242
- <select
243
- value={selectedExtension}
244
- onChange={(e) => setSelectedExtension(e.target.value)}
245
- >
246
- {extensions.map(ext => (
247
- <option key={ext} value={ext}>{ext}</option>
248
- ))}
249
- </select>
250
- {/* Rest of your call UI */}
251
- </div>
83
+ <>
84
+ {/* This should be rendered globally to handle incoming calls */}
85
+ <CallInterface isOpen={isOpen} onOpenChange={setIsOpen} />
86
+ </>
252
87
  );
253
88
  }
254
89
  ```
255
90
 
256
- ### Error Handling
91
+ ### `Dialpad`
92
+
93
+ A flexible keypad for entering numbers and initiating calls.
257
94
 
258
95
  ```tsx
259
- function CallWithErrorHandling() {
260
- const { call, error, callStatus } = useCall();
261
- const [number, setNumber] = useState('');
262
-
263
- const handleCall = async () => {
264
- try {
265
- await call(number);
266
- } catch (err) {
267
- console.error('Call failed:', err);
268
- // Show error to user
269
- }
270
- };
96
+ import { Dialpad } from "@dora-cell/sdk-react";
271
97
 
98
+ function DialerModal() {
272
99
  return (
273
- <div>
274
- {error && <div className="error">{error.message}</div>}
275
- {/* Rest of your UI */}
276
- </div>
100
+ <Dialpad
101
+ showKeys={true}
102
+ onCallInitiated={(number) => console.log("Placing call to:", number)}
103
+ />
277
104
  );
278
105
  }
279
106
  ```
280
107
 
281
- ## TypeScript Support
108
+ ## API Reference
282
109
 
283
- All hooks and components are fully typed. Import types as needed:
110
+ ### `useCall()`
284
111
 
285
- ```typescript
286
- import type { Call, CallStatus, ConnectionStatus } from '@dora-cell/sdk';
287
- import type { DoraCellConfig } from '@dora-cell/sdk-react';
288
- ```
112
+ Returns methods and state for the active call.
289
113
 
290
- ## Examples
114
+ - `call(number)`: Initiate a call.
115
+ - `hangup()`: End current call.
116
+ - `answerCall()`: Answer incoming call.
117
+ - `toggleMute()`: Toggle microphone.
118
+ - `callStatus`: `'idle' | 'connecting' | 'ringing' | 'ongoing' | 'ended'`.
119
+ - `callDuration`: Formatted string `"00:00"`.
120
+ - `isMuted`: Boolean state.
291
121
 
292
- See the `/examples` directory in the main repository for complete working examples:
293
- - `react-app/` - React application with hooks
294
- - `nextjs-app/` - Next.js application
122
+ ### `useConnectionStatus()`
295
123
 
296
- ## Requirements
124
+ Returns the SIP registration state.
297
125
 
298
- - React 18.0.0 or higher (including React 19)
299
- - @dora-cell/sdk (peer dependency)
300
- - jssip (peer dependency)
126
+ - `isConnected`: `true` when registered and ready.
127
+ - `connectionStatus`: `'disconnected' | 'connecting' | 'connected' | 'registered' | 'registrationFailed'`.
128
+ - `error`: Any connection error object.
301
129
 
302
- ## License
130
+ ## Styling
303
131
 
304
- MIT
132
+ The components use Tailwind CSS internally. You can import our styles in your main entry file:
305
133
 
306
- ## Related Packages
134
+ ```javascript
135
+ import "@dora-cell/sdk-react/dist/styles.css";
136
+ ```
137
+
138
+ ## License
307
139
 
308
- - [@dora-cell/sdk](https://www.npmjs.com/package/@dora-cell/sdk) - Core VoIP SDK
140
+ MIT
package/dist/index.d.mts CHANGED
@@ -2,6 +2,29 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
3
  import { DoraCellConfig, CallStatus, Call, ConnectionStatus, DoraCell } from '@dora-cell/sdk';
4
4
 
5
+ interface CallInterfaceProps {
6
+ isOpen?: boolean;
7
+ onOpenChange?: (open: boolean) => void;
8
+ onCallEnded?: () => void;
9
+ maximizeIcon?: React.ReactNode;
10
+ minimizeIcon?: React.ReactNode;
11
+ }
12
+ declare function CallInterface({ isOpen, onOpenChange, onCallEnded, maximizeIcon, minimizeIcon, }: CallInterfaceProps): react_jsx_runtime.JSX.Element | null;
13
+
14
+ interface DialpadProps {
15
+ onCallInitiated?: (number: string) => void;
16
+ initialNumber?: string;
17
+ showKeys?: boolean;
18
+ className?: string;
19
+ availableExtensions?: Array<{
20
+ label: string;
21
+ value: string;
22
+ }>;
23
+ selectedExtension?: string;
24
+ onExtensionChange?: (ext: string) => void;
25
+ }
26
+ declare function Dialpad({ onCallInitiated, initialNumber, showKeys, className, availableExtensions, selectedExtension, onExtensionChange, }: DialpadProps): react_jsx_runtime.JSX.Element;
27
+
5
28
  interface DoraCellContextValue {
6
29
  sdk: DoraCell | null;
7
30
  connectionStatus: ConnectionStatus;
@@ -33,10 +56,12 @@ declare function useCall(): {
33
56
  call: (phoneNumber: string, extension?: string) => Promise<void>;
34
57
  hangup: () => void;
35
58
  toggleMute: () => void;
59
+ answerCall: () => void;
36
60
  callStatus: CallStatus;
37
61
  callDuration: string;
38
62
  isMuted: boolean;
39
63
  currentCall: Call | null;
64
+ callError: string | undefined;
40
65
  };
41
66
  /**
42
67
  * Hook for connection status
@@ -48,4 +73,4 @@ declare function useConnectionStatus(): {
48
73
  error: Error | null;
49
74
  };
50
75
 
51
- export { DoraCellProvider, type DoraCellProviderProps, useCall, useConnectionStatus, useDoraCell };
76
+ export { CallInterface, Dialpad, DoraCellProvider, type DoraCellProviderProps, useCall, useConnectionStatus, useDoraCell };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,29 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
3
  import { DoraCellConfig, CallStatus, Call, ConnectionStatus, DoraCell } from '@dora-cell/sdk';
4
4
 
5
+ interface CallInterfaceProps {
6
+ isOpen?: boolean;
7
+ onOpenChange?: (open: boolean) => void;
8
+ onCallEnded?: () => void;
9
+ maximizeIcon?: React.ReactNode;
10
+ minimizeIcon?: React.ReactNode;
11
+ }
12
+ declare function CallInterface({ isOpen, onOpenChange, onCallEnded, maximizeIcon, minimizeIcon, }: CallInterfaceProps): react_jsx_runtime.JSX.Element | null;
13
+
14
+ interface DialpadProps {
15
+ onCallInitiated?: (number: string) => void;
16
+ initialNumber?: string;
17
+ showKeys?: boolean;
18
+ className?: string;
19
+ availableExtensions?: Array<{
20
+ label: string;
21
+ value: string;
22
+ }>;
23
+ selectedExtension?: string;
24
+ onExtensionChange?: (ext: string) => void;
25
+ }
26
+ declare function Dialpad({ onCallInitiated, initialNumber, showKeys, className, availableExtensions, selectedExtension, onExtensionChange, }: DialpadProps): react_jsx_runtime.JSX.Element;
27
+
5
28
  interface DoraCellContextValue {
6
29
  sdk: DoraCell | null;
7
30
  connectionStatus: ConnectionStatus;
@@ -33,10 +56,12 @@ declare function useCall(): {
33
56
  call: (phoneNumber: string, extension?: string) => Promise<void>;
34
57
  hangup: () => void;
35
58
  toggleMute: () => void;
59
+ answerCall: () => void;
36
60
  callStatus: CallStatus;
37
61
  callDuration: string;
38
62
  isMuted: boolean;
39
63
  currentCall: Call | null;
64
+ callError: string | undefined;
40
65
  };
41
66
  /**
42
67
  * Hook for connection status
@@ -48,4 +73,4 @@ declare function useConnectionStatus(): {
48
73
  error: Error | null;
49
74
  };
50
75
 
51
- export { DoraCellProvider, type DoraCellProviderProps, useCall, useConnectionStatus, useDoraCell };
76
+ export { CallInterface, Dialpad, DoraCellProvider, type DoraCellProviderProps, useCall, useConnectionStatus, useDoraCell };