orb-ui 0.6.1 → 0.8.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 +99 -37
- package/dist/adapters/audio-level.d.ts +57 -20
- package/dist/adapters/elevenlabs/index.d.ts +13 -2
- package/dist/adapters/gemini-live/index.d.ts +9 -5
- package/dist/adapters/index.d.ts +3 -2
- package/dist/adapters/livekit/browser.d.ts +9 -5
- package/dist/adapters/livekit/index.d.ts +9 -5
- package/dist/adapters/openai-realtime/index.d.ts +9 -5
- package/dist/adapters/pipecat/index.d.ts +9 -5
- package/dist/adapters/types.d.ts +0 -5
- package/dist/adapters/vapi/index.d.ts +29 -3
- package/dist/adapters/volume-presets.d.ts +35 -0
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +405 -457
- package/dist/components/Orb/Orb.d.ts +1 -1
- package/dist/components/Orb/Orb.types.d.ts +92 -15
- package/dist/components/Orb/OrbThemeProvider.d.ts +16 -0
- package/dist/components/Orb/index.d.ts +6 -1
- package/dist/components/Orb/signals.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/livekit-7Re8E7By.js +394 -0
- package/dist/livekit-C36Kmz6s.cjs +1 -0
- package/dist/livekit-adapter.cjs +1 -1
- package/dist/livekit-adapter.js +6 -4
- package/dist/orb-ui.cjs +96 -4
- package/dist/orb-ui.js +1461 -407
- package/dist/themes/bars/BarsTheme.d.ts +8 -4
- package/dist/themes/circle/CircleTheme.d.ts +8 -4
- package/dist/themes/cloud/CloudTheme.d.ts +8 -4
- package/dist/themes/config.d.ts +151 -0
- package/dist/themes/css-variables.d.ts +5 -0
- package/dist/themes/debug/DebugTheme.d.ts +11 -6
- package/dist/themes/index.d.ts +1 -0
- package/dist/themes/radial/RadialTheme.d.ts +19 -0
- package/dist/themes/radial/index.d.ts +1 -0
- package/dist/themes/slots.d.ts +4 -0
- package/package.json +3 -2
- package/dist/livekit-CukEeYFK.js +0 -316
- package/dist/livekit-Dt-QZ6Gs.cjs +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { OrbProps } from './Orb.types.js';
|
|
2
|
-
export declare function Orb(
|
|
2
|
+
export declare function Orb(props: OrbProps): string | number | boolean | Iterable<import('react').ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { AriaAttributes, CSSProperties } from 'react';
|
|
1
|
+
import { AriaAttributes, CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import { OrbTheme } from '../../themes/config.js';
|
|
3
|
+
export type { BarsAppearance, BarsGeometry, BarsMotion, BarsThemeConfig, CircleAppearance, CircleGeometry, CircleMotion, CircleThemeConfig, CloudAppearance, CloudGeometry, CloudMotion, CloudThemeConfig, DebugAppearance, DebugGeometry, DebugMotion, DebugThemeConfig, OrbTheme, OrbThemeConfig, OrbThemeName, OrbThemePreset, RadialAppearance, RadialGeometry, RadialMotion, RadialThemeConfig, } from '../../themes/config.js';
|
|
4
|
+
export type OrbStyle = CSSProperties & {
|
|
5
|
+
/** Responsive rendered size, for example `min(70vw, 320px)`. */
|
|
6
|
+
'--orb-ui-size'?: string;
|
|
7
|
+
/** Typed access to the stable orb-ui design-token namespace. */
|
|
8
|
+
[cssVariable: `--orb-ui-${string}`]: string | number | undefined;
|
|
9
|
+
};
|
|
2
10
|
export type OrbState = 'idle' | 'connecting' | 'listening' | 'thinking' | 'speaking' | 'error';
|
|
3
|
-
export type OrbTheme = 'debug' | 'circle' | 'bars' | 'cloud';
|
|
4
11
|
export interface OrbSignal {
|
|
5
12
|
state: OrbState;
|
|
6
|
-
volume?: number;
|
|
7
13
|
inputVolume?: number;
|
|
8
14
|
outputVolume?: number;
|
|
9
15
|
error?: unknown;
|
|
@@ -33,6 +39,77 @@ export interface OrbHtmlAttributes extends AriaAttributes {
|
|
|
33
39
|
/** Forward data-* attributes, e.g. data-testid. */
|
|
34
40
|
[dataAttribute: `data-${string}`]: DataAttributeValue;
|
|
35
41
|
}
|
|
42
|
+
export interface OrbSlotAttributes extends AriaAttributes {
|
|
43
|
+
className?: string;
|
|
44
|
+
style?: CSSProperties;
|
|
45
|
+
id?: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
role?: string;
|
|
48
|
+
[dataAttribute: `data-${string}`]: DataAttributeValue;
|
|
49
|
+
}
|
|
50
|
+
/** Stable semantic hooks shared by the built-in themes. Unsupported slots are ignored. */
|
|
51
|
+
export interface OrbSlotProps {
|
|
52
|
+
root?: OrbSlotAttributes;
|
|
53
|
+
content?: OrbSlotAttributes;
|
|
54
|
+
surface?: OrbSlotAttributes;
|
|
55
|
+
glow?: OrbSlotAttributes;
|
|
56
|
+
bar?: OrbSlotAttributes;
|
|
57
|
+
launch?: OrbSlotAttributes;
|
|
58
|
+
spinner?: OrbSlotAttributes;
|
|
59
|
+
control?: OrbSlotAttributes;
|
|
60
|
+
icon?: OrbSlotAttributes;
|
|
61
|
+
header?: OrbSlotAttributes;
|
|
62
|
+
label?: OrbSlotAttributes;
|
|
63
|
+
meterTrack?: OrbSlotAttributes;
|
|
64
|
+
meterFill?: OrbSlotAttributes;
|
|
65
|
+
actions?: OrbSlotAttributes;
|
|
66
|
+
}
|
|
67
|
+
export type OrbSlotName = keyof OrbSlotProps;
|
|
68
|
+
export interface OrbThemeComponentContext {
|
|
69
|
+
state: OrbState;
|
|
70
|
+
active: boolean;
|
|
71
|
+
connecting: boolean;
|
|
72
|
+
disabled: boolean;
|
|
73
|
+
size: number;
|
|
74
|
+
}
|
|
75
|
+
export type OrbThemeComponent = ReactNode | ((context: OrbThemeComponentContext) => ReactNode);
|
|
76
|
+
/** Replace small pieces of built-in theme chrome without replacing the entire renderer. */
|
|
77
|
+
export interface OrbThemeComponents {
|
|
78
|
+
controlIcon?: OrbThemeComponent;
|
|
79
|
+
connectingIndicator?: OrbThemeComponent;
|
|
80
|
+
}
|
|
81
|
+
export interface OrbThemeRendererRootProps extends OrbHtmlAttributes {
|
|
82
|
+
ref: (element: HTMLElement | null) => void;
|
|
83
|
+
className?: string;
|
|
84
|
+
style?: OrbStyle;
|
|
85
|
+
}
|
|
86
|
+
export interface OrbThemeRendererControlProps extends OrbHtmlAttributes {
|
|
87
|
+
type: 'button';
|
|
88
|
+
className?: string;
|
|
89
|
+
style?: CSSProperties;
|
|
90
|
+
disabled: boolean;
|
|
91
|
+
onClick?: () => void;
|
|
92
|
+
}
|
|
93
|
+
export interface OrbThemeRendererProps {
|
|
94
|
+
state: OrbState;
|
|
95
|
+
signal: OrbSignal;
|
|
96
|
+
inputVolume: number;
|
|
97
|
+
outputVolume: number;
|
|
98
|
+
/** Direction-selected normalized activity for the current state. */
|
|
99
|
+
activity: number;
|
|
100
|
+
size: number;
|
|
101
|
+
isActive: boolean;
|
|
102
|
+
interactive: boolean;
|
|
103
|
+
disabled: boolean;
|
|
104
|
+
start: () => void | Promise<void>;
|
|
105
|
+
stop: () => void | Promise<void>;
|
|
106
|
+
toggle: () => void | Promise<void>;
|
|
107
|
+
/** Apply to the custom artwork's outer element for sizing, styling, and diagnostics. */
|
|
108
|
+
rootProps: OrbThemeRendererRootProps;
|
|
109
|
+
/** Apply to its button to preserve Orb's lifecycle and accessible control contract. */
|
|
110
|
+
controlProps: OrbThemeRendererControlProps;
|
|
111
|
+
}
|
|
112
|
+
export type OrbThemeRenderer = (props: OrbThemeRendererProps) => ReactNode;
|
|
36
113
|
export interface OrbProps extends OrbHtmlAttributes {
|
|
37
114
|
/**
|
|
38
115
|
* Current voice signal. Use this controlled mode when your app has separate
|
|
@@ -44,28 +121,29 @@ export interface OrbProps extends OrbHtmlAttributes {
|
|
|
44
121
|
* Overrides signal and adapter state if provided.
|
|
45
122
|
*/
|
|
46
123
|
state?: OrbState;
|
|
47
|
-
/**
|
|
48
|
-
* Current audio volume, normalized 0–1.
|
|
49
|
-
* Overrides signal and adapter volume if provided.
|
|
50
|
-
*/
|
|
51
|
-
volume?: number;
|
|
52
124
|
/**
|
|
53
125
|
* Provider adapter (Vapi, ElevenLabs, etc.).
|
|
54
126
|
* Handles signal updates automatically from the SDK.
|
|
55
127
|
*/
|
|
56
128
|
adapter?: OrbAdapter;
|
|
57
|
-
/**
|
|
129
|
+
/** Theme name or preset/override object. Defaults to 'debug'. */
|
|
58
130
|
theme?: OrbTheme;
|
|
59
131
|
/** Size in pixels. Defaults to 200. */
|
|
60
132
|
size?: number;
|
|
61
133
|
/** Optional class name for the rendered orb container/control. */
|
|
62
134
|
className?: string;
|
|
63
135
|
/** Optional inline styles for the rendered orb container/control. */
|
|
64
|
-
style?:
|
|
65
|
-
/**
|
|
136
|
+
style?: OrbStyle;
|
|
137
|
+
/** Stable style/class hooks for semantic pieces of built-in themes. */
|
|
138
|
+
slotProps?: OrbSlotProps;
|
|
139
|
+
/** Replace supported built-in controls such as the radial phone icon and spinner. */
|
|
140
|
+
components?: OrbThemeComponents;
|
|
141
|
+
/** Render completely custom artwork while Orb keeps signal and lifecycle ownership. */
|
|
142
|
+
renderTheme?: OrbThemeRenderer;
|
|
143
|
+
/** Disable interactive theme and debug start/stop controls. */
|
|
66
144
|
disabled?: boolean;
|
|
67
145
|
/**
|
|
68
|
-
* Allow the
|
|
146
|
+
* Allow the rendered theme control to start and stop an adapter-backed session.
|
|
69
147
|
* Set this to false when session controls live elsewhere in your UI.
|
|
70
148
|
*/
|
|
71
149
|
interactive?: boolean;
|
|
@@ -73,11 +151,10 @@ export interface OrbProps extends OrbHtmlAttributes {
|
|
|
73
151
|
* Called when a clickable theme is activated while idle/error.
|
|
74
152
|
* Overrides adapter.start() when provided.
|
|
75
153
|
*/
|
|
76
|
-
onStart?: () => void
|
|
154
|
+
onStart?: () => void | Promise<void>;
|
|
77
155
|
/**
|
|
78
156
|
* Called when a clickable theme is activated while active.
|
|
79
157
|
* Overrides adapter.stop() when provided.
|
|
80
158
|
*/
|
|
81
|
-
onStop?: () => void
|
|
159
|
+
onStop?: () => void | Promise<void>;
|
|
82
160
|
}
|
|
83
|
-
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { OrbSlotProps, OrbStyle, OrbTheme, OrbThemeComponents, OrbThemeRenderer } from './Orb.types.js';
|
|
3
|
+
export interface OrbThemeDefaults {
|
|
4
|
+
theme?: OrbTheme;
|
|
5
|
+
size?: number;
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: OrbStyle;
|
|
8
|
+
slotProps?: OrbSlotProps;
|
|
9
|
+
components?: OrbThemeComponents;
|
|
10
|
+
renderTheme?: OrbThemeRenderer;
|
|
11
|
+
}
|
|
12
|
+
export interface OrbThemeProviderProps extends OrbThemeDefaults {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export declare function OrbThemeProvider({ children, theme, size, className, style, slotProps, components, renderTheme, }: OrbThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare function useOrbThemeDefaults(): OrbThemeDefaults | undefined;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export { Orb } from './Orb.js';
|
|
2
|
-
export
|
|
2
|
+
export { OrbThemeProvider } from './OrbThemeProvider.js';
|
|
3
|
+
export type { OrbThemeDefaults, OrbThemeProviderProps } from './OrbThemeProvider.js';
|
|
4
|
+
export { defineOrbTheme } from '../../themes/config.js';
|
|
5
|
+
export { orbThemeCssVariable } from '../../themes/css-variables.js';
|
|
6
|
+
export type { OrbThemeCssSection } from '../../themes/css-variables.js';
|
|
7
|
+
export type { BarsAppearance, BarsGeometry, BarsMotion, BarsThemeConfig, CircleAppearance, CircleGeometry, CircleMotion, CircleThemeConfig, CloudAppearance, CloudGeometry, CloudMotion, CloudThemeConfig, DebugAppearance, DebugGeometry, DebugMotion, DebugThemeConfig, OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbSlotAttributes, OrbSlotName, OrbSlotProps, OrbState, OrbStyle, OrbTheme, OrbThemeComponent, OrbThemeComponentContext, OrbThemeComponents, OrbThemeConfig, OrbThemeName, OrbThemePreset, OrbThemeRenderer, OrbThemeRendererControlProps, OrbThemeRendererProps, OrbThemeRendererRootProps, RadialAppearance, RadialGeometry, RadialMotion, RadialThemeConfig, } from './Orb.types.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { OrbSignal, OrbState } from './Orb.types.js';
|
|
2
2
|
export declare function deriveOrbState(state: OrbState | undefined, signal: OrbSignal | undefined, adapterSignal: OrbSignal): OrbState;
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function selectOrbVolume(state: OrbState, signal: OrbSignal): number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Orb } from './components/Orb/index.js';
|
|
2
|
-
export type { OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbState, OrbTheme, } from './components/Orb/index.js';
|
|
1
|
+
export { Orb, OrbThemeProvider, defineOrbTheme, orbThemeCssVariable } from './components/Orb/index.js';
|
|
2
|
+
export type { OrbAdapter, OrbProps, OrbSignal, OrbSignalListener, OrbSlotAttributes, OrbSlotName, OrbSlotProps, OrbState, OrbStyle, OrbTheme, OrbThemeComponent, OrbThemeComponentContext, OrbThemeComponents, OrbThemeConfig, OrbThemeCssSection, OrbThemeDefaults, OrbThemeName, OrbThemePreset, OrbThemeProviderProps, OrbThemeRenderer, OrbThemeRendererControlProps, OrbThemeRendererProps, OrbThemeRendererRootProps, BarsAppearance, BarsGeometry, BarsMotion, BarsThemeConfig, CircleAppearance, CircleGeometry, CircleMotion, CircleThemeConfig, CloudAppearance, CloudGeometry, CloudMotion, CloudThemeConfig, DebugAppearance, DebugGeometry, DebugMotion, DebugThemeConfig, RadialAppearance, RadialGeometry, RadialMotion, RadialThemeConfig, } from './components/Orb/index.js';
|
|
3
3
|
export { Orb as VoiceOrb } from './components/Orb/index.js';
|
|
4
4
|
export type { OrbProps as VoiceOrbProps } from './components/Orb/index.js';
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
//#region src/adapters/audio-level.ts
|
|
2
|
+
var e = 1e-6, t = 1e3 / 30, n = {
|
|
3
|
+
amplitude: {
|
|
4
|
+
silenceFloor: 0,
|
|
5
|
+
speechReference: .5,
|
|
6
|
+
speechPeak: 1
|
|
7
|
+
},
|
|
8
|
+
envelope: {
|
|
9
|
+
riseTimeMs: 100,
|
|
10
|
+
fallTimeMs: 400
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
function r(e, t, n) {
|
|
14
|
+
return Math.min(n, Math.max(t, e));
|
|
15
|
+
}
|
|
16
|
+
function i(e, t) {
|
|
17
|
+
return typeof e == "number" && Number.isFinite(e) ? e : t;
|
|
18
|
+
}
|
|
19
|
+
function a(t, n) {
|
|
20
|
+
let a = r(i(n?.silenceFloor, t.silenceFloor), 0, 1 - e * 2), o = r(i(n?.speechReference, t.speechReference), a + e, 1 - e);
|
|
21
|
+
return {
|
|
22
|
+
silenceFloor: a,
|
|
23
|
+
speechReference: o,
|
|
24
|
+
speechPeak: r(i(n?.speechPeak, t.speechPeak), o + e, 1)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function o(e, t) {
|
|
28
|
+
let n = typeof t == "function" ? t() : t;
|
|
29
|
+
return {
|
|
30
|
+
amplitude: a(e.amplitude, n?.amplitude),
|
|
31
|
+
envelope: {
|
|
32
|
+
riseTimeMs: Math.max(0, i(n?.envelope?.riseTimeMs, e.envelope.riseTimeMs)),
|
|
33
|
+
fallTimeMs: Math.max(0, i(n?.envelope?.fallTimeMs, e.envelope.fallTimeMs))
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function s(t, i) {
|
|
38
|
+
let o = a(n.amplitude, i), s = Number.isFinite(t) ? r(t, 0, 1) : 0;
|
|
39
|
+
if (s <= o.silenceFloor) return 0;
|
|
40
|
+
if (s >= o.speechPeak) return 1;
|
|
41
|
+
let c = o.speechPeak - o.silenceFloor, l = r((s - o.silenceFloor) / c, 0, 1), u = r((o.speechReference - o.silenceFloor) / c, e, 1 - e);
|
|
42
|
+
return r(l ** +(Math.log(.5) / Math.log(u)), 0, 1);
|
|
43
|
+
}
|
|
44
|
+
function c(e, t, n, i) {
|
|
45
|
+
if (n <= 0) return t;
|
|
46
|
+
let a = 1 - .1 ** (Math.max(0, i) / n);
|
|
47
|
+
return r(e + (t - e) * a, 0, 1);
|
|
48
|
+
}
|
|
49
|
+
function l(e, t, i, a = n, l) {
|
|
50
|
+
let u = o(a, l), d = Number.isFinite(e) ? r(e, 0, 1) : 0, f = s(d, u.amplitude);
|
|
51
|
+
return {
|
|
52
|
+
raw: d,
|
|
53
|
+
mapped: f,
|
|
54
|
+
normalized: c(t, f, f > t ? u.envelope.riseTimeMs : u.envelope.fallTimeMs, i),
|
|
55
|
+
elapsedMs: i
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function u(e = n, i) {
|
|
59
|
+
let a = 0, o;
|
|
60
|
+
return {
|
|
61
|
+
sample(n, s = performance.now()) {
|
|
62
|
+
let c = o === void 0 ? t : r(s - o, 0, 1e3);
|
|
63
|
+
o = s;
|
|
64
|
+
let u = l(n, a, c, e, i);
|
|
65
|
+
return a = u.normalized, u;
|
|
66
|
+
},
|
|
67
|
+
reset(e = 0) {
|
|
68
|
+
a = r(e, 0, 1), o = void 0;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function d(e, t) {
|
|
73
|
+
let n = e.filter((e) => Number.isFinite(e)).map((e) => r(e, 0, 1)).sort((e, t) => e - t);
|
|
74
|
+
if (n.length === 0) return 0;
|
|
75
|
+
let i = r(t, 0, 1) * (n.length - 1), a = Math.floor(i), o = Math.ceil(i), s = i - a;
|
|
76
|
+
return n[a] + (n[o] - n[a]) * s;
|
|
77
|
+
}
|
|
78
|
+
function f(e, t, n) {
|
|
79
|
+
return d(e.map((e) => s(e, n)), t);
|
|
80
|
+
}
|
|
81
|
+
function p(e, t = n.envelope) {
|
|
82
|
+
for (let t of [
|
|
83
|
+
"silence",
|
|
84
|
+
"quiet",
|
|
85
|
+
"normal",
|
|
86
|
+
"energetic"
|
|
87
|
+
]) if (!e[t].some((e) => Number.isFinite(e))) throw Error(`Volume calibration requires at least one ${t} sample.`);
|
|
88
|
+
let r = d(e.silence, .99), o = d(e.normal, .5), c = Math.max(d(e.energetic, .99), d(e.normal, .99)), l = Math.max(0, o - r), u = {
|
|
89
|
+
amplitude: a(n.amplitude, {
|
|
90
|
+
silenceFloor: r + Math.min(.005, l * .05),
|
|
91
|
+
speechReference: o,
|
|
92
|
+
speechPeak: c
|
|
93
|
+
}),
|
|
94
|
+
envelope: {
|
|
95
|
+
riseTimeMs: Math.max(0, i(t.riseTimeMs, 100)),
|
|
96
|
+
fallTimeMs: Math.max(0, i(t.fallTimeMs, 400))
|
|
97
|
+
}
|
|
98
|
+
}, p = [
|
|
99
|
+
...e.quiet,
|
|
100
|
+
...e.normal,
|
|
101
|
+
...e.energetic
|
|
102
|
+
].map((e) => s(e, u.amplitude));
|
|
103
|
+
return {
|
|
104
|
+
calibration: u,
|
|
105
|
+
metrics: {
|
|
106
|
+
silenceP99: f(e.silence, .99, u.amplitude),
|
|
107
|
+
quietMedian: f(e.quiet, .5, u.amplitude),
|
|
108
|
+
normalMedian: f(e.normal, .5, u.amplitude),
|
|
109
|
+
energeticMedian: f(e.energetic, .5, u.amplitude),
|
|
110
|
+
speechP99: d(p, .99),
|
|
111
|
+
saturationRatio: p.length === 0 ? 0 : p.filter((e) => e >= .999).length / p.length
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function m(e, t, n) {
|
|
116
|
+
let r;
|
|
117
|
+
try {
|
|
118
|
+
if (r = t(), !r) return;
|
|
119
|
+
let i = r;
|
|
120
|
+
i.state === "suspended" && i.resume().catch(() => void 0);
|
|
121
|
+
let a = i.createMediaStreamSource(new MediaStream([e])), o = i.createAnalyser();
|
|
122
|
+
o.fftSize = 512, o.smoothingTimeConstant = .25, a.connect(o);
|
|
123
|
+
let s = new Float32Array(o.fftSize), c = setInterval(() => {
|
|
124
|
+
o.getFloatTimeDomainData(s);
|
|
125
|
+
let e = 0;
|
|
126
|
+
for (let t of s) e += t * t;
|
|
127
|
+
n(Math.sqrt(e / s.length));
|
|
128
|
+
}, 33);
|
|
129
|
+
return { async stop() {
|
|
130
|
+
clearInterval(c);
|
|
131
|
+
try {
|
|
132
|
+
a.disconnect(), o.disconnect();
|
|
133
|
+
} finally {
|
|
134
|
+
i.state !== "closed" && await i.close();
|
|
135
|
+
}
|
|
136
|
+
} };
|
|
137
|
+
} catch {
|
|
138
|
+
r?.state !== "closed" && r?.close().catch(() => void 0);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/adapters/volume-presets.ts
|
|
144
|
+
var h = {
|
|
145
|
+
riseTimeMs: 100,
|
|
146
|
+
fallTimeMs: 400
|
|
147
|
+
};
|
|
148
|
+
function g(e, t, n) {
|
|
149
|
+
return {
|
|
150
|
+
amplitude: {
|
|
151
|
+
silenceFloor: e,
|
|
152
|
+
speechReference: t,
|
|
153
|
+
speechPeak: n
|
|
154
|
+
},
|
|
155
|
+
envelope: { ...h }
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
var _ = {
|
|
159
|
+
vapi: {
|
|
160
|
+
input: g(0, .105112, .25),
|
|
161
|
+
output: g(.005, .4, 1)
|
|
162
|
+
},
|
|
163
|
+
elevenlabs: {
|
|
164
|
+
input: g(0, .36, .52),
|
|
165
|
+
output: g(0, .4, .55)
|
|
166
|
+
},
|
|
167
|
+
livekit: {
|
|
168
|
+
input: g(0, .18, .4),
|
|
169
|
+
output: g(.015, .18, .3)
|
|
170
|
+
},
|
|
171
|
+
pipecat: {
|
|
172
|
+
input: g(.002, .107112, .252),
|
|
173
|
+
output: g(.002, .084441, .198078)
|
|
174
|
+
},
|
|
175
|
+
openai: {
|
|
176
|
+
input: g(0, .105112, .25),
|
|
177
|
+
output: g(.003, .07, .2)
|
|
178
|
+
},
|
|
179
|
+
gemini: {
|
|
180
|
+
input: g(0, .105112, .25),
|
|
181
|
+
output: g(.003, .17, .38)
|
|
182
|
+
}
|
|
183
|
+
}, v = 4, y = {
|
|
184
|
+
fftSize: 512,
|
|
185
|
+
smoothingTimeConstant: .25,
|
|
186
|
+
minDecibels: -85,
|
|
187
|
+
maxDecibels: -20
|
|
188
|
+
};
|
|
189
|
+
function b(e) {
|
|
190
|
+
switch (e) {
|
|
191
|
+
case "speaking": return "speaking";
|
|
192
|
+
case "thinking": return "thinking";
|
|
193
|
+
case "listening":
|
|
194
|
+
case "idle": return "listening";
|
|
195
|
+
case "connecting":
|
|
196
|
+
case "pre-connect-buffering":
|
|
197
|
+
case "initializing": return "connecting";
|
|
198
|
+
case "disconnected": return "idle";
|
|
199
|
+
case "failed": return "error";
|
|
200
|
+
default: return "idle";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function x(e) {
|
|
204
|
+
return "RoomClass" in e;
|
|
205
|
+
}
|
|
206
|
+
function S(e) {
|
|
207
|
+
return typeof e == "function" ? e() : e;
|
|
208
|
+
}
|
|
209
|
+
function C(e) {
|
|
210
|
+
if (!e) return {};
|
|
211
|
+
let t = {}, n = (e, n) => {
|
|
212
|
+
n !== void 0 && (t[e] = n);
|
|
213
|
+
};
|
|
214
|
+
return n("roomName", S(e.roomName)), n("participantName", S(e.participantName)), n("participantIdentity", S(e.participantIdentity)), n("participantMetadata", S(e.participantMetadata)), n("participantAttributes", typeof e.participantAttributes == "function" ? e.participantAttributes() : e.participantAttributes), n("agentName", S(e.agentName)), n("agentMetadata", S(e.agentMetadata)), n("deployment", S(e.deployment)), t;
|
|
215
|
+
}
|
|
216
|
+
function w(e) {
|
|
217
|
+
if (!e.serverUrl || !e.participantToken) throw Error("[orb-ui/livekit] connection details must include serverUrl and participantToken.");
|
|
218
|
+
return e;
|
|
219
|
+
}
|
|
220
|
+
async function T(e) {
|
|
221
|
+
let t = C(e.tokenOptions);
|
|
222
|
+
return typeof e.getConnectionDetails == "function" ? w(await e.getConnectionDetails(t)) : e.tokenSource ? w(await e.tokenSource.fetch(t)) : w({
|
|
223
|
+
serverUrl: e.serverUrl,
|
|
224
|
+
participantToken: e.participantToken
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function E(e) {
|
|
228
|
+
for (let [, t] of e.remoteParticipants) if (!t.isLocal && (t.kind === v || t.attributes?.["lk.agent.state"] !== void 0)) return t;
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
function D(e, t, n) {
|
|
232
|
+
let r = e.off;
|
|
233
|
+
if (r) {
|
|
234
|
+
r.call(e, t, n);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
e.removeListener?.call(e, t, n);
|
|
238
|
+
}
|
|
239
|
+
function O(e, t, n) {
|
|
240
|
+
e.on.call(e, t, n);
|
|
241
|
+
}
|
|
242
|
+
function k(e) {
|
|
243
|
+
let t = x(e), n = e.createAudioAnalyser, r = { current: t ? null : e.room }, i = /* @__PURE__ */ new Set(), a = {
|
|
244
|
+
state: "idle",
|
|
245
|
+
inputVolume: 0,
|
|
246
|
+
outputVolume: 0
|
|
247
|
+
}, o = "idle", s = null, c = null, l = null, d = null, f = null, p = null, m = null, h = null, g = u(_.livekit.input, e.inputVolumeCalibration), S = u(_.livekit.output, e.outputVolumeCalibration);
|
|
248
|
+
function C(e) {
|
|
249
|
+
a = e, i.forEach((t) => t(e));
|
|
250
|
+
}
|
|
251
|
+
function w(e) {
|
|
252
|
+
C({
|
|
253
|
+
...a,
|
|
254
|
+
...e,
|
|
255
|
+
state: e.state ?? a.state
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function k() {
|
|
259
|
+
S.reset(), w({ outputVolume: 0 });
|
|
260
|
+
}
|
|
261
|
+
function A({ emitZero: e = !0 } = {}) {
|
|
262
|
+
f &&= (clearInterval(f), null), d &&= (d.cleanup().catch(() => {}), null), g.reset(), e && w({ inputVolume: 0 });
|
|
263
|
+
}
|
|
264
|
+
function j(t) {
|
|
265
|
+
if (!(s === t && d)) {
|
|
266
|
+
A({ emitZero: !1 }), s = t;
|
|
267
|
+
try {
|
|
268
|
+
d = n(t, y);
|
|
269
|
+
} catch (e) {
|
|
270
|
+
console.warn("[orb-ui/livekit] local createAudioAnalyser failed:", e);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
f = setInterval(() => {
|
|
274
|
+
if (!d) return;
|
|
275
|
+
let t = g.sample(d.calculateVolume());
|
|
276
|
+
e.onInputVolumeSample?.(t), w({ inputVolume: t.normalized });
|
|
277
|
+
}, 33);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function M({ emitZero: e = !0 } = {}) {
|
|
281
|
+
m &&= (clearInterval(m), null), p &&= (p.cleanup().catch(() => {}), null), S.reset(), e && w({ outputVolume: 0 });
|
|
282
|
+
}
|
|
283
|
+
function N(t) {
|
|
284
|
+
M();
|
|
285
|
+
try {
|
|
286
|
+
p = n(t, y);
|
|
287
|
+
} catch (e) {
|
|
288
|
+
console.warn("[orb-ui/livekit] remote createAudioAnalyser failed:", e);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
m = setInterval(() => {
|
|
292
|
+
if (!p) return;
|
|
293
|
+
let t = S.sample(p.calculateVolume());
|
|
294
|
+
e.onOutputVolumeSample?.(t), w({ outputVolume: t.normalized });
|
|
295
|
+
}, 33);
|
|
296
|
+
}
|
|
297
|
+
function P(e) {
|
|
298
|
+
o = e, e === "idle" || e === "connecting" || e === "error" ? (g.reset(), S.reset(), w({
|
|
299
|
+
state: e,
|
|
300
|
+
inputVolume: 0,
|
|
301
|
+
outputVolume: 0
|
|
302
|
+
})) : w({ state: e }), c && !p && N(c);
|
|
303
|
+
}
|
|
304
|
+
function F(e) {
|
|
305
|
+
l || typeof document > "u" || (l = e.attach(), l.id = "orb-ui-livekit-agent-audio", document.body.appendChild(l));
|
|
306
|
+
}
|
|
307
|
+
function I() {
|
|
308
|
+
l &&= (l.remove(), null);
|
|
309
|
+
}
|
|
310
|
+
function L(e) {
|
|
311
|
+
c = e, F(e), N(e);
|
|
312
|
+
}
|
|
313
|
+
function R(e) {
|
|
314
|
+
j(e);
|
|
315
|
+
}
|
|
316
|
+
function z(e) {
|
|
317
|
+
let t = e.getTrackPublication?.("microphone");
|
|
318
|
+
t?.track && R(t.track);
|
|
319
|
+
}
|
|
320
|
+
function B(e) {
|
|
321
|
+
let t = b(e);
|
|
322
|
+
t !== o && P(t);
|
|
323
|
+
}
|
|
324
|
+
function V(e) {
|
|
325
|
+
let t = e.attributes?.["lk.agent.state"];
|
|
326
|
+
t && B(t);
|
|
327
|
+
let n = e.getTrackPublication("microphone");
|
|
328
|
+
n?.track && L(n.track);
|
|
329
|
+
}
|
|
330
|
+
function H(e) {
|
|
331
|
+
if (h) return;
|
|
332
|
+
let t = (e, t) => {
|
|
333
|
+
if (t.isLocal) return;
|
|
334
|
+
let n = e["lk.agent.state"];
|
|
335
|
+
n && B(n);
|
|
336
|
+
}, n = (e, t, n) => {
|
|
337
|
+
n.isLocal || !(n.kind === v || n.attributes?.["lk.agent.state"] !== void 0) || e.mediaStreamTrack.kind !== "audio" || L(e);
|
|
338
|
+
}, r = (e) => {
|
|
339
|
+
c === e && (c = null, I(), M());
|
|
340
|
+
}, i = (e) => {
|
|
341
|
+
e.source !== "microphone" || !e.track || R(e.track);
|
|
342
|
+
}, a = (e) => {
|
|
343
|
+
e.source === "microphone" && (s = null, A());
|
|
344
|
+
}, o = () => {
|
|
345
|
+
s = null, c = null, I(), A({ emitZero: !1 }), M({ emitZero: !1 }), P("idle");
|
|
346
|
+
};
|
|
347
|
+
if (O(e, "participantAttributesChanged", t), O(e, "trackSubscribed", n), O(e, "trackUnsubscribed", r), O(e, "localTrackPublished", i), O(e, "localTrackUnpublished", a), O(e, "disconnected", o), h = () => {
|
|
348
|
+
D(e, "participantAttributesChanged", t), D(e, "trackSubscribed", n), D(e, "trackUnsubscribed", r), D(e, "localTrackPublished", i), D(e, "localTrackUnpublished", a), D(e, "disconnected", o);
|
|
349
|
+
}, z(e.localParticipant), e.state === "connected") {
|
|
350
|
+
let t = E(e);
|
|
351
|
+
t ? V(t) : P("connecting");
|
|
352
|
+
} else P("idle");
|
|
353
|
+
}
|
|
354
|
+
function U() {
|
|
355
|
+
h?.(), h = null, s = null, c = null, I(), A({ emitZero: !1 }), M({ emitZero: !1 }), g.reset(), S.reset(), w({
|
|
356
|
+
inputVolume: 0,
|
|
357
|
+
outputVolume: 0
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
let W = (e) => {
|
|
361
|
+
i.add(e), e(a);
|
|
362
|
+
let t = r.current;
|
|
363
|
+
return t && H(t), () => {
|
|
364
|
+
i.delete(e), i.size === 0 && U();
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
return t ? {
|
|
368
|
+
subscribe: W,
|
|
369
|
+
async start() {
|
|
370
|
+
if (r.current) return;
|
|
371
|
+
let t = e, n = new t.RoomClass();
|
|
372
|
+
P("connecting");
|
|
373
|
+
try {
|
|
374
|
+
let e = await T(t);
|
|
375
|
+
if (await n.connect(e.serverUrl, e.participantToken, t.connectOptions), r.current = n, H(n), t.enableMicrophone !== !1) {
|
|
376
|
+
let e = (await n.localParticipant.setMicrophoneEnabled(!0))?.track ?? n.localParticipant.getTrackPublication?.("microphone")?.track;
|
|
377
|
+
e && R(e);
|
|
378
|
+
}
|
|
379
|
+
} catch (e) {
|
|
380
|
+
throw console.error("[orb-ui/livekit] connect failed:", e), r.current === n && U(), n.disconnect(), r.current = null, P("error"), k(), w({ error: e }), e;
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
async stop() {
|
|
384
|
+
let e = r.current;
|
|
385
|
+
if (!e) {
|
|
386
|
+
P("idle");
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
U(), e.disconnect(), r.current = null, P("idle");
|
|
390
|
+
}
|
|
391
|
+
} : { subscribe: W };
|
|
392
|
+
}
|
|
393
|
+
//#endregion
|
|
394
|
+
export { m as a, s as c, l as i, _ as n, u as o, n as r, p as s, k as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=1e-6,t=1e3/30,n={amplitude:{silenceFloor:0,speechReference:.5,speechPeak:1},envelope:{riseTimeMs:100,fallTimeMs:400}};function r(e,t,n){return Math.min(n,Math.max(t,e))}function i(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function a(t,n){let a=r(i(n?.silenceFloor,t.silenceFloor),0,1-e*2),o=r(i(n?.speechReference,t.speechReference),a+e,1-e);return{silenceFloor:a,speechReference:o,speechPeak:r(i(n?.speechPeak,t.speechPeak),o+e,1)}}function o(e,t){let n=typeof t==`function`?t():t;return{amplitude:a(e.amplitude,n?.amplitude),envelope:{riseTimeMs:Math.max(0,i(n?.envelope?.riseTimeMs,e.envelope.riseTimeMs)),fallTimeMs:Math.max(0,i(n?.envelope?.fallTimeMs,e.envelope.fallTimeMs))}}}function s(t,i){let o=a(n.amplitude,i),s=Number.isFinite(t)?r(t,0,1):0;if(s<=o.silenceFloor)return 0;if(s>=o.speechPeak)return 1;let c=o.speechPeak-o.silenceFloor,l=r((s-o.silenceFloor)/c,0,1),u=r((o.speechReference-o.silenceFloor)/c,e,1-e);return r(l**+(Math.log(.5)/Math.log(u)),0,1)}function c(e,t,n,i){if(n<=0)return t;let a=1-.1**(Math.max(0,i)/n);return r(e+(t-e)*a,0,1)}function l(e,t,i,a=n,l){let u=o(a,l),d=Number.isFinite(e)?r(e,0,1):0,f=s(d,u.amplitude);return{raw:d,mapped:f,normalized:c(t,f,f>t?u.envelope.riseTimeMs:u.envelope.fallTimeMs,i),elapsedMs:i}}function u(e=n,i){let a=0,o;return{sample(n,s=performance.now()){let c=o===void 0?t:r(s-o,0,1e3);o=s;let u=l(n,a,c,e,i);return a=u.normalized,u},reset(e=0){a=r(e,0,1),o=void 0}}}function d(e,t){let n=e.filter(e=>Number.isFinite(e)).map(e=>r(e,0,1)).sort((e,t)=>e-t);if(n.length===0)return 0;let i=r(t,0,1)*(n.length-1),a=Math.floor(i),o=Math.ceil(i),s=i-a;return n[a]+(n[o]-n[a])*s}function f(e,t,n){return d(e.map(e=>s(e,n)),t)}function p(e,t=n.envelope){for(let t of[`silence`,`quiet`,`normal`,`energetic`])if(!e[t].some(e=>Number.isFinite(e)))throw Error(`Volume calibration requires at least one ${t} sample.`);let r=d(e.silence,.99),o=d(e.normal,.5),c=Math.max(d(e.energetic,.99),d(e.normal,.99)),l=Math.max(0,o-r),u={amplitude:a(n.amplitude,{silenceFloor:r+Math.min(.005,l*.05),speechReference:o,speechPeak:c}),envelope:{riseTimeMs:Math.max(0,i(t.riseTimeMs,100)),fallTimeMs:Math.max(0,i(t.fallTimeMs,400))}},p=[...e.quiet,...e.normal,...e.energetic].map(e=>s(e,u.amplitude));return{calibration:u,metrics:{silenceP99:f(e.silence,.99,u.amplitude),quietMedian:f(e.quiet,.5,u.amplitude),normalMedian:f(e.normal,.5,u.amplitude),energeticMedian:f(e.energetic,.5,u.amplitude),speechP99:d(p,.99),saturationRatio:p.length===0?0:p.filter(e=>e>=.999).length/p.length}}}function m(e,t,n){let r;try{if(r=t(),!r)return;let i=r;i.state===`suspended`&&i.resume().catch(()=>void 0);let a=i.createMediaStreamSource(new MediaStream([e])),o=i.createAnalyser();o.fftSize=512,o.smoothingTimeConstant=.25,a.connect(o);let s=new Float32Array(o.fftSize),c=setInterval(()=>{o.getFloatTimeDomainData(s);let e=0;for(let t of s)e+=t*t;n(Math.sqrt(e/s.length))},33);return{async stop(){clearInterval(c);try{a.disconnect(),o.disconnect()}finally{i.state!==`closed`&&await i.close()}}}}catch{r?.state!==`closed`&&r?.close().catch(()=>void 0);return}}var h={riseTimeMs:100,fallTimeMs:400};function g(e,t,n){return{amplitude:{silenceFloor:e,speechReference:t,speechPeak:n},envelope:{...h}}}var _={vapi:{input:g(0,.105112,.25),output:g(.005,.4,1)},elevenlabs:{input:g(0,.36,.52),output:g(0,.4,.55)},livekit:{input:g(0,.18,.4),output:g(.015,.18,.3)},pipecat:{input:g(.002,.107112,.252),output:g(.002,.084441,.198078)},openai:{input:g(0,.105112,.25),output:g(.003,.07,.2)},gemini:{input:g(0,.105112,.25),output:g(.003,.17,.38)}},v=4,y={fftSize:512,smoothingTimeConstant:.25,minDecibels:-85,maxDecibels:-20};function b(e){switch(e){case`speaking`:return`speaking`;case`thinking`:return`thinking`;case`listening`:case`idle`:return`listening`;case`connecting`:case`pre-connect-buffering`:case`initializing`:return`connecting`;case`disconnected`:return`idle`;case`failed`:return`error`;default:return`idle`}}function x(e){return`RoomClass`in e}function S(e){return typeof e==`function`?e():e}function C(e){if(!e)return{};let t={},n=(e,n)=>{n!==void 0&&(t[e]=n)};return n(`roomName`,S(e.roomName)),n(`participantName`,S(e.participantName)),n(`participantIdentity`,S(e.participantIdentity)),n(`participantMetadata`,S(e.participantMetadata)),n(`participantAttributes`,typeof e.participantAttributes==`function`?e.participantAttributes():e.participantAttributes),n(`agentName`,S(e.agentName)),n(`agentMetadata`,S(e.agentMetadata)),n(`deployment`,S(e.deployment)),t}function w(e){if(!e.serverUrl||!e.participantToken)throw Error(`[orb-ui/livekit] connection details must include serverUrl and participantToken.`);return e}async function T(e){let t=C(e.tokenOptions);return typeof e.getConnectionDetails==`function`?w(await e.getConnectionDetails(t)):e.tokenSource?w(await e.tokenSource.fetch(t)):w({serverUrl:e.serverUrl,participantToken:e.participantToken})}function E(e){for(let[,t]of e.remoteParticipants)if(!t.isLocal&&(t.kind===v||t.attributes?.[`lk.agent.state`]!==void 0))return t;return null}function D(e,t,n){let r=e.off;if(r){r.call(e,t,n);return}e.removeListener?.call(e,t,n)}function O(e,t,n){e.on.call(e,t,n)}function k(e){let t=x(e),n=e.createAudioAnalyser,r={current:t?null:e.room},i=new Set,a={state:`idle`,inputVolume:0,outputVolume:0},o=`idle`,s=null,c=null,l=null,d=null,f=null,p=null,m=null,h=null,g=u(_.livekit.input,e.inputVolumeCalibration),S=u(_.livekit.output,e.outputVolumeCalibration);function C(e){a=e,i.forEach(t=>t(e))}function w(e){C({...a,...e,state:e.state??a.state})}function k(){S.reset(),w({outputVolume:0})}function A({emitZero:e=!0}={}){f&&=(clearInterval(f),null),d&&=(d.cleanup().catch(()=>{}),null),g.reset(),e&&w({inputVolume:0})}function j(t){if(!(s===t&&d)){A({emitZero:!1}),s=t;try{d=n(t,y)}catch(e){console.warn(`[orb-ui/livekit] local createAudioAnalyser failed:`,e);return}f=setInterval(()=>{if(!d)return;let t=g.sample(d.calculateVolume());e.onInputVolumeSample?.(t),w({inputVolume:t.normalized})},33)}}function M({emitZero:e=!0}={}){m&&=(clearInterval(m),null),p&&=(p.cleanup().catch(()=>{}),null),S.reset(),e&&w({outputVolume:0})}function N(t){M();try{p=n(t,y)}catch(e){console.warn(`[orb-ui/livekit] remote createAudioAnalyser failed:`,e);return}m=setInterval(()=>{if(!p)return;let t=S.sample(p.calculateVolume());e.onOutputVolumeSample?.(t),w({outputVolume:t.normalized})},33)}function P(e){o=e,e===`idle`||e===`connecting`||e===`error`?(g.reset(),S.reset(),w({state:e,inputVolume:0,outputVolume:0})):w({state:e}),c&&!p&&N(c)}function F(e){l||typeof document>`u`||(l=e.attach(),l.id=`orb-ui-livekit-agent-audio`,document.body.appendChild(l))}function I(){l&&=(l.remove(),null)}function L(e){c=e,F(e),N(e)}function R(e){j(e)}function z(e){let t=e.getTrackPublication?.(`microphone`);t?.track&&R(t.track)}function B(e){let t=b(e);t!==o&&P(t)}function V(e){let t=e.attributes?.[`lk.agent.state`];t&&B(t);let n=e.getTrackPublication(`microphone`);n?.track&&L(n.track)}function H(e){if(h)return;let t=(e,t)=>{if(t.isLocal)return;let n=e[`lk.agent.state`];n&&B(n)},n=(e,t,n)=>{n.isLocal||!(n.kind===v||n.attributes?.[`lk.agent.state`]!==void 0)||e.mediaStreamTrack.kind!==`audio`||L(e)},r=e=>{c===e&&(c=null,I(),M())},i=e=>{e.source!==`microphone`||!e.track||R(e.track)},a=e=>{e.source===`microphone`&&(s=null,A())},o=()=>{s=null,c=null,I(),A({emitZero:!1}),M({emitZero:!1}),P(`idle`)};if(O(e,`participantAttributesChanged`,t),O(e,`trackSubscribed`,n),O(e,`trackUnsubscribed`,r),O(e,`localTrackPublished`,i),O(e,`localTrackUnpublished`,a),O(e,`disconnected`,o),h=()=>{D(e,`participantAttributesChanged`,t),D(e,`trackSubscribed`,n),D(e,`trackUnsubscribed`,r),D(e,`localTrackPublished`,i),D(e,`localTrackUnpublished`,a),D(e,`disconnected`,o)},z(e.localParticipant),e.state===`connected`){let t=E(e);t?V(t):P(`connecting`)}else P(`idle`)}function U(){h?.(),h=null,s=null,c=null,I(),A({emitZero:!1}),M({emitZero:!1}),g.reset(),S.reset(),w({inputVolume:0,outputVolume:0})}let W=e=>{i.add(e),e(a);let t=r.current;return t&&H(t),()=>{i.delete(e),i.size===0&&U()}};return t?{subscribe:W,async start(){if(r.current)return;let t=e,n=new t.RoomClass;P(`connecting`);try{let e=await T(t);if(await n.connect(e.serverUrl,e.participantToken,t.connectOptions),r.current=n,H(n),t.enableMicrophone!==!1){let e=(await n.localParticipant.setMicrophoneEnabled(!0))?.track??n.localParticipant.getTrackPublication?.(`microphone`)?.track;e&&R(e)}}catch(e){throw console.error(`[orb-ui/livekit] connect failed:`,e),r.current===n&&U(),n.disconnect(),r.current=null,P(`error`),k(),w({error:e}),e}},async stop(){let e=r.current;if(!e){P(`idle`);return}U(),e.disconnect(),r.current=null,P(`idle`)}}:{subscribe:W}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return k}});
|
package/dist/livekit-adapter.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./livekit-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./livekit-C36Kmz6s.cjs");let t=require("livekit-client");function n(){return`orb-${globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random().toString(36).slice(2)}`}`}function r(r){let{agentMetadata:i,agentName:a,connectOptions:o,deployment:s,enableMicrophone:c,participantAttributes:l,participantIdentity:u,participantMetadata:d,participantName:f,roomName:p=n,inputVolumeCalibration:m,outputVolumeCalibration:h,onInputVolumeSample:g,onOutputVolumeSample:_}=r;return e.t({tokenSource:r.tokenEndpoint===void 0?t.TokenSource.sandboxTokenServer(r.sandboxId,r.sandboxOptions):t.TokenSource.endpoint(r.tokenEndpoint,r.tokenEndpointOptions),tokenOptions:{agentMetadata:i,agentName:a,deployment:s,participantAttributes:l,participantIdentity:u,participantMetadata:d,participantName:f,roomName:p},connectOptions:o,enableMicrophone:c,inputVolumeCalibration:m,outputVolumeCalibration:h,onInputVolumeSample:g,onOutputVolumeSample:_,createAudioAnalyser:t.createAudioAnalyser,RoomClass:t.Room})}exports.createLiveKitAdapter=r;
|
package/dist/livekit-adapter.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as e } from "./livekit-
|
|
1
|
+
import { t as e } from "./livekit-7Re8E7By.js";
|
|
2
2
|
import { Room as t, TokenSource as n, createAudioAnalyser as r } from "livekit-client";
|
|
3
3
|
//#region src/adapters/livekit/browser.ts
|
|
4
4
|
function i() {
|
|
5
5
|
return `orb-${globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`}`;
|
|
6
6
|
}
|
|
7
7
|
function a(a) {
|
|
8
|
-
let { agentMetadata: o, agentName: s, connectOptions: c, deployment: l, enableMicrophone: u, participantAttributes: d, participantIdentity: f, participantMetadata: p, participantName: m, roomName: h = i,
|
|
8
|
+
let { agentMetadata: o, agentName: s, connectOptions: c, deployment: l, enableMicrophone: u, participantAttributes: d, participantIdentity: f, participantMetadata: p, participantName: m, roomName: h = i, inputVolumeCalibration: g, outputVolumeCalibration: _, onInputVolumeSample: v, onOutputVolumeSample: y } = a;
|
|
9
9
|
return e({
|
|
10
10
|
tokenSource: a.tokenEndpoint === void 0 ? n.sandboxTokenServer(a.sandboxId, a.sandboxOptions) : n.endpoint(a.tokenEndpoint, a.tokenEndpointOptions),
|
|
11
11
|
tokenOptions: {
|
|
@@ -20,8 +20,10 @@ function a(a) {
|
|
|
20
20
|
},
|
|
21
21
|
connectOptions: c,
|
|
22
22
|
enableMicrophone: u,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
inputVolumeCalibration: g,
|
|
24
|
+
outputVolumeCalibration: _,
|
|
25
|
+
onInputVolumeSample: v,
|
|
26
|
+
onOutputVolumeSample: y,
|
|
25
27
|
createAudioAnalyser: r,
|
|
26
28
|
RoomClass: t
|
|
27
29
|
});
|