UNPKG

@hoosei/voxweave-react

Version:

A customizable and interactive voice UI component for React applications

3 lines (2 loc) 3.27 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),c=require("./index6.js"),v=require("./index55.js"),l=require("./index56.js"),e=require("react/jsx-runtime"),B=require("./index45.js"),F=require("./index43.js"),P=require("./index18.js"),k=require("./index17.js");function z({isListening:i,onStartCall:f,onClose:u,audioData:d,agentAudioData:h,agentStatus:m,darkMode:x,startCallLabel:j,endCallLabel:b}){const[y,w]=s.useState([]),[N,g]=s.useState(null),[q,p]=s.useState(!1),[S,C]=s.useState(Array(8).fill(2));s.useEffect(()=>{(async()=>{try{await navigator.mediaDevices.getUserMedia({audio:!0});const t=(await navigator.mediaDevices.enumerateDevices()).filter(a=>a.kind==="audioinput").map(a=>({deviceId:a.deviceId,label:a.label||`Microphone ${a.deviceId.slice(0,5)}...`}));w(t),t.length>0&&g(t[0])}catch(r){console.error("Error accessing audio devices:",r)}})()},[]);const I=s.useCallback((o,r)=>{if(!i)return 0;let t=o,a=2;if(m==="speaking"&&r&&(t=r,a=1.6),!t||t.length===0)return 0;const n=t.reduce(($,M)=>$+M,0);if(n===0)return 0;const D=n/t.length;return Math.pow(D/255,1.2)*a},[i,m]);return s.useEffect(()=>{const o=I(d,h);C(r=>r.map(()=>{if(o===0)return 1;const t=Math.random()*2.5,a=o*55,n=Math.max(2,a*t);return Math.min(n,24)}))},[i,d,h]),e.jsxs("div",{className:"vox:flex vox:items-center vox:gap-3",children:[e.jsxs("div",{className:`vox:bg-${x?"gray-800":"white"} vox:rounded-full vox:py-2.5 vox:px-4 vox:flex vox:items-center vox:gap-3 vox:shadow-sm`,children:[e.jsxs(v.Popover,{open:q,onOpenChange:p,children:[e.jsx(v.PopoverTrigger,{asChild:!0,children:e.jsx(c.Button,{variant:"ghost",size:"icon",className:"vox:h-5 vox:w-5 vox:p-0 hover:vox:bg-transparent","aria-label":"Select a microphone",children:e.jsx(B.default,{className:`vox:h-5 vox:w-5 ${x?"vox:text-gray-300":"vox:text-gray-600"}`})})}),e.jsx(v.PopoverContent,{className:"vox:w-[200px] vox:p-0",align:"start",children:e.jsx(l.Command,{children:e.jsx(l.CommandGroup,{heading:"Select Microphone",children:y.map(o=>e.jsxs(l.CommandItem,{onSelect:()=>{g(o),p(!1)},className:"vox:flex vox:items-center vox:justify-between",children:[e.jsx("span",{className:"vox:truncate",children:o.label}),N?.deviceId===o.deviceId&&e.jsx(F.default,{className:"vox:h-4 vox:w-4 vox:text-green-600"})]},o.deviceId))})})})]}),e.jsx("div",{className:"vox:flex vox:items-end vox:gap-0.5 vox:h-6",children:S.map((o,r)=>e.jsx("div",{className:`vox:w-1 ${x?"vox:bg-gray-400":"vox:bg-gray-600"} vox:rounded-full vox:transition-all vox:duration-100`,style:{height:`${o}px`}},r))}),e.jsx(c.Button,{variant:"ghost",size:"icon",className:"vox:h-5 vox:w-5 vox:p-0 hover:vox:bg-transparent",onClick:u,children:e.jsx(P.default,{className:`vox:h-5 vox:w-5 ${x?"vox:text-gray-300":"vox:text-gray-600"}`})})]}),e.jsxs(c.Button,{className:`vox:inline-flex vox:justify-center vox:items-center vox:gap-1 vox:px-3 vox:py-1 vox:rounded-full vox:text-xs vox:transition vox:duration-300 vox:ease-in-out ${x?"vox:bg-gray-700 vox:text-white hover:vox:bg-gray-600":"vox:bg-black vox:text-white hover:vox:bg-gray-700"}`,size:"sm",onClick:i?u:f,children:[e.jsx(k.default,{className:"vox:w-3 vox:h-3","aria-hidden":"true"}),i?b:j]})]})}exports.VoxweaveMinimal=z; //# sourceMappingURL=index11.js.map