t2-mapper/docs/assets/ChatSoundPlayer-W2IMffj8.js
2026-03-16 19:04:48 -07:00

1 line
No EOL
1.4 KiB
JavaScript

import{r as e}from"./chunk-DECur_0Z.js";import{r as t}from"./jsx-runtime-BpGWiA-R.js";import"./react-three-fiber.esm-IOIyqSDz.js";import{a as n}from"./SettingsProvider-Dg81XAbP.js";import"./logger-CC5j_O4o.js";import"./traditional-ec-lUAFC.js";import{c as r}from"./three.module-BCXZgYUA.js";import"./mission-CgOJ5O6t.js";import{i,r as a}from"./engineStore-DYTudHqF.js";import{r as o}from"./loaders-Ba8dC3nL.js";import{n as s}from"./AudioContext-DRJ1vuj7.js";import"./FloatingLabel-9DGW88qJ.js";import{getCachedAudioBuffer as c,getSoundGeneration as l,trackSound as u,untrackSound as d}from"./AudioEmitter-LzTkKNI4.js";var f=e(t(),1);function p(){let{audioLoader:e,audioListener:t}=s(),{audioEnabled:p}=n(),m=i(e=>e.playback.streamSnapshot?.chatMessages),h=i(e=>e.playback.streamSnapshot?.timeSec),g=(0,f.useRef)(new WeakSet),_=(0,f.useRef)(new Map);return(0,f.useEffect)(()=>{if(!p||!e||!t||!m?.length||h==null)return;let n=g.current,i=_.current;for(let s of m)if(!n.has(s)&&(n.add(s),s.soundPath&&!(Math.abs(h-s.timeSec)>2)))try{let n=o(s.soundPath),f=s.soundPitch??1,p=a.getState().playback.rate,m=s.sender,h=l();c(n,e,e=>{if(h!==l())return;if(m){let e=i.get(m);if(e){try{e.stop()}catch{}d(e);try{e.disconnect()}catch{}i.delete(m)}}let n=new r(t);n.setBuffer(e),n.setPlaybackRate(f*p),u(n,f),m&&i.set(m,n),n.play(),n.source.onended=()=>{d(n);try{n.disconnect()}catch{}m&&i.get(m)===n&&i.delete(m)}})}catch{}},[p,e,t,m,h]),null}export{p as ChatSoundPlayer};