voxnix 1.0.0

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 ADDED
@@ -0,0 +1,109 @@
1
+ # Voxnix Plugin
2
+
3
+ A self-contained Voice Widget Plugin running inside an iframe, built with React, Vite, and Tailwind CSS.
4
+
5
+ ## Overview
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`.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install voxnix
13
+ # or
14
+ yarn add voxnix
15
+ ```
16
+
17
+ ## Usage
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`.
22
+
23
+ ```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
+ }, []);
65
+
66
+ 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
+ />
73
+ );
74
+ };
75
+
76
+ export default ParentApp;
77
+ ```
78
+
79
+ ## Supported Voice Platforms
80
+
81
+ - **Sip.js**
82
+ - **Yeastar**
83
+ - **Flashphoner**
84
+
85
+ ## Message Events Protocol
86
+
87
+ ### Parent -> Widget
88
+ - `init_config`: Sent from parent to widget. Contains credentials (`tenantName`, `platform`, `pabxConfig: { auth: { username, password, host } }`).
89
+
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.
95
+
96
+ ## Development
97
+
98
+ To start the widget locally:
99
+
100
+ ```bash
101
+ yarn install
102
+ yarn dev
103
+ ```
104
+
105
+ To build for production:
106
+
107
+ ```bash
108
+ yarn build
109
+ ```