@vanira/sdk-react-native 0.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.
Files changed (148) hide show
  1. package/README.md +239 -0
  2. package/package.json +53 -0
  3. package/src/__tests__/WebRTCClient.integration.test.ts +396 -0
  4. package/src/__tests__/adapters.test.ts +475 -0
  5. package/src/__tests__/httpResponse.test.ts +25 -0
  6. package/src/__tests__/mocks/react-native-incall-manager.ts +8 -0
  7. package/src/__tests__/mocks/react-native-permissions.ts +15 -0
  8. package/src/__tests__/mocks/react-native-webrtc.ts +6 -0
  9. package/src/__tests__/mocks/react-native.ts +28 -0
  10. package/src/__tests__/preset.test.ts +239 -0
  11. package/src/__tests__/resolveRuntimeConfig.test.ts +90 -0
  12. package/src/__tests__/storage.test.ts +211 -0
  13. package/src/__tests__/webrtcSignaling.test.ts +42 -0
  14. package/src/adapters/PeerConnectionAdapter.ts +101 -0
  15. package/src/adapters/browser/BrowserAudioAdapter.ts +43 -0
  16. package/src/adapters/browser/BrowserDataChannelAdapter.ts +69 -0
  17. package/src/adapters/browser/BrowserMediaAdapter.ts +15 -0
  18. package/src/adapters/browser/BrowserPeerAdapter.ts +14 -0
  19. package/src/adapters/browser/index.ts +4 -0
  20. package/src/adapters/interfaces.ts +84 -0
  21. package/src/adapters/react-native/RNAudioAdapter.ts +42 -0
  22. package/src/adapters/react-native/RNDataChannelAdapter.ts +79 -0
  23. package/src/adapters/react-native/RNMediaAdapter.ts +46 -0
  24. package/src/adapters/react-native/RNPeerAdapter.ts +28 -0
  25. package/src/adapters/react-native/callAudioRouting.ts +115 -0
  26. package/src/adapters/react-native/decodeUtf8.ts +72 -0
  27. package/src/adapters/react-native/index.ts +4 -0
  28. package/src/adapters/react-native/rnUploadFile.ts +76 -0
  29. package/src/adapters/storage/BrowserDualStorageAdapter.ts +71 -0
  30. package/src/adapters/storage/MemoryStorageAdapter.ts +50 -0
  31. package/src/adapters/storage/StorageAdapter.ts +21 -0
  32. package/src/adapters/storage/createSyncStorageAdapter.ts +40 -0
  33. package/src/adapters/storage/index.ts +7 -0
  34. package/src/api/services/ChatService.ts +304 -0
  35. package/src/api/services/ConfigService.ts +33 -0
  36. package/src/assets/icons.js +35 -0
  37. package/src/cdn.ts +68 -0
  38. package/src/core/CallSessionStore.ts +137 -0
  39. package/src/core/DraggableController.ts +83 -0
  40. package/src/core/SessionManager.ts +322 -0
  41. package/src/core/VaniraAI.ts +464 -0
  42. package/src/core/WebRTCClient.ts +1012 -0
  43. package/src/core/httpResponse.ts +22 -0
  44. package/src/core/iceServers.ts +18 -0
  45. package/src/core/toolCallNormalize.ts +80 -0
  46. package/src/core/voice-client.js +236 -0
  47. package/src/core/webrtcSignaling.ts +72 -0
  48. package/src/index.js +34 -0
  49. package/src/index.ts +6 -0
  50. package/src/platforms/browser.ts +67 -0
  51. package/src/platforms/react-native.ts +105 -0
  52. package/src/presets/BookingCalendarModal.tsx +457 -0
  53. package/src/presets/CameraModal.tsx +576 -0
  54. package/src/presets/DynamicFormModal.tsx +378 -0
  55. package/src/presets/NativePresetRenderer.tsx +350 -0
  56. package/src/presets/NavigateHandler.tsx +75 -0
  57. package/src/presets/PresetHost.tsx +155 -0
  58. package/src/presets/PresetShellModal.tsx +97 -0
  59. package/src/presets/UploadModal.tsx +321 -0
  60. package/src/presets/calendar/calendarUtils.ts +386 -0
  61. package/src/presets/call/CallSpeakerToggle.tsx +59 -0
  62. package/src/presets/call/callAudioRouting.ts +2 -0
  63. package/src/presets/call/useCallSpeaker.ts +31 -0
  64. package/src/presets/camera/cameraPermissions.ts +18 -0
  65. package/src/presets/camera/cameraStream.ts +19 -0
  66. package/src/presets/camera/cameraUtils.ts +21 -0
  67. package/src/presets/camera/useLivenessFlow.ts +95 -0
  68. package/src/presets/chalkboard/ChalkboardOverlay.tsx +156 -0
  69. package/src/presets/chalkboard/EraseTextHandler.tsx +95 -0
  70. package/src/presets/chalkboard/TypeTextHandler.tsx +107 -0
  71. package/src/presets/chalkboard/boardAbort.ts +36 -0
  72. package/src/presets/chalkboard/boardQueue.ts +620 -0
  73. package/src/presets/chalkboard/chalkboardSession.ts +75 -0
  74. package/src/presets/chalkboard/drawUtils.ts +123 -0
  75. package/src/presets/chalkboard/textUtils.ts +109 -0
  76. package/src/presets/clipRegion/ClipRegionModal.tsx +261 -0
  77. package/src/presets/clipRegion/clipRegionBridge.ts +19 -0
  78. package/src/presets/form/formValidation.ts +104 -0
  79. package/src/presets/form/parseFormFields.ts +171 -0
  80. package/src/presets/host/HostElementPresetHandler.tsx +155 -0
  81. package/src/presets/host/hostPresetBridge.ts +71 -0
  82. package/src/presets/index.ts +63 -0
  83. package/src/presets/liveScreen/CloseLiveScreenHandler.tsx +36 -0
  84. package/src/presets/liveScreen/LiveScreenCaptureHost.tsx +312 -0
  85. package/src/presets/liveScreen/LiveScreenHandler.tsx +25 -0
  86. package/src/presets/liveScreen/LiveScreenPipOverlay.tsx +6 -0
  87. package/src/presets/liveScreen/liveScreenSession.ts +73 -0
  88. package/src/presets/liveVision/CloseLiveVisionHandler.tsx +29 -0
  89. package/src/presets/liveVision/LiveVisionCameraHost.tsx +317 -0
  90. package/src/presets/liveVision/LiveVisionHandler.tsx +26 -0
  91. package/src/presets/liveVision/LiveVisionPipOverlay.tsx +7 -0
  92. package/src/presets/liveVision/liveVisionFrameLoop.ts +38 -0
  93. package/src/presets/liveVision/liveVisionSession.ts +75 -0
  94. package/src/presets/liveVision/liveVisionUpload.ts +62 -0
  95. package/src/presets/navigation/internalRouteRegistry.ts +25 -0
  96. package/src/presets/navigation/navigationBridge.ts +76 -0
  97. package/src/presets/navigation/navigationTypes.ts +12 -0
  98. package/src/presets/parseToolCall.ts +60 -0
  99. package/src/presets/presetClientAdapter.ts +29 -0
  100. package/src/presets/presetCompletion.ts +91 -0
  101. package/src/presets/presetEventHelpers.ts +45 -0
  102. package/src/presets/registry.ts +128 -0
  103. package/src/presets/streaming/mediaFrameUpload.ts +93 -0
  104. package/src/presets/types.ts +74 -0
  105. package/src/presets/upload/pickUploadFile.ts +256 -0
  106. package/src/presets/upload/uploadFormats.ts +163 -0
  107. package/src/presets/upload/uploadUtils.ts +68 -0
  108. package/src/react/PresetRenderer.tsx +144 -0
  109. package/src/react/index.ts +1 -0
  110. package/src/runtime/browserRuntime.ts +54 -0
  111. package/src/runtime/platform.ts +17 -0
  112. package/src/runtime/reactNativeRuntime.ts +68 -0
  113. package/src/runtime/resolveRuntimeConfig.ts +75 -0
  114. package/src/runtime/runtimeBundles.ts +74 -0
  115. package/src/runtime/types.ts +135 -0
  116. package/src/types/react-native-incall-manager.d.ts +17 -0
  117. package/src/types/react-native-webrtc.d.ts +47 -0
  118. package/src/types.ts +133 -0
  119. package/src/ui/VaniraWidget.ts +87 -0
  120. package/src/ui/abstraction/AbstractWidgetProvider.ts +18 -0
  121. package/src/ui/abstraction/interfaces.ts +12 -0
  122. package/src/ui/adapters/VaniraChatAdapter.ts +42 -0
  123. package/src/ui/components/AvatarView.ts +81 -0
  124. package/src/ui/components/ChatWindow.ts +263 -0
  125. package/src/ui/components/FloatingButton.ts +163 -0
  126. package/src/ui/components/FloatingWelcomeChips.ts +137 -0
  127. package/src/ui/components/Panel.ts +120 -0
  128. package/src/ui/components/VoiceOrb.ts +79 -0
  129. package/src/ui/components/VoiceOverlay.ts +497 -0
  130. package/src/ui/components/index.ts +7 -0
  131. package/src/ui/factory/WidgetFactory.ts +16 -0
  132. package/src/ui/icons_data.ts +2 -0
  133. package/src/ui/presets/WidgetPresetRenderer.ts +1802 -0
  134. package/src/ui/presets/types.ts +16 -0
  135. package/src/ui/providers/VaniraInternalProvider.ts +1066 -0
  136. package/src/ui/styles/index.ts +323 -0
  137. package/src/ui/styles/keyframes.ts +76 -0
  138. package/src/ui/styles/theme.ts +57 -0
  139. package/src/ui/styles/widget.css.ts +838 -0
  140. package/src/ui/utils.ts +37 -0
  141. package/src/ui/views/AbstractChatView.ts +93 -0
  142. package/src/ui/views/AbstractVoiceView.ts +57 -0
  143. package/src/ui/views/AvatarOnlyView.ts +78 -0
  144. package/src/ui/views/ChatAvatarView.ts +66 -0
  145. package/src/ui/views/ChatOnlyView.ts +28 -0
  146. package/src/ui/views/ChatVoiceView.ts +15 -0
  147. package/src/ui/views/VoiceOnlyView.ts +25 -0
  148. package/src/ui/views/index.ts +5 -0
