1import{updateCoinsBalance,updateQuest,redeemReward}from"gamificationEvents";const WEBSOCKET_ENDPOINT=`wss://${document.location.host}/centrifugo/connection/websocket`;class CentrifugeManager{constructor(){this.client=null,this.token=null,this.userId=document.body.dataset.userId||"",this.channels={balance:`user_balance:#${this.userId}`,events:`user_events:#${this.userId}`,quests:`user_quests:#${this.userId}`,rewards:`user_rewards:#${this.userId}`}}async initialize(){if(this.userId&&document.body.dataset.gamificationEnabled)try{if(this.token=await this.getToken(),!this.token)return;this.client=new Centrifuge(WEBSOCKET_ENDPOINT,{token:this.token,getToken:this.getToken.bind(this),debug:"prod"!==document.body.dataset.websiteEnv}),this.subscribeToChannel(this.channels.balance,updateCoinsBalance),this.subscribeToChannel(this.channels.quests,updateQuest),this.subscribeToChannel(this.channels.rewards,redeemReward),this.subscribeToChannel(this.channels.events),this.client.connect(),window.getCentrifugeClient=()=>this.client}catch(e){}}async getToken(){try{const e=await fetch("/api/centrifugo/token");if(!e.ok)throw new Error(`Failed to fetch token: ${e.status}`);const{token:t}=await e.json();return t}catch(e){throw e}}subscribeToChannel(e,t=()=>{}){if(!this.client)return;const n=this.client.newSubscription(e);n.on("publication",({data:e})=>t(e)),n.subscribe()}async publishToChannel(e,t){if(this.client)try{const n=await this.client.getSubscription(e);if(!n)return;await n.publish(t)}catch(e){}}async publishCustomEvent(e,t={}){await this.publishToChannel(this.channels.events,{type:e,body:t})}}const centrifugeManager=new CentrifugeManager;export{centrifugeManager};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.