voxnix 1.0.1 → 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
@@ -4,7 +4,7 @@ A React Component SDK for seamless Voice PABX Integration.
4
4
 
5
5
  ## Overview
6
6
 
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.
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,13 +16,15 @@ yarn add voxnix
16
16
 
17
17
  ## Usage
18
18
 
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.
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.
20
20
 
21
21
  ```jsx
22
- import React, { useState } from 'react';
22
+ import React, { useRef } from 'react';
23
23
  import { Voxnix } from 'voxnix';
24
24
 
25
25
  const App = () => {
26
+ const voxnixRef = useRef(null);
27
+
26
28
  const pabxConfig = {
27
29
  auth: {
28
30
  username: "YOUR_USERNAME",
@@ -33,6 +35,8 @@ const App = () => {
33
35
 
34
36
  const handleIncomingCall = (callData) => {
35
37
  console.log('Incoming call notification:', callData);
38
+ // You can answer programmatically
39
+ // voxnixRef.current.answer();
36
40
  };
37
41
 
38
42
  const handleCallAnswered = () => {
@@ -47,12 +51,18 @@ const App = () => {
47
51
  console.log('PABX Registration Status:', status); // "REGISTERED" | "FAILED"
48
52
  };
49
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();
58
+
50
59
  return (
51
60
  <div style={{ padding: '20px' }}>
52
61
  <h1>Voice Integration App</h1>
53
62
 
54
63
  {/* Voxnix Voice Engine & UI Component */}
55
64
  <Voxnix
65
+ ref={voxnixRef}
56
66
  config={pabxConfig}
57
67
  onIncomingCall={handleIncomingCall}
58
68
  onCallAnswered={handleCallAnswered}
@@ -77,6 +87,22 @@ export default App;
77
87
  | `onCallUnanswered` | `Function` | Callback triggered when an incoming call is not answered. |
78
88
  | `onRegisterStatus` | `Function` | Callback triggered when the PABX registration status changes. |
79
89
 
90
+ ## Ref API (Call Controls)
91
+
92
+ You can access these methods by passing a `ref` to the `Voxnix` component:
93
+
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. |
101
+
102
+ ## Media Handling (Sip.js)
103
+
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.
105
+
80
106
  ## Development
81
107
 
82
108
  To run the project locally for development: