1import{m as t}from"../assets/vendor-mqtt-DUOv-3Io.js";import{c as e,i as o,a as n,b as s}from"../assets/helper-C6s7TZM4.js";import{u as i}from"../assets/decrypt-w2rEWcc-.js";import{d as c,a}from"../assets/debug-utils-DPNoUJjN.js";import"../assets/vendor-axios-DGc3PeEL.js";import"../assets/vendor-pako-DZXWdWhw.js";const r={"1H":"Hiá»p 1","2H":"Hiá»p 2",HT:"HT",FT:"Kết Thúc"};class l{constructor(t){this.mqttClient=null,this.topicId=t,this.isConnected=!1,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.mqttConfig={domain:"mqtt.sportsfeed.pro",securePorts:[8084,443,8883],insecurePorts:[8083],path:"/mqtt"},this.initializeConnection()}createMQTTOptions(t,e,o){return{clientId:t,clean:!0,keepalive:60,connectTimeout:7e3,reconnectPeriod:0,protocolVersion:5,rejectUnauthorized:!1,port:e,path:o,properties:{sessionExpiryInterval:0,receiveMaximum:100,maximumPacketSize:102400}}}initializeConnection(){if(c("[MQTT Live Score] Starting connection for topic: "+this.topicId),this.mqttClient){try{this.mqttClient.removeAllListeners("message"),this.mqttClient.end(!0)}catch(t){a("[MQTT Live Score] Error ending previous connection:",t)}this.mqttClient=null}"https:"===window.location.protocol?(c("[MQTT Live Score] HTTPS detected - using secure WebSockets"),this.trySecureConnection()):(c("[MQTT Live Score] HTTP detected - using standard WebSockets"),this.tryInsecureConnection())}trySecureConnection(){const e=this.mqttConfig.securePorts;let o=0;const n=()=>
1{if(o>=e.length)return a("[MQTT Live Score] All secure WebSocket ports failed"),void this.notifyConnectionFailed("All secure ports failed");const s=e[o],i="wss://"+this.mqttConfig.domain,r=this.mqttConfig.path;c(`[MQTT Live Score] Trying secure connection on port ${s}...`);const l=`matchlist_${this.topicId}_${Math.random().toString(16).substring(2,8)}`,m=this.createMQTTOptions(l,s,r);try{const e=t.connect(i,m);this.setupClientHandlers(e,s,()=>{o++,setTimeout(n,500)})}catch(d){a(`[MQTT Live Score] Error creating MQTT client on port ${s}:`,d),o++,setTimeout(n,500)}};n()}tryInsecureConnection(){const e=this.mqttConfig.insecurePorts[0],o="ws://"+this.mqttConfig.domain,n=this.mqttConfig.path;c(`[MQTT Live Score] Connecting to: ${o} on port ${e}`);const s=`matchlist_${this.topicId}_${Math.random().toString(16).substring(2,8)}`,i=this.createMQTTOptions(s,e,n);i.connectTimeout=3e3,i.reconnectPeriod=4e3;try{this.mqttClient=t.connect(o,i),this.setupClientHandlers(this.mqttClient,e,()=>{this.notifyConnectionFailed("Insecure connection failed")})}catch(r){a("[MQTT Live Score] Error creating insecure MQTT client:",r),this.notifyConnectionFailed("Connection creation failed")}}setupClientHandlers(t,e,o){t.on("connect",o=>{c("[MQTT Live Score] Connected to MQTT broker on port "+e,o),this.isConnected=!0,this.reconnectAttempts=0,this.mqttClient=t,this.subscribeToTopic(this.topicId),this.notifyConnectionSuccess()}),t.on("error",n=>{a(`[MQTT Live Score] Connection error on port ${e}:`,n.message||n);try{t.end(!0)}catch(s){a("[MQTT Live Score] Error ending failed connection:",s)}o&&o()}),t.on("close",()=>{c(`[MQTT Live Score] Connection on port ${e} closed`),this.mqttClient===t&&(this.isConnected=!1,this.handleDisconnection())}),t.on("message",(t,e,o)=>{this.handleIncomingData(t,e,o)}),t.on("reconnect",()=>{c(`[MQTT Live Score] Reconnecting on port ${e}...`)}),t.on("offline",()=>{c(`[MQTT Live Score] Client on port ${e} is offline`)})}subscribeToTopic(t){this.mqttClient&&this.mqttClient.connected?(c("[MQTT Live Score] Subscribing to topic: "+t),this.mqttClient.subscribe(t,{qos:1},(e,o)=>{e?a("[MQTT Live Score] Subscription failed:",e):c("[MQTT Live Score] Successfully subscribed to topic:",t)})):a("[MQTT Live Score] Cannot subscribe - client not connected")}handleIncomingData(t,e,o){try{const t=i(e,!0);"score"===t.type&&Array.isArray(t.data)&&this.processScoreUpdates(t.data,t.sport_id||1)}catch(n){a("[MQTT Live Score] Error handling MQTT data:",n)}}
1processScoreUpdates(t,e){const{total:o,updated:n,updatedTeams:s}=t.reduce((t,o)=>{const n=o.uuid,s=document.querySelectorAll(`[data-match-id="${n}"]`);if(0===s.length)return{...t,total:t.total+1};const i=s[0],c=2===e?this.prepareBasketballUpdate(o):this.prepareMatchUpdate(o,i);this.updateMatchElements(n,c);const a=i.querySelector(".bals-home-team-name")?.textContent?.trim()||"Unknown Home",r=i.querySelector(".bals-away-team-name")?.textContent?.trim()||"Unknown Away";return{total:t.total+1,updated:t.updated+1,updatedTeams:[...t.updatedTeams,`${a} vs ${r}`]}},{total:0,updated:0,updatedTeams:[]}),i=2===e?"ð Basketball":"â½ Football";c(n>0?`[${i}] Updated ${n}/${o} matches:\n- ${s.join("\n- ")}`:`[${i}] No matches updated.`)}prepareMatchUpdate(t,o){const n=parseInt(o.getAttribute("data-match-time")||"0");return t.match_time=n,{homeScore:e(t.home_scores),awayScore:e(t.away_scores),homeHtScore:t.home_scores?.[1]??0,awayHtScore:t.away_scores?.[1]??0,homeYellowCard:t.home_scores?.[3]??0,awayYellowCard:t.away_scores?.[3]??0,homeCorner:t.home_scores?.[4]??0,awayCorner:t.away_scores?.[4]??0,homePenaltyScore:t.home_scores?.[6]??0,awayPenaltyScore:t.away_scores?.[6]??0,statusName:t.status_name||"",elapsedTime:this.calculateElapsedTime(t),isTerminated:["PS","INT","CANC","TBD"].includes(t.status_name),homeTeamName:t.home_team_name||"",awayTeamName:t.away_team_name||""}}prepareBasketballUpdate(t){return{homeScore:(t.home_scores??[]).reduce((t,e)=>t+(e??0),0),awayScore:(t.away_scores??[]).reduce((t,e)=>t+(e??0),0),statusName:t.status_name||"",elapsedTime:this.calculateBasketballTimer(t),isTerminated:["FT","CANC","TBD","INT"].includes(t.status_name)}}calculateBasketballTimer(t){const e=t.timer;if(!e||e.length<4)return"";const[o,n,s,i]=e;if(1===o&&1===n){const t=Math.floor(Date.now()/1e3),e=Math.max(0,i-Math.max(0,t-s));return`${Math.floor(e/60)}:${(e%60+"").padStart(2,"0")}`}return i>0?`${Math.floor(i/60)}:${(i%60+"").padStart(2,"0")}`:""}updateMatchElements(t,e){document.querySelectorAll(`[data-match-id="${t}"]`).forEach(t=>{if(t.matches(".match-card")){const i=o(t);n(t,e.statusName),s(t,e.statusName,i)}const i=t.querySelector(".bals-status-name"),c=t.querySelector(".bals-elapsed-time");var a;i&&(i.textContent=r[a=e.statusName]||a),c&&(c.textContent=e.elapsedTime);const l=t.querySelector(".bals-home-score"),m=t.querySelector(".bals-away-score");l&&(l.textContent=e.homeScore),m&&(m.textContent=e.awayScore),l&&m&&(l.classList.toggle("bg-gradient-red-bright",e.homeScore>e.awayScore),m.classList.toggle("bg-gradient-red-bright",e.awayScore>e.homeScore));const d=t.querySelector(".bals-ht-score");d&&(d.textContent=`${e.homeHtScore}-${e.awayHtScore}`);const h=t.querySelector(".bals-corners");h&&(h.textContent=`${e.homeCorner}-${e.awayCorner}`);const u=t.querySelector(".bals-yellow-cards");u&&(u.textContent=`${e.homeYellowCard}-${e.awayYellowCard}`);const p=t.querySelector(".bals-penalty-note");p&&(e.homePenaltyScore>0||e.awayPenaltyScore>0?(p.textContent=`(Phạt súng: ${e.homePenaltyScore} - ${e.awayPenaltyScore})`,p.style.display="block"):p.style.display="none")})}calculateElapsedTime(t){if(!t.kick_off_timestamp||!t.match_time)return" - ";const e=Math.floor(Date.now()/1e3),{kick_off_timestamp:o,match_time:n,status_name:s}=t,i={PS:"PS",NS:"",FT:"Kết Thúc",HT:"HT",ET:"ET",PK:"PK",INT:"INT",CANC:"CANC",TBD:"TBD"};if(i[s])return i[s];let c=this.computeElapsedMinutes(e,o,n,s);c=Math.max(0,c);const a="1H"===s?60:120;return c>a&&(c=a),"1H"===s&&c>45?"45+":"2H"===s&&c>90?"90+":c+"'"}computeElapsedMinutes(t,e,o,n){const s=e&&0!==e?e:o&&0!==o?o:0;if(!s)return 0;const i=Math.floor((t-s)/60);return"2H"===n?Math.max(46,i+45):Math.max(0,i)}notifyConnectionSuccess(){c("[MQTT Live Score] â
Connection successful")}notifyConnectionFailed(t){a("[MQTT Live Score] â Connection failed: "+t)}handleDisconnection(){if(this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const t=1e3*Math.pow(2,this.reconnectAttempts-1);c(`[MQTT Live Score] Scheduling reconnect attempt ${this.reconnectAttempts} in ${t}ms`),setTimeout(()=>{this.initializeConnection()},t)}else a("[MQTT Live Score] Max reconnection attempts reached")}disconnect(){if(this.mqttClient){try{this.topicId&&this.mqttClient.unsubscribe(this.topicId),this.mqttClient.end(!0)}catch(t){a("[MQTT Live Score] Error during disconnect:",t)}this.mqttClient=null}this.isConnected=!1,c("[MQTT Live Score] Disconnected")}}function m(t="matchlist_1"){return new l(t)}window.initializeMQTTScoreUpdater=m,document.addEventListener("DOMContentLoaded",()=>{const t=m(),e=m("matchlist_2");window.mqttScoreUpdater=t,window.mqttBasketballUpdater=e});
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.