UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.45 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Rl as t,Wo as n,li as r,oi as i,ut as a,zl as o}from"./_4____________________________.js";import{AN as s,Gn as c,Jn as l,Xn as u,qn as d}from"./_2_____________________________.js";function f(e){return u(c(e),`audioinput`)}function p(e){return e.reason instanceof Error?e.reason:new DOMException(`Realtime Talk input cancelled`,`AbortError`)}async function m(e,t,n){let i=globalThis.navigator?.mediaDevices;if(!i?.getUserMedia)throw Error(r(e===`audioinput`?`chat.composer.realtimeTalkRequiresMicrophone`:`chat.composer.cameraAccessFailed`));let s=t?.trim(),d;try{if(n?.aborted)throw p(n);let t=i.getUserMedia(e===`audioinput`?{audio:{autoGainControl:!0,echoCancellation:!0,noiseSuppression:!0,...s?{deviceId:{exact:s}}:{}}}:{video:!s||{deviceId:{exact:s}}});try{d=await o(t,n,p)}catch(e){throw n?.aborted?(t.then(e=>e.getTracks().forEach(e=>e.stop()),()=>void 0),p(n)):e}}catch(t){if(n?.aborted)throw p(n);let i=l(t);throw e===`audioinput`&&(!i||i===`AbortError`)?t:s&&i===`OverconstrainedError`?e===`audioinput`?new g:Error(r(`chat.composer.selectedCameraUnavailable`)):new a(u(c(t),e),{cause:t})}if(n?.aborted)throw d.getTracks().forEach(e=>e.stop()),p(n);return d}async function h(e,t={}){return m(`videoinput`,e,t.signal)}var g,_;function v(){return(v=e((()=>{t(),i(),s(),d(),g=class extends Error{constructor(){super(r(`chat.composer.selectedMicrophoneUnavailable`)),this.name=`RealtimeTalkSelectedMicrophoneError`}},_=class{constructor(e,t){this.onEnded=e,this.onConnecting=t,this.controller=null,this.media=null}get stream(){return this.media}requireStream(){let e=this.media;if(!e)throw Error(r(`chat.composer.microphoneStopped`));return e}adopt(e){let t=this.requireStream();return this.onEnded=e,t}async open(e){this.stop();let t=new AbortController;this.controller=t;try{this.onConnecting?.(r(`chat.composer.microphoneAccessPending`));let i=await m(`audioinput`,e,t.signal);if(t.signal.aborted)throw i.getTracks().forEach(e=>e.stop()),p(t.signal);this.media=i;let a=()=>{this.controller===t&&(this.stop(),this.onEnded(r(`chat.composer.microphoneStopped`)))};for(let e of i.getTracks())n(e,`ended`,a,{signal:t.signal});return this.onConnecting?.(),i}catch(e){throw this.controller===t&&this.stop(),e}}stop(){let e=this.controller,t=this.media;this.controller=null,this.media=null,e?.abort(),t?.getTracks().forEach(e=>e.stop())}}})))()}export{h as a,v as i,g as n,f as r,_ as t};