Skip to content

Commit e712ab6

Browse files
feat(shadcn): livekit api token route (#1292)
1 parent 89db224 commit e712ab6

15 files changed

+242
-33
lines changed

docs/storybook/stories/agents-ui/AgentAudioVisualizerAura.stories.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ export default {
1212
const {
1313
local: { microphoneTrack },
1414
} = useSessionContext();
15-
const { theme } = useTheme();
16-
const themeMode = theme === 'dark' ? 'dark' : 'light';
15+
const { resolvedTheme = 'dark' } = useTheme();
1716

1817
return (
19-
<AgentAudioVisualizerAura {...args} themeMode={themeMode} audioTrack={microphoneTrack} />
18+
<AgentAudioVisualizerAura
19+
{...args}
20+
audioTrack={microphoneTrack}
21+
themeMode={resolvedTheme as 'dark' | 'light'}
22+
/>
2023
);
2124
},
2225
args: {
2326
size: 'xl',
2427
color: '#1FD5F9',
2528
colorShift: 0.1,
26-
themeMode: 'dark',
2729
state: 'connecting',
2830
},
2931
argTypes: {
@@ -49,7 +51,7 @@ export default {
4951
control: { type: 'color' },
5052
},
5153
colorShift: {
52-
control: { type: 'range', min: 0, max: 1, step: 0.01 },
54+
control: { type: 'range', min: 0, max: 2, step: 0.01 },
5355
},
5456
className: { control: { type: 'text' } },
5557
},

docs/storybook/stories/agents-ui/AgentAudioVisualizerBar.stories.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,17 @@ import * as React from 'react';
22
import { StoryObj } from '@storybook/react-vite';
33
import { useSessionContext } from '@livekit/components-react';
44
import { AgentSessionProvider } from '../../.storybook/lk-decorators/AgentSessionProvider';
5-
import {
6-
AgentAudioVisualizerBar,
7-
AgentAudioVisualizerBarElementVariants,
8-
AgentAudioVisualizerBarProps,
9-
} from '@agents-ui';
10-
import { cn } from '@/lib/utils';
5+
import { AgentAudioVisualizerBar, AgentAudioVisualizerBarProps } from '@agents-ui';
116

127
export default {
138
component: AgentAudioVisualizerBar,
149
decorators: [AgentSessionProvider],
15-
render: ({ color, ...args }: AgentAudioVisualizerBarProps & { color?: string }) => {
10+
render: (args: AgentAudioVisualizerBarProps) => {
1611
const {
1712
local: { microphoneTrack },
1813
} = useSessionContext();
1914

20-
return (
21-
<div style={{ color }}>
22-
<AgentAudioVisualizerBar {...args} audioTrack={microphoneTrack} />
23-
</div>
24-
);
15+
return <AgentAudioVisualizerBar {...args} audioTrack={microphoneTrack} />;
2516
},
2617
args: {
2718
size: 'xl',

docs/storybook/stories/agents-ui/AgentAudioVisualizerGrid.stories.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ import { cn } from '@/lib/utils';
1212
export default {
1313
component: AgentAudioVisualizerGrid,
1414
decorators: [AgentSessionProvider],
15-
render: ({ color, ...args }: AgentAudioVisualizerGridProps & { color?: string }) => {
15+
render: (args: AgentAudioVisualizerGridProps) => {
1616
const {
1717
local: { microphoneTrack },
1818
} = useSessionContext();
1919

20-
return (
21-
<div style={{ color }}>
22-
<AgentAudioVisualizerGrid {...args} audioTrack={microphoneTrack} />
23-
</div>
24-
);
20+
return <AgentAudioVisualizerGrid {...args} audioTrack={microphoneTrack} />;
2521
},
2622
args: {
2723
size: 'lg',

docs/storybook/stories/agents-ui/AgentAudioVisualizerRadial.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default {
1818
size: 'lg',
1919
state: 'connecting',
2020
radius: undefined,
21+
color: undefined,
2122
},
2223
argTypes: {
2324
size: {
@@ -44,6 +45,7 @@ export default {
4445
radius: {
4546
control: { type: 'range', min: 1, max: 500, step: 1 },
4647
},
48+
color: { control: { type: 'color' } },
4749
className: { control: { type: 'text' } },
4850
},
4951
parameters: {

docs/storybook/stories/agents-ui/AgentAudioVisualizerWave.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default {
2020
state: 'connecting',
2121
blur: 0.1,
2222
color: '#1FD5F9',
23+
colorShift: 0.3,
2324
},
2425
argTypes: {
2526
size: {
@@ -49,6 +50,9 @@ export default {
4950
color: {
5051
control: { type: 'color' },
5152
},
53+
colorShift: {
54+
control: { type: 'range', min: 0, max: 2, step: 0.1 },
55+
},
5256
},
5357
parameters: {
5458
layout: 'centered',

packages/shadcn/components/agents-ui/agent-audio-visualizer-bar.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export interface AgentAudioVisualizerBarProps {
9393
* @defaultValue 'connecting'
9494
*/
9595
state?: AgentState;
96+
/**
97+
* The color of the bars.
98+
*/
99+
color?: string;
96100
/**
97101
* The number of bars to display in the visualizer.
98102
* If not provided, defaults based on size: 3 for 'icon'/'sm', 5 for others.
@@ -132,10 +136,12 @@ export interface AgentAudioVisualizerBarProps {
132136
export function AgentAudioVisualizerBar({
133137
size = 'md',
134138
state = 'connecting',
139+
color,
135140
barCount,
136141
audioTrack,
137142
className,
138143
children,
144+
style,
139145
...props
140146
}: AgentAudioVisualizerBarProps &
141147
VariantProps<typeof AgentAudioVisualizerBarVariants> &
@@ -192,6 +198,7 @@ export function AgentAudioVisualizerBar({
192198
return (
193199
<div
194200
data-lk-state={state}
201+
style={{ ...style, color } as CSSProperties}
195202
className={cn(AgentAudioVisualizerBarVariants({ size }), className)}
196203
{...props}
197204
>

packages/shadcn/components/agents-ui/agent-audio-visualizer-grid.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ export type AgentAudioVisualizerGridProps = GridOptions & {
198198
* @defaultValue 'connecting'
199199
*/
200200
state?: AgentState;
201+
/**
202+
* The color of the grid cells.
203+
* @defaultValue '#1FD5F9'
204+
*/
205+
color?: string;
201206
/**
202207
* The audio track to visualize. Can be a local/remote audio track or a track reference.
203208
*/
@@ -235,6 +240,7 @@ export function AgentAudioVisualizerGrid({
235240
size = 'md',
236241
state = 'connecting',
237242
radius,
243+
color,
238244
rowCount: _rowCount = 5,
239245
columnCount: _columnCount = 5,
240246
interval = 100,
@@ -266,7 +272,9 @@ export function AgentAudioVisualizerGrid({
266272
<div
267273
data-lk-state={state}
268274
className={cn(AgentAudioVisualizerGridVariants({ size }), className)}
269-
style={{ ...style, gridTemplateColumns: `repeat(${columnCount}, 1fr)` }}
275+
style={
276+
{ ...style, gridTemplateColumns: `repeat(${columnCount}, 1fr)`, color } as CSSProperties
277+
}
270278
{...props}
271279
>
272280
{items.map((idx) => (

packages/shadcn/components/agents-ui/agent-audio-visualizer-radial.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { type ComponentProps, useMemo } from 'react';
3+
import { type ComponentProps, CSSProperties, useMemo } from 'react';
44
import { type VariantProps, cva } from 'class-variance-authority';
55
import { type LocalAudioTrack, type RemoteAudioTrack } from 'livekit-client';
66
import {
@@ -52,6 +52,11 @@ export interface AgentAudioVisualizerRadialProps {
5252
* @defaultValue 'connecting'
5353
*/
5454
state?: AgentState;
55+
/**
56+
* The color of the radial bars.
57+
* @defaultValue '#1FD5F9'
58+
*/
59+
color?: string;
5560
/**
5661
* The radius (distance from center) for the radial bars.
5762
* If not provided, defaults based on size.
@@ -93,10 +98,12 @@ export interface AgentAudioVisualizerRadialProps {
9398
export function AgentAudioVisualizerRadial({
9499
size = 'md',
95100
state = 'connecting',
101+
color,
96102
radius,
97103
barCount,
98104
audioTrack,
99105
className,
106+
style,
100107
...props
101108
}: AgentAudioVisualizerRadialProps &
102109
ComponentProps<'div'> &
@@ -175,6 +182,7 @@ export function AgentAudioVisualizerRadial({
175182
<div
176183
data-lk-state={state}
177184
className={cn(AgentAudioVisualizerRadialVariants({ size }), 'relative', className)}
185+
style={{ ...style, color } as CSSProperties}
178186
{...props}
179187
>
180188
{bands.map((band, idx) => {

packages/shadcn/components/agents-ui/agent-audio-visualizer-wave.tsx

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function hexToRgb(hexColor: string) {
2121

2222
return color;
2323
}
24-
} catch (error) {
24+
} catch {
2525
console.error(
2626
`Invalid hex color '${hexColor}'.\nFalling back to default color '${DEFAULT_COLOR}'.`,
2727
);
@@ -45,6 +45,23 @@ float luma(vec3 color) {
4545
return dot(color, vec3(0.299, 0.587, 0.114));
4646
}
4747
48+
// RGB to HSV
49+
vec3 rgb2hsv(vec3 c) {
50+
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
51+
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
52+
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
53+
float d = q.x - min(q.w, q.y);
54+
float e = 1.0e-10;
55+
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
56+
}
57+
58+
// HSV to RGB
59+
vec3 hsv2rgb(vec3 c) {
60+
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
61+
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
62+
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
63+
}
64+
4865
// Bell curve function for attenuation from center with rounded top
4966
float bellCurve(float distanceFromCenter, float maxDistance) {
5067
float normalizedDistance = distanceFromCenter / maxDistance;
@@ -105,9 +122,18 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
105122
// Solid line with smooth edges using minimum distance
106123
float line = smoothstep(lineWidthUV + smoothingUV, lineWidthUV - smoothingUV, minDist);
107124
108-
// Calculate color position based on x position for gradient effect
109-
float colorPos = x;
110125
vec3 color = uColor;
126+
if(abs(uColorShift) > 0.01) {
127+
// Keep the center 50% at base color, then ramp shift across outer 25% on each side.
128+
float centerBandHalfWidth = 0.2;
129+
float edgeBandWidth = 0.5;
130+
float distanceFromCenter = abs(x - centerX);
131+
float edgeFactor = clamp((distanceFromCenter - centerBandHalfWidth) / edgeBandWidth, 0.0, 1.0);
132+
vec3 hsv = rgb2hsv(color);
133+
// Hue shift is zero in the center band and strongest at far edges.
134+
hsv.x = fract(hsv.x + edgeFactor * uColorShift * 0.3);
135+
color = hsv2rgb(hsv);
136+
}
111137
112138
// Apply line intensity
113139
color *= line;
@@ -147,6 +173,11 @@ interface WaveShaderProps {
147173
* @default '#1FD5F9'
148174
*/
149175
color?: string;
176+
/**
177+
* Hue shift amount applied toward the outside of the wave. Center remains at the base color.
178+
* @default 0.05
179+
*/
180+
colorShift?: number;
150181
/**
151182
* Mix of the oscilloscope
152183
* @default 1.0
@@ -167,6 +198,7 @@ interface WaveShaderProps {
167198
function WaveShader({
168199
speed = 10,
169200
color = '#1FD5F9',
201+
colorShift = 0.05,
170202
mix = 1.0,
171203
amplitude = 0.02,
172204
frequency = 20.0,
@@ -191,6 +223,7 @@ function WaveShader({
191223
uLineWidth: { type: '1f', value: lineWidth },
192224
uSmoothing: { type: '1f', value: blur },
193225
uColor: { type: '3fv', value: rgbColor },
226+
uColorShift: { type: '1f', value: colorShift },
194227
}}
195228
onError={(error) => {
196229
console.error('Shader error:', error);
@@ -237,6 +270,11 @@ export interface AgentAudioVisualizerWaveProps {
237270
* @defaultValue '#1FD5F9'
238271
*/
239272
color?: string;
273+
/**
274+
* The color shift of the wave. Higher values increase hue variation toward the edges.
275+
* @defaultValue 0.05
276+
*/
277+
colorShift?: number;
240278
/**
241279
* The line width of the wave in pixels.
242280
* @defaultValue 2.0
@@ -269,6 +307,7 @@ export interface AgentAudioVisualizerWaveProps {
269307
* size="lg"
270308
* state="speaking"
271309
* color="#1FD5F9"
310+
* colorShift={0.3}
272311
* lineWidth={2}
273312
* blur={0.5}
274313
* audioTrack={audioTrack}
@@ -279,6 +318,7 @@ export function AgentAudioVisualizerWave({
279318
size = 'lg',
280319
state = 'speaking',
281320
color,
321+
colorShift = 0.05,
282322
lineWidth,
283323
blur,
284324
audioTrack,
@@ -312,6 +352,8 @@ export function AgentAudioVisualizerWave({
312352
data-lk-state={state}
313353
speed={speed}
314354
color={color}
355+
colorShift={colorShift}
356+
mix={opacity}
315357
amplitude={amplitude}
316358
frequency={frequency}
317359
lineWidth={_lineWidth}

0 commit comments

Comments
 (0)