@convai/web-sdk 1.9.1 → 2.0.0-beta.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.
Files changed (86) hide show
  1. package/README.md +25 -14
  2. package/dist/core/ConvaiClient.js +10 -1
  3. package/dist/core/types.d.ts +13 -3
  4. package/dist/core/websocketUrl.d.ts +11 -0
  5. package/dist/core/websocketUrl.js +17 -0
  6. package/dist/react/hooks/index.d.ts +0 -2
  7. package/dist/react/hooks/index.js +0 -3
  8. package/dist/react/index.d.ts +0 -3
  9. package/dist/react/index.js +3 -10
  10. package/dist/utils/inlineMarkdown.d.ts +7 -5
  11. package/dist/utils/inlineMarkdown.js +7 -5
  12. package/dist/vanilla/WebSocketSession.d.ts +19 -13
  13. package/dist/vanilla/WebSocketSession.js +58 -14
  14. package/dist/vanilla/index.d.ts +6 -18
  15. package/dist/vanilla/index.js +7 -19
  16. package/dist/version.d.ts +1 -1
  17. package/dist/version.js +1 -1
  18. package/package.json +9 -8
  19. package/dist/react/components/ConvaiWidget.d.ts +0 -86
  20. package/dist/react/components/ConvaiWidget.js +0 -610
  21. package/dist/react/components/index.d.ts +0 -1
  22. package/dist/react/components/index.js +0 -2
  23. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +0 -9
  24. package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js +0 -315
  25. package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts +0 -35
  26. package/dist/react/components/rtc-widget/components/AudioVisualizer.js +0 -285
  27. package/dist/react/components/rtc-widget/components/ConviMessage.d.ts +0 -12
  28. package/dist/react/components/rtc-widget/components/ConviMessage.js +0 -13
  29. package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts +0 -8
  30. package/dist/react/components/rtc-widget/components/FloatingVideo.js +0 -120
  31. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +0 -31
  32. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +0 -140
  33. package/dist/react/components/rtc-widget/components/MessageBubble.d.ts +0 -9
  34. package/dist/react/components/rtc-widget/components/MessageBubble.js +0 -22
  35. package/dist/react/components/rtc-widget/components/MessageList.d.ts +0 -13
  36. package/dist/react/components/rtc-widget/components/MessageList.js +0 -88
  37. package/dist/react/components/rtc-widget/components/SiteCard.d.ts +0 -14
  38. package/dist/react/components/rtc-widget/components/SiteCard.js +0 -34
  39. package/dist/react/components/rtc-widget/components/UserMessage.d.ts +0 -8
  40. package/dist/react/components/rtc-widget/components/UserMessage.js +0 -14
  41. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts +0 -5
  42. package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +0 -14
  43. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +0 -24
  44. package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +0 -170
  45. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +0 -16
  46. package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +0 -64
  47. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +0 -11
  48. package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +0 -65
  49. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +0 -13
  50. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +0 -298
  51. package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts +0 -5
  52. package/dist/react/components/rtc-widget/components/conviComponents/index.js +0 -5
  53. package/dist/react/components/rtc-widget/components/index.d.ts +0 -8
  54. package/dist/react/components/rtc-widget/components/index.js +0 -14
  55. package/dist/react/components/rtc-widget/index.d.ts +0 -5
  56. package/dist/react/components/rtc-widget/index.js +0 -8
  57. package/dist/react/components/rtc-widget/styles/framerConfig.d.ts +0 -115
  58. package/dist/react/components/rtc-widget/styles/framerConfig.js +0 -72
  59. package/dist/react/components/rtc-widget/styles/icons.d.ts +0 -27
  60. package/dist/react/components/rtc-widget/styles/icons.js +0 -256
  61. package/dist/react/components/rtc-widget/styles/index.d.ts +0 -5
  62. package/dist/react/components/rtc-widget/styles/index.js +0 -8
  63. package/dist/react/components/rtc-widget/styles/styledComponents.d.ts +0 -89
  64. package/dist/react/components/rtc-widget/styles/styledComponents.js +0 -662
  65. package/dist/react/components/rtc-widget/styles/theme.d.ts +0 -187
  66. package/dist/react/components/rtc-widget/styles/theme.js +0 -289
  67. package/dist/react/components/rtc-widget/types/index.d.ts +0 -59
  68. package/dist/react/components/rtc-widget/types/index.js +0 -1
  69. package/dist/react/hooks/useCharacterInfo.d.ts +0 -18
  70. package/dist/react/hooks/useCharacterInfo.js +0 -65
  71. package/dist/react/hooks/useLocalCameraTrack.d.ts +0 -21
  72. package/dist/react/hooks/useLocalCameraTrack.js +0 -33
  73. package/dist/react/icons.d.ts +0 -37
  74. package/dist/react/icons.js +0 -53
  75. package/dist/utils/lightbox.d.ts +0 -15
  76. package/dist/utils/lightbox.js +0 -94
  77. package/dist/vanilla/ConvaiWidget.d.ts +0 -46
  78. package/dist/vanilla/ConvaiWidget.js +0 -2866
  79. package/dist/vanilla/WidgetEventSubscriptions.d.ts +0 -14
  80. package/dist/vanilla/WidgetEventSubscriptions.js +0 -36
  81. package/dist/vanilla/icons.d.ts +0 -34
  82. package/dist/vanilla/icons.js +0 -268
  83. package/dist/vanilla/styles.d.ts +0 -168
  84. package/dist/vanilla/styles.js +0 -407
  85. package/dist/vanilla/types.d.ts +0 -170
  86. package/dist/vanilla/types.js +0 -1
