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 CHANGED
@@ -1,10 +1,10 @@
1
- # Voxnix Plugin
1
+ # Voxnix
2
2
 
3
- A self-contained Voice Widget Plugin running inside an iframe, built with React, Vite, and Tailwind CSS.
3
+ A React Component SDK for seamless Voice PABX Integration.
4
4
 
5
5
  ## Overview
6
6
 
7
- This widget is designed to be embedded within a parent application (e.g., `wrapper-main`). All WebRTC logic (Yeastar, Flashphoner, Sip.js) runs inside the widget's memory. The parent application only needs to send configuration and credentials via `postMessage`.
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
- ### 1. Embedding the Widget
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, { useEffect, useRef } from 'react';
25
-
26
- const ParentApp = () => {
27
- const widgetRef = useRef(null);
28
-
29
- useEffect(() => {
30
- const handleMessage = (event) => {
31
- // 1. Wait for widget_ready event
32
- if (event.data?.type === 'widget_ready') {
33
- // 2. Send configuration to initialize the widget
34
- widgetRef.current.contentWindow.postMessage({
35
- type: 'init_config',
36
- payload: {
37
- tenantName: "Infomedia",
38
- platform: "sipjs", // Options: "yeastar", "flashphoner", "sipjs"
39
- pabxConfig: {
40
- auth: {
41
- username: "YOUR_USERNAME",
42
- password: "YOUR_PASSWORD",
43
- host: "YOUR_PABX_HOST"
44
- }
45
- }
46
- }
47
- }, '*'); // Replace '*' with target origin in production for security
48
- }
49
-
50
- // Handle call events from widget to parent
51
- if (event.data?.type === 'sync_incoming_call') {
52
- console.log('Incoming call notification');
53
- }
54
- if (event.data?.type === 'sync_call_answered') {
55
- console.log('Call answered');
56
- }
57
- if (event.data?.type === 'sync_call_ended') {
58
- console.log('Call ended');
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
- <iframe
68
- src="http://localhost:5173" // Or your deployed widget URL
69
- ref={widgetRef}
70
- style={{ width: '400px', height: '600px', border: 'none', borderRadius: '8px' }}
71
- allow="microphone; camera"
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 ParentApp;
76
+ export default App;
77
77
  ```
78
78
 
79
- ## Supported Voice Platforms
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
- - **Sip.js**
82
- - **Yeastar**
83
- - **Flashphoner**
92
+ You can access these methods by passing a `ref` to the `Voxnix` component:
84
93
 
85
- ## Message Events Protocol
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
- ### Parent -> Widget
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
- ### Widget -> Parent
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 start the widget locally:
108
+ To run the project locally for development:
99
109
 
100
110
  ```bash
101
111
  yarn install