"use strict";exports.id=713,exports.ids=[713],exports.modules={10713:(a,b,c)=>{c.d(b,{ensureEventBusConnected:()=>t,B:()=>s});var d=c(94735),e=c(37614),f=c(55511),g=c(29229),h=c.n(g);let i=e.vF.child({module:"redis"}),j=function(){if(process.env.REDIS_URL)return process.env.REDIS_URL;let a=process.env.REDIS_HOST;if(!a)return;let b=process.env.REDIS_PORT||"6379",c=process.env.REDIS_USERNAME||"default",d=process.env.REDIS_PASSWORD,e="rediss";return d?`${e}://${c}:${encodeURIComponent(d)}@${a}:${b}`:`${e}://${a}:${b}`}(),k=globalThis;function l(a){let b=new(h())(j,{lazyConnect:!0,maxRetriesPerRequest:null,retryStrategy(b){let c=Math.min(200*b,5e3);return i.warn({name:a,delay:c,attempt:b},"reconnecting"),c}});return b.on("error",b=>{i.error({name:a,err:b.message||"unknown redis error"},"connection error")}),b.on("connect",()=>{i.info({name:a},"connected")}),b}function m(){return j?(k.redisPub||(k.redisPub=l("pub")),k.redisPub):null}function n(){return j?(k.redisSub||(k.redisSub=l("sub")),k.redisSub):null}let o=e.vF.child({module:"event_bus"}),p="synapse:events";class q extends d.EventEmitter{async connect(){if(!this._connected&&j){if(this._connectPromise)return void await this._connectPromise;this._connectPromise=(async()=>{let a=n(),b=m();a&&(await a.connect(),b&&await b.connect(),await a.subscribe(p),a.on("message",(a,b)=>{try{let a=JSON.parse(b);if(a._origin===this._instanceId)return;super.emit(a.channel,a.data)}catch{}}),this._connected=!0)})();try{await this._connectPromise}finally{this._connectPromise=null}}}emit(a,...b){if("string"==typeof a&&j){let c=m();if(c){let d={_origin:this._instanceId,channel:a,data:b[0]};c.publish(p,JSON.stringify(d)).catch(()=>{})}}return super.emit(a,...b)}emitChange(a){this.emit("change",a)}emitPresence(a){this.emit("presence",a)}async disconnect(){let a=m(),b=n();b&&await b.quit().catch(()=>{}),a&&await a.quit().catch(()=>{}),this._connected=!1}constructor(...a){super(...a),this._connected=!1,this._connectPromise=null,this._instanceId=(0,f.randomUUID)()}}let r=globalThis,s=r.synapseEventBus??=new q;async function t(){if(j)try{await s.connect()}catch(b){let a=b instanceof Error?b.message:String(b);o.error({err:a},"Redis connect failed, falling back to memory")}}},37614:(a,b,c)=>{c.d(b,{vF:()=>h});var d=c(74552),e=c.n(d),f=c(84297);let g=process.env.LOG_LEVEL??"info",h=e()({level:g,transport:void 0,base:{service:"synapse"}});new f.AsyncLocalStorage}};