voxnix 1.0.0 → 1.0.2
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 +77 -67
- package/dist/voxnix.js +2748 -2654
- package/dist/voxnix.umd.cjs +34 -31
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# Voxnix
|
|
1
|
+
# Voxnix
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A React Component SDK for seamless Voice PABX Integration.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Voxnix is a ready-to-use SDK designed to quickly integrate voice and PABX calling features into your React applications. It provides a self-contained dialer UI and automatically handles voice engine connectivity, including remote media stream attachment and cleanup for Sip.js.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -16,86 +16,96 @@ yarn add voxnix
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Embed the widget using an iframe in your React parent application. The communication protocol uses `window.postMessage`.
|
|
19
|
+
You can use the `Voxnix` component directly in your React application. Pass the required PABX configuration credentials through the `config` prop and use the event callbacks to listen for call states. You can also use a React `ref` to imperatively control the call (e.g., answer, hold, mute, hangup) from your parent component.
|
|
22
20
|
|
|
23
21
|
```jsx
|
|
24
|
-
import React, {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
window.addEventListener('message', handleMessage);
|
|
63
|
-
return () => window.removeEventListener('message', handleMessage);
|
|
64
|
-
}, []);
|
|
22
|
+
import React, { useRef } from 'react';
|
|
23
|
+
import { Voxnix } from 'voxnix';
|
|
24
|
+
|
|
25
|
+
const App = () => {
|
|
26
|
+
const voxnixRef = useRef(null);
|
|
27
|
+
|
|
28
|
+
const pabxConfig = {
|
|
29
|
+
auth: {
|
|
30
|
+
username: "YOUR_USERNAME",
|
|
31
|
+
password: "YOUR_PASSWORD",
|
|
32
|
+
host: "YOUR_PABX_HOST" // e.g., sip.example.com
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const handleIncomingCall = (callData) => {
|
|
37
|
+
console.log('Incoming call notification:', callData);
|
|
38
|
+
// You can answer programmatically
|
|
39
|
+
// voxnixRef.current.answer();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const handleCallAnswered = () => {
|
|
43
|
+
console.log('Call has been answered');
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const handleCallEnded = () => {
|
|
47
|
+
console.log('Call has ended');
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handleRegisterStatus = (status) => {
|
|
51
|
+
console.log('PABX Registration Status:', status); // "REGISTERED" | "FAILED"
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Example Call Controls
|
|
55
|
+
const toggleMute = (isMuted) => voxnixRef.current?.mute(isMuted);
|
|
56
|
+
const toggleHold = (isOnHold, setIsOnHold) => voxnixRef.current?.hold(isOnHold, setIsOnHold);
|
|
57
|
+
const endCall = () => voxnixRef.current?.hangup();
|
|
65
58
|
|
|
66
59
|
return (
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
<div style={{ padding: '20px' }}>
|
|
61
|
+
<h1>Voice Integration App</h1>
|
|
62
|
+
|
|
63
|
+
{/* Voxnix Voice Engine & UI Component */}
|
|
64
|
+
<Voxnix
|
|
65
|
+
ref={voxnixRef}
|
|
66
|
+
config={pabxConfig}
|
|
67
|
+
onIncomingCall={handleIncomingCall}
|
|
68
|
+
onCallAnswered={handleCallAnswered}
|
|
69
|
+
onCallEnded={handleCallEnded}
|
|
70
|
+
onRegisterStatus={handleRegisterStatus}
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
73
|
);
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
export default
|
|
76
|
+
export default App;
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
##
|
|
79
|
+
## Component Props
|
|
80
|
+
|
|
81
|
+
| Prop | Type | Description |
|
|
82
|
+
|------|------|-------------|
|
|
83
|
+
| `config` | `Object` | Configuration object containing `auth` credentials (`username`, `password`, `host`). |
|
|
84
|
+
| `onIncomingCall` | `Function` | Callback triggered when there is an incoming call. |
|
|
85
|
+
| `onCallAnswered` | `Function` | Callback triggered when the call is answered. |
|
|
86
|
+
| `onCallEnded` | `Function` | Callback triggered when the call ends. |
|
|
87
|
+
| `onCallUnanswered` | `Function` | Callback triggered when an incoming call is not answered. |
|
|
88
|
+
| `onRegisterStatus` | `Function` | Callback triggered when the PABX registration status changes. |
|
|
89
|
+
|
|
90
|
+
## Ref API (Call Controls)
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
- **Yeastar**
|
|
83
|
-
- **Flashphoner**
|
|
92
|
+
You can access these methods by passing a `ref` to the `Voxnix` component:
|
|
84
93
|
|
|
85
|
-
|
|
94
|
+
| Method | Parameters | Description |
|
|
95
|
+
|--------|------------|-------------|
|
|
96
|
+
| `answer()` | - | Answers an incoming call. |
|
|
97
|
+
| `reject()` | - | Rejects an incoming call. |
|
|
98
|
+
| `hangup()` | - | Ends the current active call. |
|
|
99
|
+
| `mute(isMuted)` | `isMuted: boolean` | Mutes or unmutes the local microphone. |
|
|
100
|
+
| `hold(isOnHold, setIsOnHold)` | `isOnHold: boolean, setIsOnHold: function` | Puts the call on hold or resumes it. Passes `setIsOnHold` to allow the SDK to asynchronously update the parent UI state when the re-INVITE succeeds. |
|
|
86
101
|
|
|
87
|
-
|
|
88
|
-
- `init_config`: Sent from parent to widget. Contains credentials (`tenantName`, `platform`, `pabxConfig: { auth: { username, password, host } }`).
|
|
102
|
+
## Media Handling (Sip.js)
|
|
89
103
|
|
|
90
|
-
|
|
91
|
-
- `widget_ready`: Emitted when the React lifecycle of the widget is mounted, requesting `init_config` from the parent.
|
|
92
|
-
- `sync_incoming_call`: Emitted to the parent when there is an incoming call (for desktop/native notifications).
|
|
93
|
-
- `sync_call_answered`: Emitted when the call is answered.
|
|
94
|
-
- `sync_call_ended`: Emitted when the call ends.
|
|
104
|
+
Voxnix handles remote media setup automatically. When a call state becomes `Established`, Voxnix will attach the incoming audio stream to an invisible `<audio id="voxnix-remote-audio" />` element. When the call is terminated, the media is safely cleaned up.
|
|
95
105
|
|
|
96
106
|
## Development
|
|
97
107
|
|
|
98
|
-
To
|
|
108
|
+
To run the project locally for development:
|
|
99
109
|
|
|
100
110
|
```bash
|
|
101
111
|
yarn install
|