@@ -0,0 +1,497 @@
1
+
2
+ import { icons } from '../styles';
3
+
4
+ export class VoiceOverlay {
5
+ private element: HTMLDivElement;
6
+
7
+ // Layout
8
+ private contentContainer: HTMLDivElement;
9
+
10
+ // Orb / visual
11
+ private orbWrapper: HTMLDivElement; // w-52 h-52 centered circle area
12
+ private connectingRing: HTMLDivElement; // spinning conic-gradient ring (connecting)
13
+ private errorRing: HTMLDivElement; // red ring (error)
14
+ private waveLayers: HTMLDivElement[] = []; // active wave layers
15
+ private outerGlow: HTMLDivElement;
16
+ private wave1: HTMLDivElement;
17
+ private wave2: HTMLDivElement;
18
+ private wave3: HTMLDivElement;
19
+ private centerIcon: HTMLDivElement; // dark circle with phone/spinner
20
+
21
+ // Status area
22
+ private statusArea: HTMLDivElement;
23
+ private connectingLabel: HTMLDivElement;
24
+ private connectedBadge: HTMLDivElement;
25
+ private errorLabel: HTMLDivElement;
26
+ private giveItAMinuteLabel: HTMLDivElement;
27
+ private retryBtn: HTMLButtonElement;
28
+ private timerEl: HTMLDivElement;
29
+
30
+ // Transcription
31
+ private transcriptionEl: HTMLDivElement;
32
+
33
+ // Footer
34
+ private hangupBtn: HTMLButtonElement;
35
+
36
+ // Avatar
37
+ private videoContainer: HTMLDivElement;
38
+ private videoElement: HTMLVideoElement;
39
+ private prepareBadge: HTMLDivElement;
40
+ private statusBadge: HTMLDivElement;
41
+
42
+ private startTime: number | null = null;
43
+ private timerInterval: any = null;
44
+ private isAvatarMode: boolean = false;
45
+ private callStartedAt: number | null = null; // wall-clock ms when call started
46
+
47
+ constructor(
48
+ private onHangup: () => void,
49
+ private primaryColor: string = '#000000',
50
+ private secondaryColor: string = '#111111',
51
+ private onCallEnded?: (durationMs: number, startedAt: number) => void
52
+ ) {
53
+ // ── ROOT ────────────────────────────────────────────────────────────────
54
+ this.element = document.createElement('div');
55
+ this.element.id = 'voice-active-overlay';
56
+ this.element.style.cssText = `
57
+ position: absolute; top: 0; left: 0; width: 100%; height: 100%;
58
+ background: #f9fafb;
59
+ pointer-events: auto;
60
+ z-index: 60;
61
+ display: none;
62
+ flex-direction: column;
63
+ align-items: center;
64
+ `;
65
+
66
+ // ── CONTENT AREA ────────────────────────────────────────────────────────
67
+ this.contentContainer = document.createElement('div');
68
+ this.contentContainer.className = 'voice-content-container';
69
+ this.contentContainer.style.cssText = `
70
+ flex: 1; min-height: 0; display: flex; flex-direction: column;
71
+ align-items: center; justify-content: center;
72
+ width: 100%; padding: 24px 20px 12px;
73
+ `;
74
+
75
+ // ── AVATAR VIDEO ─────────────────────────────────────────────────────────
76
+ this.videoContainer = document.createElement('div');
77
+ this.videoContainer.className = 'voice-video-container';
78
+ this.videoContainer.style.cssText = `
79
+ display: none; position: relative; width: 100%; max-width: 260px;
80
+ aspect-ratio: 1/1; margin-bottom: 16px; overflow: hidden;
81
+ border-radius: 16px;
82
+ box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25), 0 0 0 1px rgba(17,24,39,0.05);
83
+ `;
84
+ this.videoElement = document.createElement('video');
85
+ this.videoElement.style.cssText = 'width:100%; height:100%; object-fit:cover; background:black;';
86
+ this.videoElement.autoplay = true;
87
+ this.videoElement.playsInline = true;
88
+ this.videoElement.muted = true;
89
+ this.videoContainer.appendChild(this.videoElement);
90
+ this.contentContainer.appendChild(this.videoContainer);
91
+
92
+ // ── ORB WRAPPER ──────────────────────────────────────────────────────────
93
+ this.orbWrapper = document.createElement('div');
94
+ this.orbWrapper.className = 'voice-orb-wrapper';
95
+ this.orbWrapper.style.cssText = `
96
+ position: relative; width: 208px; height: 208px;
97
+ display: flex; align-items: center; justify-content: center;
98
+ margin: 8px 0;
99
+ `;
100
+
101
+ // Connecting: spinning conic-gradient ring
102
+ this.connectingRing = document.createElement('div');
103
+ this.connectingRing.style.cssText = `
104
+ position: absolute; width: 180px; height: 180px;
105
+ border-radius: 50%;
106
+ background: conic-gradient(from 0deg, #000000, #374151, #000000);
107
+ animation: spin 2s linear infinite;
108
+ display: none;
109
+ `;
110
+ this.orbWrapper.appendChild(this.connectingRing);
111
+
112
+ // Error: red conic ring
113
+ this.errorRing = document.createElement('div');
114
+ this.errorRing.style.cssText = `
115
+ position: absolute; width: 180px; height: 180px;
116
+ border-radius: 50%;
117
+ background: conic-gradient(from 0deg, #ef4444, #f87171, #fca5a5, #ef4444);
118
+ animation: pulse 1.5s ease-in-out infinite;
119
+ display: none;
120
+ `;
121
+ this.orbWrapper.appendChild(this.errorRing);
122
+
123
+ // Wave layers (connected state)
124
+ this.outerGlow = document.createElement('div');
125
+ this.outerGlow.style.cssText = `
126
+ position: absolute; inset: 0; border-radius: 50%;
127
+ background: radial-gradient(circle, ${this.primaryColor}20 0%, transparent 70%);
128
+ animation: pulse 2s ease-in-out infinite;
129
+ display: none;
130
+ `;
131
+ this.orbWrapper.appendChild(this.outerGlow);
132
+
133
+ this.wave1 = document.createElement('div');
134
+ this.wave1.style.cssText = `
135
+ position: absolute; width: 200px; height: 200px; border-radius: 50%;
136
+ background: conic-gradient(from 0deg, ${this.primaryColor}, ${this.secondaryColor}, #fcd34d, ${this.primaryColor});
137
+ animation: wave-rotate-1 8s ease-in-out infinite;
138
+ display: none;
139
+ `;
140
+ this.orbWrapper.appendChild(this.wave1);
141
+
142
+ this.wave2 = document.createElement('div');
143
+ this.wave2.style.cssText = `
144
+ position: absolute; width: 180px; height: 180px; border-radius: 50%;
145
+ background: conic-gradient(from 60deg, ${this.secondaryColor}, #fcd34d, ${this.primaryColor}, ${this.secondaryColor});
146
+ opacity: 0.8;
147
+ animation: wave-rotate-2 6s ease-in-out infinite;
148
+ display: none;
149
+ `;
150
+ this.orbWrapper.appendChild(this.wave2);
151
+
152
+ this.wave3 = document.createElement('div');
153
+ this.wave3.style.cssText = `
154
+ position: absolute; width: 160px; height: 160px; border-radius: 50%;
155
+ background: conic-gradient(from 120deg, #fcd34d, ${this.primaryColor}, ${this.secondaryColor}, #fcd34d);
156
+ opacity: 0.9;
157
+ animation: wave-rotate-3 4s ease-in-out infinite;
158
+ display: none;
159
+ `;
160
+ this.orbWrapper.appendChild(this.wave3);
161
+
162
+ // Inner shine (connected only)
163
+ const shine = document.createElement('div');
164
+ shine.style.cssText = `
165
+ position: absolute; width: 140px; height: 140px; border-radius: 50%;
166
+ background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.4) 0%, transparent 60%);
167
+ display: none; pointer-events: none;
168
+ `;
169
+ shine.id = 'voice-shine';
170
+ this.orbWrapper.appendChild(shine);
171
+
172
+ this.waveLayers = [this.outerGlow, this.wave1, this.wave2, this.wave3, shine];
173
+
174
+ // Center dark circle with phone/spinner icon
175
+ this.centerIcon = document.createElement('div');
176
+ this.centerIcon.style.cssText = `
177
+ position: relative; z-index: 10;
178
+ width: 56px; height: 56px; border-radius: 50%;
179
+ display: flex; align-items: center; justify-content: center;
180
+ background: #374151;
181
+ box-shadow: 0 10px 25px -5px rgba(0,0,0,0.15), 0 8px 10px -6px rgba(0,0,0,0.1);
182
+ color: white;
183
+ `;
184
+ this.centerIcon.innerHTML = icons.phone;
185
+ const phoneSvg = this.centerIcon.querySelector('svg');
186
+ if (phoneSvg) { phoneSvg.style.width = '20px'; phoneSvg.style.height = '20px'; }
187
+ this.orbWrapper.appendChild(this.centerIcon);
188
+
189
+ this.contentContainer.appendChild(this.orbWrapper);
190
+
191
+ // ── STATUS AREA ──────────────────────────────────────────────────────────
192
+ this.statusArea = document.createElement('div');
193
+ this.statusArea.className = 'voice-status-area';
194
+ this.statusArea.style.cssText = 'display:flex; flex-direction:column; align-items:center; gap:8px; margin-top:8px;';
195
+
196
+ // Connecting label
197
+ this.connectingLabel = document.createElement('p');
198
+ this.connectingLabel.textContent = 'Connecting to Vanira...';
199
+ this.connectingLabel.style.cssText = 'font-size:11px; font-weight:700; color:#374151; text-transform:uppercase; letter-spacing:0.1em; margin:0; display:none;';
200
+ this.statusArea.appendChild(this.connectingLabel);
201
+
202
+ // Give it a minute label
203
+ this.giveItAMinuteLabel = document.createElement('p');
204
+ this.giveItAMinuteLabel.textContent = 'Give it a minute';
205
+ this.giveItAMinuteLabel.style.cssText = 'font-size:9px; font-weight:500; color:#94a3b8; text-transform:uppercase; letter-spacing:0.15em; margin:0; display:none; animation:pulse 1.5s infinite;';
206
+ this.statusArea.appendChild(this.giveItAMinuteLabel);
207
+
208
+ // Connected badge
209
+ this.connectedBadge = document.createElement('div');
210
+ this.connectedBadge.style.cssText = `
211
+ display: none; align-items: center; gap: 8px;
212
+ padding: 5px 16px; background: #f0fdf4;
213
+ border-radius: 9999px; border: 1px solid #dcfce7;
214
+ `;
215
+ const greenDot = document.createElement('div');
216
+ greenDot.style.cssText = 'width:8px; height:8px; border-radius:50%; background:#22c55e; flex-shrink:0; padding:0 !important; animation:pulse 2s infinite; box-shadow:0 0 8px rgba(34,197,94,0.6);';
217
+ const connectedText = document.createElement('span');
218
+ connectedText.textContent = 'Connected';
219
+ connectedText.style.cssText = 'font-size:11px; font-weight:600; color:#15803d; text-transform:uppercase; letter-spacing:0.1em;';
220
+ this.connectedBadge.appendChild(greenDot);
221
+ this.connectedBadge.appendChild(connectedText);
222
+ this.statusArea.appendChild(this.connectedBadge);
223
+
224
+ // Timer
225
+ this.timerEl = document.createElement('div');
226
+ this.timerEl.textContent = '00:00';
227
+ this.timerEl.style.cssText = 'font-size:13px; color:#6b7280; font-variant-numeric:tabular-nums; display:none;';
228
+ this.statusArea.appendChild(this.timerEl);
229
+
230
+ // Error label + retry
231
+ this.errorLabel = document.createElement('p');
232
+ this.errorLabel.textContent = 'Connection failed';
233
+ this.errorLabel.style.cssText = 'font-size:12px; color:#ef4444; font-weight:500; margin:0; display:none;';
234
+ this.statusArea.appendChild(this.errorLabel);
235
+
236
+ this.retryBtn = document.createElement('button');
237
+ this.retryBtn.textContent = '↻ Retry Connection';
238
+ this.retryBtn.style.cssText = `
239
+ display:none; padding:6px 14px; background:#f3f4f6; border:none;
240
+ border-radius:9999px; font-size:12px; font-weight:500; color:#374151;
241
+ cursor:pointer; transition:background 0.2s; pointer-events:auto;
242
+ `;
243
+ this.retryBtn.onmouseover = () => this.retryBtn.style.background = '#e5e7eb';
244
+ this.retryBtn.onmouseout = () => this.retryBtn.style.background = '#f3f4f6';
245
+ this.statusArea.appendChild(this.retryBtn);
246
+
247
+ // Avatar preparing / connected badges
248
+ this.prepareBadge = document.createElement('p');
249
+ this.prepareBadge.style.cssText = 'display:none; font-size:11px; font-weight:600; color:#a855f7; text-transform:uppercase; letter-spacing:0.1em; margin:0; animation:pulse 1.5s infinite;';
250
+ this.statusArea.appendChild(this.prepareBadge);
251
+
252
+ this.statusBadge = document.createElement('div');
253
+ this.statusBadge.style.cssText = 'display:none; align-items:center; gap:8px; padding:5px 16px; background:#f0fdf4; border-radius:9999px; border:1px solid #dcfce7;';
254
+ const sDot = document.createElement('div');
255
+ sDot.style.cssText = 'width:8px; height:8px; border-radius:50%; background:#22c55e; flex-shrink:0; padding:0 !important; animation:pulse 2s infinite;';
256
+ const sTxt = document.createElement('span');
257
+ sTxt.textContent = 'Connected';
258
+ sTxt.style.cssText = 'font-size:11px; font-weight:600; color:#15803d; text-transform:uppercase; letter-spacing:0.1em;';
259
+ this.statusBadge.appendChild(sDot);
260
+ this.statusBadge.appendChild(sTxt);
261
+ this.statusArea.appendChild(this.statusBadge);
262
+
263
+ this.contentContainer.appendChild(this.statusArea);
264
+
265
+ // ── TRANSCRIPTION ────────────────────────────────────────────────────────
266
+ this.transcriptionEl = document.createElement('div');
267
+ this.transcriptionEl.className = 'voice-transcription';
268
+ this.transcriptionEl.style.cssText = `
269
+ margin-top: 14px; padding: 0 20px; text-align: center;
270
+ min-height: 36px; max-height: 72px; overflow-y: auto;
271
+ font-size: 13px; color: #9ca3af; font-style: italic;
272
+ `;
273
+ this.contentContainer.appendChild(this.transcriptionEl);
274
+
275
+ this.element.appendChild(this.contentContainer);
276
+
277
+ // ── FOOTER: always-on End Call ───────────────────────────────────────────
278
+ const footer = document.createElement('div');
279
+ footer.className = 'voice-footer';
280
+ footer.style.cssText = 'width:100%; display:flex; justify-content:center; padding:0 20px 20px; pointer-events:auto;';
281
+
282
+ this.hangupBtn = document.createElement('button');
283
+ this.hangupBtn.className = 'voice-hangup-btn';
284
+ this.hangupBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="transform:rotate(135deg);flex-shrink:0;"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.69 12a19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 3.6 1.18h3a2 2 0 0 1 2 1.72c.127.96.361 1.903.7 2.81a2 2 0 0 1-.45 2.11L7.91 8.77a16 16 0 0 0 6.29 6.29l.87-.87a2 2 0 0 1 2.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0 1 22 16.92z"/></svg> End Call`;
285
+ this.hangupBtn.style.cssText = `
286
+ display: flex; align-items: center; gap: 8px;
287
+ padding: 10px 28px; background: #ef4444; color: white;
288
+ border: none; border-radius: 9999px; font-size: 14px; font-weight: 500;
289
+ cursor: pointer; pointer-events: auto;
290
+ transition: background-color 0.2s;
291
+ box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
292
+ `;
293
+ this.hangupBtn.onmouseover = () => this.hangupBtn.style.backgroundColor = '#dc2626';
294
+ this.hangupBtn.onmouseout = () => this.hangupBtn.style.backgroundColor = '#ef4444';
295
+ this.hangupBtn.onclick = () => {
296
+ const duration = this.callStartedAt ? Date.now() - this.callStartedAt : 0;
297
+ const startedAt = this.callStartedAt ?? Date.now();
298
+ if (this.onCallEnded && duration > 0) {
299
+ this.onCallEnded(duration, startedAt);
300
+ }
301
+ this.onHangup();
302
+ };
303
+
304
+ footer.appendChild(this.hangupBtn);
305
+ this.element.appendChild(footer);
306
+ }
307
+
308
+ public getElement(): HTMLDivElement {
309
+ return this.element;
310
+ }
311
+
312
+ public setMode(mode: 'voice' | 'avatar') {
313
+ this.isAvatarMode = (mode === 'avatar');
314
+ }
315
+
316
+ public setVideoTrack(track: MediaStreamTrack) {
317
+ this.isAvatarMode = true;
318
+ if (track.kind === 'video' && this.videoElement) {
319
+ const stream = new MediaStream([track]);
320
+ this.videoElement.srcObject = stream;
321
+ this.videoContainer.style.display = 'block';
322
+ this.orbWrapper.style.display = 'none';
323
+ this.connectingLabel.style.display = 'none';
324
+ this.timerEl.style.display = 'none';
325
+
326
+ this.videoElement.onplaying = () => {
327
+ this.prepareBadge.style.display = 'none';
328
+ this.statusBadge.style.display = 'flex';
329
+ };
330
+ this.videoElement.play().catch(e => console.warn('Video play error', e));
331
+ }
332
+ }
333
+
334
+ public setStatus(status: 'connecting' | 'connected' | 'disconnected' | 'error', errorMsg?: string) {
335
+ if (status === 'connecting') {
336
+ // CENTER ICON: spinner while connecting
337
+ this.centerIcon.style.background = '#4b5563';
338
+ this.centerIcon.innerHTML = `<div style="width:18px;height:18px;border:2px solid #ffffff;border-top-color:transparent;border-radius:50%;animation:spin 1s linear infinite;"></div>`;
339
+
340
+ if (this.isAvatarMode) {
341
+ this.videoContainer.style.display = 'block';
342
+ this.orbWrapper.style.display = 'none';
343
+ this.prepareBadge.textContent = 'CONNECTING...';
344
+ this.prepareBadge.style.display = 'block';
345
+ this.statusBadge.style.display = 'none';
346
+ this.connectingLabel.style.display = 'none';
347
+ } else {
348
+ this.orbWrapper.style.display = 'flex';
349
+ this.videoContainer.style.display = 'none';
350
+ this.connectingRing.style.display = 'block';
351
+ this.errorRing.style.display = 'none';
352
+ this.waveLayers.forEach(l => l.style.display = 'none');
353
+ this.connectingLabel.style.display = 'block';
354
+ this.giveItAMinuteLabel.style.display = 'block';
355
+ this.connectedBadge.style.display = 'none';
356
+ this.timerEl.style.display = 'none';
357
+ this.errorLabel.style.display = 'none';
358
+ this.retryBtn.style.display = 'none';
359
+ }
360
+ this.stopTimer();
361
+
362
+ } else if (status === 'connected') {
363
+ // CENTER ICON: phone
364
+ this.centerIcon.style.background = '#1f2937';
365
+ this.centerIcon.innerHTML = icons.phone;
366
+ const svg = this.centerIcon.querySelector('svg');
367
+ if (svg) { svg.style.cssText = 'width:20px;height:20px;'; }
368
+
369
+ if (this.isAvatarMode) {
370
+ const isPlaying = this.videoElement && !this.videoElement.paused && this.videoElement.readyState > 2;
371
+ if (isPlaying) {
372
+ this.prepareBadge.style.display = 'none';
373
+ this.statusBadge.style.display = 'flex';
374
+ } else {
375
+ this.prepareBadge.textContent = 'AGENT IS ON THE WAY...';
376
+ this.prepareBadge.style.display = 'block';
377
+ setTimeout(() => {
378
+ if (this.prepareBadge.style.display !== 'none') {
379
+ this.prepareBadge.style.display = 'none';
380
+ this.statusBadge.style.display = 'flex';
381
+ }
382
+ }, 5000);
383
+ }
384
+ } else {
385
+ this.connectingRing.style.display = 'none';
386
+ this.errorRing.style.display = 'none';
387
+ this.waveLayers.forEach(l => l.style.display = 'flex');
388
+ this.connectingLabel.style.display = 'none';
389
+ this.giveItAMinuteLabel.style.display = 'none';
390
+ this.connectedBadge.style.display = 'flex';
391
+ this.timerEl.style.display = 'block';
392
+ this.errorLabel.style.display = 'none';
393
+ this.retryBtn.style.display = 'none';
394
+ this.startTimer();
395
+ }
396
+
397
+ } else if (status === 'error') {
398
+ this.centerIcon.style.background = '#dc2626';
399
+ this.centerIcon.innerHTML = icons.phone;
400
+ this.connectingRing.style.display = 'none';
401
+ this.errorRing.style.display = 'block';
402
+ this.waveLayers.forEach(l => l.style.display = 'none');
403
+ this.connectingLabel.style.display = 'none';
404
+ this.giveItAMinuteLabel.style.display = 'none';
405
+ this.connectedBadge.style.display = 'none';
406
+ this.timerEl.style.display = 'none';
407
+ this.errorLabel.textContent = errorMsg || 'Connection failed';
408
+ this.errorLabel.style.display = 'block';
409
+ this.retryBtn.style.display = 'block';
410
+ this.stopTimer();
411
+ }
412
+ }
413
+
414
+ public setTranscription(text: string, isFinal: boolean) {
415
+ this.transcriptionEl.textContent = `"${text}"`;
416
+ this.transcriptionEl.style.color = isFinal ? '#1f2937' : '#9ca3af';
417
+ this.transcriptionEl.style.fontStyle = isFinal ? 'normal' : 'italic';
418
+ }
419
+
420
+ public show() {
421
+ this.callStartedAt = Date.now();
422
+ this.element.style.display = 'flex';
423
+ this.setStatus('connecting');
424
+ }
425
+
426
+ public hide() {
427
+ this.element.style.display = 'none';
428
+ this.reset();
429
+ }
430
+
431
+ public reset() {
432
+ if (this.videoElement) this.videoElement.srcObject = null;
433
+ this.isAvatarMode = false;
434
+ this.callStartedAt = null;
435
+ this.stopTimer();
436
+ this.transcriptionEl.textContent = '';
437
+
438
+ // Reset to defaults
439
+ this.videoContainer.style.display = 'none';
440
+ this.orbWrapper.style.display = 'flex';
441
+ this.connectingRing.style.display = 'none';
442
+ this.errorRing.style.display = 'none';
443
+ this.waveLayers.forEach(l => l.style.display = 'none');
444
+ this.connectingLabel.style.display = 'none';
445
+ this.connectedBadge.style.display = 'none';
446
+ this.timerEl.style.display = 'none';
447
+ this.errorLabel.style.display = 'none';
448
+ this.retryBtn.style.display = 'none';
449
+ this.prepareBadge.style.display = 'none';
450
+ this.statusBadge.style.display = 'none';
451
+ this.giveItAMinuteLabel.style.display = 'none';
452
+ this.centerIcon.style.background = '#374151';
453
+ this.centerIcon.innerHTML = icons.phone;
454
+ const svg = this.centerIcon.querySelector('svg');
455
+ if (svg) { svg.style.cssText = 'width:20px;height:20px;'; }
456
+ }
457
+
458
+ private startTimer() {
459
+ if (this.timerInterval) clearInterval(this.timerInterval);
460
+ this.startTime = Date.now();
461
+ this.timerEl.textContent = '00:00';
462
+ this.timerInterval = setInterval(() => {
463
+ if (!this.startTime) return;
464
+ const diff = Math.floor((Date.now() - this.startTime) / 1000);
465
+ const mins = Math.floor(diff / 60).toString().padStart(2, '0');
466
+ const secs = (diff % 60).toString().padStart(2, '0');
467
+ this.timerEl.textContent = `${mins}:${secs}`;
468
+ }, 1000);
469
+ }
470
+
471
+ private stopTimer() {
472
+ if (this.timerInterval) { clearInterval(this.timerInterval); this.timerInterval = null; }
473
+ this.timerEl.textContent = '';
474
+ }
475
+
476
+ public setFullScreen(enable: boolean) {
477
+ if (enable) {
478
+ this.videoContainer.style.position = 'absolute';
479
+ this.videoContainer.style.top = '0';
480
+ this.videoContainer.style.left = '0';
481
+ this.videoContainer.style.width = '100%';
482
+ this.videoContainer.style.height = '100%';
483
+ this.videoContainer.style.maxWidth = 'none';
484
+ this.videoContainer.style.borderRadius = '0';
485
+ this.videoContainer.style.margin = '0';
486
+ this.videoContainer.style.zIndex = '0';
487
+ } else {
488
+ this.videoContainer.style.position = 'relative';
489
+ this.videoContainer.style.width = '100%';
490
+ this.videoContainer.style.maxWidth = '260px';
491
+ this.videoContainer.style.height = 'auto';
492
+ this.videoContainer.style.aspectRatio = '1/1';
493
+ this.videoContainer.style.borderRadius = '16px';
494
+ this.videoContainer.style.marginBottom = '16px';
495
+ }
496
+ }
497
+ }
@@ -0,0 +1,7 @@
1
+ export * from './FloatingButton';
2
+ export * from './Panel';
3
+ export * from './VoiceOverlay';
4
+ export * from './ChatWindow';
5
+ export * from './AvatarView';
6
+ export * from './VoiceOrb';
7
+ export * from './FloatingWelcomeChips';
@@ -0,0 +1,16 @@
1
+ import { IWidgetProvider } from '../abstraction/interfaces';
2
+ import { VaniraInternalProvider } from '../providers/VaniraInternalProvider';
3
+
4
+ export class WidgetProviderFactory {
5
+ /**
6
+ * Factory Method to create the appropriate Widget Provider.
7
+ * Implements the Factory Pattern to decouple creation logic.
8
+ * Trade-off: Currently hardcoded to VaniraInternalProvider, but extensible for other providers.
9
+ */
10
+ static getProvider(config: any): IWidgetProvider {
11
+ // Here we could check config.providerType to return different implementations
12
+ // e.g. if (config.provider === 'external_sip') return new ExternalSIPProvider(config);
13
+
14
+ return new VaniraInternalProvider(config);
15
+ }
16
+ }