@@ -1,315 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from "react";
3
- import styled from "styled-components";
4
- const Panel = styled.div `
5
- position: absolute;
6
- bottom: 100%;
7
- right: 0;
8
- margin-bottom: 12px;
9
- width: 360px;
10
- background: rgba(15, 23, 42, 0.98);
11
- border: 1px solid rgba(148, 163, 184, 0.2);
12
- border-radius: 16px;
13
- padding: 24px;
14
- box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3),
15
- 0 10px 10px -5px rgba(0, 0, 0, 0.2);
16
- backdrop-filter: blur(10px);
17
- opacity: ${(props) => (props.isOpen ? 1 : 0)};
18
- pointer-events: ${(props) => (props.isOpen ? "all" : "none")};
19
- transform: ${(props) => props.isOpen ? "translateY(0)" : "translateY(10px)"};
20
- transition: all 0.2s ease-out;
21
- z-index: 1000;
22
-
23
- @media (max-width: 640px) {
24
- width: calc(100vw - 32px);
25
- right: 16px;
26
- }
27
- `;
28
- const Title = styled.div `
29
- font-size: 18px;
30
- font-weight: 600;
31
- color: #f1f5f9;
32
- margin-bottom: 8px;
33
- display: flex;
34
- align-items: center;
35
- gap: 8px;
36
- `;
37
- const Subtitle = styled.div `
38
- font-size: 13px;
39
- color: #94a3b8;
40
- margin-bottom: 20px;
41
- line-height: 1.5;
42
- `;
43
- const SettingGroup = styled.div `
44
- margin-bottom: 20px;
45
-
46
- &:last-child {
47
- margin-bottom: 0;
48
- }
49
- `;
50
- const SettingLabel = styled.label `
51
- display: flex;
52
- align-items: center;
53
- justify-content: space-between;
54
- font-size: 14px;
55
- color: #e2e8f0;
56
- margin-bottom: 8px;
57
- cursor: pointer;
58
- user-select: none;
59
- padding: 10px 12px;
60
- border-radius: 8px;
61
- transition: background 0.15s ease;
62
-
63
- &:hover {
64
- background: rgba(148, 163, 184, 0.1);
65
- }
66
- `;
67
- const SettingDescription = styled.div `
68
- font-size: 12px;
69
- color: #64748b;
70
- margin-top: -4px;
71
- margin-bottom: 8px;
72
- padding-left: 12px;
73
- line-height: 1.4;
74
- `;
75
- const Toggle = styled.div `
76
- width: 44px;
77
- height: 24px;
78
- background: ${(props) => props.enabled
79
- ? "linear-gradient(135deg, #10b981 0%, #059669 100%)"
80
- : "rgba(71, 85, 105, 0.5)"};
81
- border-radius: 12px;
82
- position: relative;
83
- transition: all 0.2s ease;
84
- box-shadow: ${(props) => props.enabled
85
- ? "0 0 12px rgba(16, 185, 129, 0.3)"
86
- : "inset 0 2px 4px rgba(0, 0, 0, 0.2)"};
87
-
88
- &::after {
89
- content: "";
90
- position: absolute;
91
- top: 2px;
92
- left: ${(props) => (props.enabled ? "22px" : "2px")};
93
- width: 20px;
94
- height: 20px;
95
- background: white;
96
- border-radius: 50%;
97
- transition: left 0.2s ease;
98
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
99
- }
100
- `;
101
- const SliderGroup = styled.div `
102
- margin-bottom: 16px;
103
- `;
104
- const SliderLabel = styled.div `
105
- display: flex;
106
- align-items: center;
107
- justify-content: space-between;
108
- margin-bottom: 8px;
109
- font-size: 14px;
110
- color: #e2e8f0;
111
- `;
112
- const SliderValue = styled.span `
113
- font-weight: 600;
114
- color: #10b981;
115
- font-size: 13px;
116
- `;
117
- const Slider = styled.input `
118
- width: 100%;
119
- height: 6px;
120
- border-radius: 3px;
121
- background: rgba(71, 85, 105, 0.3);
122
- outline: none;
123
- -webkit-appearance: none;
124
-
125
- &::-webkit-slider-thumb {
126
- -webkit-appearance: none;
127
- appearance: none;
128
- width: 18px;
129
- height: 18px;
130
- border-radius: 50%;
131
- background: linear-gradient(135deg, #10b981 0%, #059669 100%);
132
- cursor: pointer;
133
- box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
134
- transition: transform 0.15s ease;
135
-
136
- &:hover {
137
- transform: scale(1.1);
138
- }
139
-
140
- &:active {
141
- transform: scale(0.95);
142
- }
143
- }
144
-
145
- &::-moz-range-thumb {
146
- width: 18px;
147
- height: 18px;
148
- border-radius: 50%;
149
- background: linear-gradient(135deg, #10b981 0%, #059669 100%);
150
- cursor: pointer;
151
- box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
152
- border: none;
153
- transition: transform 0.15s ease;
154
-
155
- &:hover {
156
- transform: scale(1.1);
157
- }
158
-
159
- &:active {
160
- transform: scale(0.95);
161
- }
162
- }
163
- `;
164
- const PresetButtons = styled.div `
165
- display: grid;
166
- grid-template-columns: repeat(3, 1fr);
167
- gap: 8px;
168
- margin-top: 20px;
169
- padding-top: 20px;
170
- border-top: 1px solid rgba(148, 163, 184, 0.2);
171
- `;
172
- const PresetButton = styled.button `
173
- padding: 10px 12px;
174
- font-size: 13px;
175
- font-weight: 500;
176
- border-radius: 8px;
177
- border: 1px solid
178
- ${(props) => props.active ? "rgba(16, 185, 129, 0.5)" : "rgba(148, 163, 184, 0.2)"};
179
- background: ${(props) => props.active
180
- ? "rgba(16, 185, 129, 0.15)"
181
- : "rgba(30, 41, 59, 0.5)"};
182
- color: ${(props) => (props.active ? "#10b981" : "#cbd5e1")};
183
- cursor: pointer;
184
- transition: all 0.15s ease;
185
-
186
- &:hover {
187
- background: ${(props) => props.active
188
- ? "rgba(16, 185, 129, 0.25)"
189
- : "rgba(148, 163, 184, 0.1)"};
190
- border-color: ${(props) => props.active ? "#10b981" : "rgba(148, 163, 184, 0.3)"};
191
- }
192
-
193
- &:active {
194
- transform: scale(0.98);
195
- }
196
-
197
- &:disabled {
198
- opacity: 0.5;
199
- cursor: not-allowed;
200
- }
201
- `;
202
- const InfoBox = styled.div `
203
- background: rgba(59, 130, 246, 0.1);
204
- border: 1px solid rgba(59, 130, 246, 0.2);
205
- border-radius: 8px;
206
- padding: 12px;
207
- margin-bottom: 20px;
208
- font-size: 12px;
209
- color: #93c5fd;
210
- line-height: 1.5;
211
- `;
212
- const StatusIndicator = styled.div `
213
- display: inline-flex;
214
- align-items: center;
215
- gap: 6px;
216
- padding: 4px 10px;
217
- border-radius: 12px;
218
- font-size: 11px;
219
- font-weight: 600;
220
- background: ${(props) => props.isConnected
221
- ? "rgba(16, 185, 129, 0.15)"
222
- : "rgba(239, 68, 68, 0.15)"};
223
- color: ${(props) => (props.isConnected ? "#10b981" : "#ef4444")};
224
-
225
- &::before {
226
- content: "";
227
- width: 6px;
228
- height: 6px;
229
- border-radius: 50%;
230
- background: currentColor;
231
- }
232
- `;
233
- export const AudioSettingsPanel = ({ currentSettings, onUpdateSettings, isConnected, }) => {
234
- const [localSettings, setLocalSettings] = useState(currentSettings);
235
- const [isUpdating, setIsUpdating] = useState(false);
236
- const handleToggle = async (key, value) => {
237
- setLocalSettings((prev) => ({ ...prev, [key]: value }));
238
- setIsUpdating(true);
239
- try {
240
- await onUpdateSettings({ [key]: value });
241
- }
242
- finally {
243
- setIsUpdating(false);
244
- }
245
- };
246
- const handleSliderChange = (key, value) => {
247
- setLocalSettings((prev) => ({ ...prev, [key]: value }));
248
- };
249
- const handleSliderRelease = async (key, value) => {
250
- setIsUpdating(true);
251
- try {
252
- await onUpdateSettings({ [key]: value });
253
- }
254
- finally {
255
- setIsUpdating(false);
256
- }
257
- };
258
- const applyPreset = async (preset) => {
259
- setIsUpdating(true);
260
- let newSettings;
261
- switch (preset) {
262
- case "quiet":
263
- // Quiet environment - minimal processing, more sensitive to interruptions
264
- newSettings = {
265
- echoCancellation: false,
266
- noiseSuppression: false,
267
- autoGainControl: false,
268
- sampleRate: 48000,
269
- channelCount: 1,
270
- };
271
- break;
272
- case "balanced":
273
- // Balanced - moderate processing, good middle ground
274
- newSettings = {
275
- echoCancellation: true,
276
- noiseSuppression: true,
277
- autoGainControl: false,
278
- sampleRate: 48000,
279
- channelCount: 1,
280
- };
281
- break;
282
- case "noisy":
283
- // Noisy environment - aggressive processing, reduces interruptions
284
- newSettings = {
285
- echoCancellation: true,
286
- noiseSuppression: true,
287
- autoGainControl: true,
288
- sampleRate: 48000,
289
- channelCount: 1,
290
- };
291
- break;
292
- }
293
- setLocalSettings(newSettings);
294
- try {
295
- await onUpdateSettings(newSettings);
296
- }
297
- finally {
298
- setIsUpdating(false);
299
- }
300
- };
301
- const getCurrentPreset = () => {
302
- const { echoCancellation, noiseSuppression, autoGainControl } = localSettings;
303
- if (!echoCancellation && !noiseSuppression && !autoGainControl) {
304
- return "quiet";
305
- }
306
- if (echoCancellation && noiseSuppression && !autoGainControl) {
307
- return "balanced";
308
- }
309
- if (echoCancellation && noiseSuppression && autoGainControl) {
310
- return "noisy";
311
- }
312
- return null;
313
- };
314
- return (_jsxs(Panel, { isOpen: true, children: [_jsxs(Title, { children: ["Audio Sensitivity Settings", _jsx(StatusIndicator, { isConnected: isConnected, children: isConnected ? "LIVE" : "OFFLINE" })] }), _jsx(Subtitle, { children: "Adjust these settings to reduce interruptions and find the optimal balance for your environment." }), isConnected && (_jsx(InfoBox, { children: "Warning: Changing settings will briefly restart your microphone. Changes apply immediately." })), _jsxs(SettingGroup, { children: [_jsxs(SettingLabel, { children: [_jsx("span", { children: "Echo Cancellation" }), _jsx(Toggle, { enabled: localSettings.echoCancellation || false, onClick: () => handleToggle("echoCancellation", !localSettings.echoCancellation) })] }), _jsx(SettingDescription, { children: "Prevents feedback loops from speakers. Recommended ON." })] }), _jsxs(SettingGroup, { children: [_jsxs(SettingLabel, { children: [_jsx("span", { children: "Noise Suppression" }), _jsx(Toggle, { enabled: localSettings.noiseSuppression || false, onClick: () => handleToggle("noiseSuppression", !localSettings.noiseSuppression) })] }), _jsx(SettingDescription, { children: "Filters out background noise. Turn ON to reduce false interruptions." })] }), _jsxs(SettingGroup, { children: [_jsxs(SettingLabel, { children: [_jsx("span", { children: "Auto Gain Control" }), _jsx(Toggle, { enabled: localSettings.autoGainControl || false, onClick: () => handleToggle("autoGainControl", !localSettings.autoGainControl) })] }), _jsx(SettingDescription, { children: "Automatically adjusts microphone volume. Turn ON in noisy environments to prevent unwanted interruptions." })] }), _jsxs(SliderGroup, { children: [_jsxs(SliderLabel, { children: [_jsx("span", { children: "Sample Rate" }), _jsxs(SliderValue, { children: [localSettings.sampleRate || 48000, " Hz"] })] }), _jsx(Slider, { type: "range", min: "8000", max: "48000", step: "8000", value: localSettings.sampleRate || 48000, onChange: (e) => handleSliderChange("sampleRate", parseInt(e.target.value)), onMouseUp: (e) => handleSliderRelease("sampleRate", parseInt(e.target.value)), onTouchEnd: (e) => handleSliderRelease("sampleRate", parseInt(e.target.value)) }), _jsx(SettingDescription, { children: "Higher = better quality, lower = less data. 48000 Hz recommended." })] }), _jsxs(PresetButtons, { children: [_jsx(PresetButton, { onClick: () => applyPreset("quiet"), active: getCurrentPreset() === "quiet", disabled: isUpdating, children: "\uD83D\uDD07 Quiet" }), _jsx(PresetButton, { onClick: () => applyPreset("balanced"), active: getCurrentPreset() === "balanced", disabled: isUpdating, children: "Balanced" }), _jsx(PresetButton, { onClick: () => applyPreset("noisy"), active: getCurrentPreset() === "noisy", disabled: isUpdating, children: "\uD83D\uDD0A Noisy" })] })] }));
315
- };
@@ -1,35 +0,0 @@
1
- import { Room } from 'livekit-client';
2
- interface AudioVisualizerProps {
3
- /** LiveKit room instance containing the remote participant's audio track */
4
- room: Room | null;
5
- /** Canvas size in pixels (width and height) */
6
- size?: number;
7
- /** CSS color value for the bars */
8
- color?: string;
9
- /** Base opacity of the bars (0-1), actual opacity varies with audio intensity */
10
- opacity?: number;
11
- /** Radius of the circular visualization area in pixels */
12
- avatarRadius?: number;
13
- /** Number of radial bars to display around the circle */
14
- barCount?: number;
15
- /** Callback function called when speaking state changes */
16
- onSpeakingChange?: (isSpeaking: boolean) => void;
17
- }
18
- /**
19
- * Circular Audio Visualizer Component
20
- *
21
- * A real-time circular audio visualization component that displays radial bars arranged
22
- * in a circle around an avatar. The visualization reacts to the remote participant's
23
- * (bot) audio output from a LiveKit room, using logarithmic frequency bands and a
24
- * traveling wave animation effect.
25
- *
26
- * Features:
27
- * - Circular radial bar visualization with configurable bar count
28
- * - Logarithmic frequency band distribution (low frequencies distributed around the ring)
29
- * - Traveling wave animation that propagates around the circle
30
- * - Speaking detection with callback support
31
- * - Automatic track detection and reconnection
32
- * - Canvas-based rendering for smooth animations
33
- */
34
- export declare const AudioVisualizer: React.FC<AudioVisualizerProps>;
35
- export {};
@@ -1,285 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useRef } from 'react';
3
- import styled from 'styled-components';
4
- const VisualizerContainer = styled.div `
5
- position: absolute;
6
- width: 100%;
7
- height: 100%;
8
- z-index: 1;
9
- pointer-events: none;
10
- border-radius: 50%;
11
- overflow: visible;
12
- `;
13
- const Canvas = styled.canvas `
14
- display: block;
15
- width: 100%;
16
- height: 100%;
17
- `;
18
- /**
19
- * Circular Audio Visualizer Component
20
- *
21
- * A real-time circular audio visualization component that displays radial bars arranged
22
- * in a circle around an avatar. The visualization reacts to the remote participant's
23
- * (bot) audio output from a LiveKit room, using logarithmic frequency bands and a
24
- * traveling wave animation effect.
25
- *
26
- * Features:
27
- * - Circular radial bar visualization with configurable bar count
28
- * - Logarithmic frequency band distribution (low frequencies distributed around the ring)
29
- * - Traveling wave animation that propagates around the circle
30
- * - Speaking detection with callback support
31
- * - Automatic track detection and reconnection
32
- * - Canvas-based rendering for smooth animations
33
- */
34
- export const AudioVisualizer = ({ room, size = 350, color = '#10b981', opacity = 0.4, avatarRadius = 80, barCount = 64, onSpeakingChange, }) => {
35
- // Refs for canvas and Web Audio API nodes
36
- const canvasRef = useRef(null);
37
- const animationFrameRef = useRef(null);
38
- const audioContextRef = useRef(null);
39
- const analyserRef = useRef(null);
40
- const sourceNodeRef = useRef(null);
41
- const isActiveRef = useRef(false);
42
- // Refs for animation and state management
43
- const timeRef = useRef(0);
44
- const previousSpeakingStateRef = useRef(false);
45
- const bandEdgesRef = useRef(null);
46
- useEffect(() => {
47
- if (!room)
48
- return;
49
- const canvas = canvasRef.current;
50
- if (!canvas)
51
- return;
52
- const ctx = canvas.getContext('2d');
53
- if (!ctx)
54
- return;
55
- canvas.width = size;
56
- canvas.height = size;
57
- // Initialize Web Audio API context and analyser
58
- const audioContext = new (window.AudioContext || window.webkitAudioContext)();
59
- const analyser = audioContext.createAnalyser();
60
- analyser.fftSize = 512;
61
- analyser.smoothingTimeConstant = 0.6;
62
- audioContextRef.current = audioContext;
63
- analyserRef.current = analyser;
64
- /**
65
- * Builds logarithmically-spaced frequency band edges.
66
- * This distributes low-frequency energy (which has more power) evenly around
67
- * the circular visualization, rather than clustering it at the start.
68
- */
69
- const buildLogBands = () => {
70
- const nyquist = audioContext.sampleRate / 2;
71
- const bufferLength = analyser.frequencyBinCount;
72
- const minHz = 60;
73
- const maxHz = Math.min(8000, nyquist);
74
- const edges = Array.from({ length: barCount + 1 }, (_, k) => {
75
- const hz = minHz * Math.pow(maxHz / minHz, k / barCount);
76
- const bin = Math.max(0, Math.min(bufferLength - 1, Math.floor((hz / nyquist) * bufferLength)));
77
- return bin;
78
- });
79
- // Ensure strictly increasing edges (no zero-width bands)
80
- for (let i = 1; i < edges.length; i++) {
81
- if (edges[i] <= edges[i - 1])
82
- edges[i] = Math.min(edges[i - 1] + 1, bufferLength - 1);
83
- }
84
- bandEdgesRef.current = edges;
85
- };
86
- /**
87
- * Finds the bot participant from remote participants.
88
- */
89
- const findBotParticipant = (remoteParticipants, localParticipant) => {
90
- const participants = Array.from(remoteParticipants.values()).filter((p) => p !== localParticipant && p !== room.localParticipant);
91
- if (participants.length === 0) {
92
- return null;
93
- }
94
- // Prefer participants with audio tracks (bot typically has audio)
95
- const participantsWithAudio = participants.filter((participant) => {
96
- if (!participant.trackPublications)
97
- return false;
98
- const audioTracks = Array.from(participant.trackPublications.values()).filter((p) => p.kind === 'audio' && p.track);
99
- return audioTracks.length > 0;
100
- });
101
- return participantsWithAudio.length > 0 ? participantsWithAudio[0] : participants[0];
102
- };
103
- /**
104
- * Sets up the audio source by connecting the remote participant's (bot) audio track
105
- * to the Web Audio API analyser.
106
- */
107
- const setupAudioSource = async () => {
108
- try {
109
- if (audioContext.state === 'suspended')
110
- await audioContext.resume();
111
- const remoteParticipants = room.remoteParticipants;
112
- if (remoteParticipants.size === 0) {
113
- isActiveRef.current = false;
114
- return;
115
- }
116
- const botParticipant = findBotParticipant(remoteParticipants, room.localParticipant);
117
- if (!botParticipant) {
118
- isActiveRef.current = false;
119
- return;
120
- }
121
- const audioTracks = Array.from(botParticipant.trackPublications.values()).filter((p) => p.kind === 'audio' && p.track);
122
- if (audioTracks.length === 0) {
123
- isActiveRef.current = false;
124
- return;
125
- }
126
- const liveKitTrack = audioTracks[0].track;
127
- const mediaStreamTrack = liveKitTrack.mediaStreamTrack;
128
- if (!mediaStreamTrack) {
129
- isActiveRef.current = false;
130
- return;
131
- }
132
- const mediaStream = new MediaStream([mediaStreamTrack]);
133
- if (sourceNodeRef.current)
134
- sourceNodeRef.current.disconnect();
135
- const source = audioContext.createMediaStreamSource(mediaStream);
136
- source.connect(analyser);
137
- sourceNodeRef.current = source;
138
- // Build bands after context is ready
139
- buildLogBands();
140
- isActiveRef.current = true;
141
- }
142
- catch {
143
- isActiveRef.current = false;
144
- }
145
- };
146
- setupAudioSource();
147
- const setupTimeout = setTimeout(setupAudioSource, 500);
148
- const handleTrackSubscribed = (track, publication, participant) => {
149
- if (track && track.kind === 'audio' && participant !== room.localParticipant) {
150
- setTimeout(setupAudioSource, 200);
151
- }
152
- };
153
- const handleParticipantConnected = (participant) => {
154
- if (participant !== room.localParticipant)
155
- setTimeout(setupAudioSource, 200);
156
- };
157
- room.on('trackSubscribed', handleTrackSubscribed);
158
- room.on('participantConnected', handleParticipantConnected);
159
- /**
160
- * Main rendering function that draws the circular audio visualization.
161
- */
162
- const bufferLength = analyser.frequencyBinCount;
163
- const dataArray = new Uint8Array(bufferLength);
164
- let frameParity = 0;
165
- let idleFramesPainted = 0;
166
- const draw = () => {
167
- // THROTTLE: 30fps, and stop repainting once the idle state has
168
- // settled — every canvas update forces the compositor to re-blend
169
- // the widget panel over the host page's WebGL canvas, which judders
170
- // the 3D scene if done at 60fps continuously.
171
- frameParity ^= 1;
172
- if (frameParity) {
173
- animationFrameRef.current = requestAnimationFrame(draw);
174
- return;
175
- }
176
- timeRef.current += 0.16;
177
- analyser.getByteFrequencyData(dataArray);
178
- {
179
- let t = 0;
180
- for (let i = 0; i < bufferLength; i++)
181
- t += dataArray[i] || 0;
182
- if (!isActiveRef.current || t / (bufferLength * 255) < 0.01) {
183
- // Fade the ring out over a few frames, then hold it static.
184
- if (idleFramesPainted > 20) {
185
- animationFrameRef.current = requestAnimationFrame(draw);
186
- return;
187
- }
188
- idleFramesPainted++;
189
- }
190
- else {
191
- idleFramesPainted = 0;
192
- }
193
- }
194
- ctx.clearRect(0, 0, canvas.width, canvas.height);
195
- const centerX = canvas.width / 2;
196
- const centerY = canvas.height / 2;
197
- // The bars should surround the character, not be clipped inside
198
- // Character is 120px (radius 60px), visualizer canvas is 220px (radius 110px)
199
- const characterRadius = 60; // Half of 120px character image
200
- const innerRadius = characterRadius; // Start bars at edge of character
201
- const outerRadius = avatarRadius; // Extend to edge of visualizer canvas
202
- const maxBarLength = outerRadius - innerRadius;
203
- ctx.save();
204
- // No clipping - let bars render freely around the circle
205
- const angleStep = (Math.PI * 2) / barCount;
206
- // Calculate overall audio level for speaking detection
207
- let total = 0;
208
- for (let i = 0; i < bufferLength; i++)
209
- total += isActiveRef.current ? (dataArray[i] || 0) : 0;
210
- const overallLevel = total / (bufferLength * 255);
211
- // Speaking detection
212
- const speakingThreshold = 0.1;
213
- const isSpeaking = isActiveRef.current && overallLevel > speakingThreshold;
214
- if (onSpeakingChange && isSpeaking !== previousSpeakingStateRef.current) {
215
- previousSpeakingStateRef.current = isSpeaking;
216
- onSpeakingChange(isSpeaking);
217
- }
218
- // Precompute band edges if not ready yet
219
- if (!bandEdgesRef.current) {
220
- bandEdgesRef.current = Array.from({ length: barCount + 1 }, (_, k) => Math.floor((k / barCount) * bufferLength));
221
- }
222
- const edges = bandEdgesRef.current;
223
- // Traveling wave parameters
224
- const waveRevolutions = 2;
225
- const phasePerBar = (Math.PI * 2 * waveRevolutions) / barCount;
226
- const baseWaveAmp = 0.35;
227
- const waveAmp = baseWaveAmp * (0.3 + 0.7 * overallLevel);
228
- for (let i = 0; i < barCount; i++) {
229
- const angle = i * angleStep - Math.PI / 2;
230
- // Calculate average energy for this bar's frequency band
231
- const startFreq = edges[i];
232
- const endFreq = edges[i + 1];
233
- let sum = 0;
234
- let count = 0;
235
- for (let f = startFreq; f < endFreq && f < bufferLength; f++) {
236
- sum += isActiveRef.current ? (dataArray[f] || 0) : 0;
237
- count++;
238
- }
239
- const bandAvg = count > 0 ? sum / (count * 255) : 0;
240
- // Mix band-specific energy with overall level
241
- const energy = 0.4 * bandAvg + 0.6 * overallLevel;
242
- // Apply traveling wave modulation
243
- const wavePhase = i * phasePerBar;
244
- const wave = 1 + waveAmp * Math.sin(timeRef.current + wavePhase);
245
- // Final intensity
246
- const intensity = Math.min(1, energy * wave);
247
- // Convert to bar length
248
- const length = Math.max(maxBarLength * 0.03, intensity * maxBarLength * 0.95);
249
- // Coordinates
250
- const startX = centerX + Math.cos(angle) * innerRadius;
251
- const startY = centerY + Math.sin(angle) * innerRadius;
252
- const endX = centerX + Math.cos(angle) * (innerRadius + length);
253
- const endY = centerY + Math.sin(angle) * (innerRadius + length);
254
- // Draw
255
- ctx.strokeStyle = color;
256
- ctx.lineWidth = 5;
257
- ctx.lineCap = 'round';
258
- ctx.globalAlpha = opacity * (0.5 + 0.5 * intensity);
259
- ctx.beginPath();
260
- ctx.moveTo(startX, startY);
261
- ctx.lineTo(endX, endY);
262
- ctx.stroke();
263
- }
264
- ctx.globalAlpha = 1;
265
- ctx.restore();
266
- animationFrameRef.current = requestAnimationFrame(draw);
267
- };
268
- draw();
269
- return () => {
270
- clearTimeout(setupTimeout);
271
- if (animationFrameRef.current)
272
- cancelAnimationFrame(animationFrameRef.current);
273
- if (sourceNodeRef.current)
274
- sourceNodeRef.current.disconnect();
275
- if (analyserRef.current)
276
- analyserRef.current.disconnect();
277
- if (audioContextRef.current && audioContextRef.current.state !== 'closed') {
278
- audioContextRef.current.close();
279
- }
280
- room.off('trackSubscribed', handleTrackSubscribed);
281
- room.off('participantConnected', handleParticipantConnected);
282
- };
283
- }, [room, size, color, opacity, avatarRadius, barCount, onSpeakingChange]);
284
- return (_jsx(VisualizerContainer, { style: { width: size, height: size }, children: _jsx(Canvas, { ref: canvasRef }) }));
285
- };
@@ -1,12 +0,0 @@
1
- import type { LinkPreviewResolver } from "../../../../utils/linkPreview.js";
2
- interface ConviMessageProps {
3
- message: string;
4
- timestamp?: string;
5
- className?: string;
6
- showLogo?: boolean;
7
- sender?: string;
8
- /** Open Graph lookup for plain web links; see MarkdownRenderer. */
9
- resolveLinkPreview?: LinkPreviewResolver;
10
- }
11
- export declare const ConviMessage: ({ message, timestamp, className, showLogo, sender, resolveLinkPreview, }: ConviMessageProps) => import("react/jsx-runtime").JSX.Element;
12
- export {};
@@ -1,13 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { aeroTheme } from "../styles/index.js";
3
- import { ConvaiLogo, ConviBubble, ConviMessageContainer, MessageHeader, ConviLabel, LogoWrapper, } from "../styles/index.js";
4
- import { MarkdownRenderer } from "./MarkdownRenderer.js";
5
- export const ConviMessage = ({ message, timestamp, className, showLogo = true, sender, resolveLinkPreview, }) => {
6
- return (_jsxs(ConviMessageContainer, { className: className, children: [_jsxs(ConviBubble, { children: [showLogo && (_jsxs(MessageHeader, { children: [_jsx(LogoWrapper, { children: _jsx(ConvaiLogo, { size: "sm", color: "#10b981", animate: false, state: "connected" }) }), _jsx(ConviLabel, { children: sender })] })), _jsx(MarkdownRenderer, { text: message, resolveLinkPreview: resolveLinkPreview })] }), timestamp && (_jsx("span", { style: {
7
- fontSize: aeroTheme.typography.sizes.caption,
8
- color: aeroTheme.colors.text.secondary,
9
- marginTop: 4,
10
- alignSelf: "flex-start",
11
- fontFamily: aeroTheme.typography.fontFamily.body,
12
- }, children: timestamp }))] }));
13
- };
@@ -1,8 +0,0 @@
1
- import React from "react";
2
- interface FloatingVideoProps {
3
- isVisible: boolean;
4
- onClose: () => void;
5
- mirror?: boolean;
6
- }
7
- export declare const FloatingVideo: React.FC<FloatingVideoProps>;
8
- export {};