t2-mapper/docs/assets/ChatSoundPlayer-D3K8GxX-.js
2026-04-08 23:48:42 -07:00

1 line
No EOL
1.1 KiB
JavaScript

import{r as e}from"./chunk-DECur_0Z.js";import{r as t}from"./jsx-runtime-BpGWiA-R.js";import{a as n,s as r}from"./SettingsProvider-BdqQ2Cm4.js";import{c as i}from"./three.module-DKAirPAO.js";import{r as a}from"./loaders-5n1D4iOD.js";import{i as o}from"./engineStore-B1KAgiiF.js";import{c as s,d as c,i as l,l as u,r as d}from"./AudioEmitter-3VHhCc7Y.js";var f=e(t(),1);function p(){let{audioLoader:e,audioListener:t}=c(),{audioEnabled:p}=n(),m=o(e=>e.playback.streamSnapshot?.chatMessages),h=o(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,o=_.current;for(let c of m)if(!n.has(c)&&(n.add(c),c.soundPath&&!(Math.abs(h-c.timeSec)>2)))try{let n=a(c.soundPath),f=c.soundPitch??1,p=c.sender,m=l();d(n,e,e=>{if(m!==l())return;if(p){let e=o.get(p);if(e){try{e.stop()}catch{}u(e);try{e.disconnect()}catch{}o.delete(p)}}let n=new i(t);n.setBuffer(e),n.setPlaybackRate(r(f)),s(n,f),p&&o.set(p,n),n.play(),n.source.onended=()=>{u(n);try{n.disconnect()}catch{}p&&o.get(p)===n&&o.delete(p)}})}catch{}},[p,e,t,m,h]),null}export{p as ChatSoundPlayer};