Current section
Files
Jump to
Current section
Files
priv/static/live_reloader.min.js
var Combo=Combo||{};Combo.LiveReloader=(()=>{var ie=Object.create;var N=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var ae=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),he=(i,e)=>{for(var t in e)N(i,t,{get:e[t],enumerable:!0})},I=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ne(e))!oe.call(i,n)&&n!==t&&N(i,n,{get:()=>e[n],enumerable:!(s=se(e,n))||s.enumerable});return i};var le=(i,e,t)=>(t=i!=null?ie(re(i)):{},I(e||!i||!i.__esModule?N(t,"default",{value:i,enumerable:!0}):t,i)),ce=i=>I(N({},"__esModule",{value:!0}),i);var q=ae((mt,K)=>{var de="Expected a function",X=NaN,pe="[object Symbol]",me=/^\s+|\s+$/g,ge=/^[-+]0x[0-9a-f]+$/i,Te=/^0b[01]+$/i,be=/^0o[0-7]+$/i,Se=parseInt,Ce=typeof global=="object"&&global&&global.Object===Object&&global,Ee=typeof self=="object"&&self&&self.Object===Object&&self,ye=Ce||Ee||Function("return this")(),ve=Object.prototype,Re=ve.toString,je=Math.max,ke=Math.min,B=function(){return ye.Date.now()};function Ae(i,e,t){var s,n,o,r,a,h,l=0,c=!1,u=!1,A=!0;if(typeof i!="function")throw new TypeError(de);e=G(e)||0,U(t)&&(c=!!t.leading,u="maxWait"in t,o=u?je(G(t.maxWait)||0,e):o,A="trailing"in t?!!t.trailing:A);function _(f){var S=s,w=n;return s=n=void 0,l=f,r=i.apply(w,S),r}function Y(f){return l=f,a=setTimeout(O,e),c?_(f):r}function Z(f){var S=f-h,w=f-l,D=e-S;return u?ke(D,o-w):D}function M(f){var S=f-h,w=f-l;return h===void 0||S>=e||S<0||u&&w>=o}function O(){var f=B();if(M(f))return P(f);a=setTimeout(O,Z(f))}function P(f){return a=void 0,A&&s?_(f):(s=n=void 0,r)}function ee(){a!==void 0&&clearTimeout(a),l=0,s=h=n=a=void 0}function te(){return a===void 0?r:P(B())}function H(){var f=B(),S=M(f);if(s=arguments,n=this,h=f,S){if(a===void 0)return Y(h);if(u)return a=setTimeout(O,e),_(h)}return a===void 0&&(a=setTimeout(O,e)),r}return H.cancel=ee,H.flush=te,H}function U(i){var e=typeof i;return!!i&&(e=="object"||e=="function")}function _e(i){return!!i&&typeof i=="object"}function we(i){return typeof i=="symbol"||_e(i)&&Re.call(i)==pe}function G(i){if(typeof i=="number")return i;if(we(i))return X;if(U(i)){var e=typeof i.valueOf=="function"?i.valueOf():i;i=U(e)?e+"":e}if(typeof i!="string")return i===0?i:+i;i=i.replace(me,"");var t=Te.test(i);return t||be.test(i)?Se(i.slice(2),t?2:8):ge.test(i)?X:+i}K.exports=Ae});var Be={};he(Be,{default:()=>He});var fe=typeof self!="undefined"?self:null,v=typeof window!="undefined"?window:null,p=fe||v||globalThis,F="2.0.0",m={connecting:0,open:1,closing:2,closed:3},W=1e4,J=1e3,d={closed:"closed",errored:"errored",joined:"joined",joining:"joining",leaving:"leaving"},g={close:"phx_close",error:"phx_error",join:"phx_join",reply:"phx_reply",leave:"phx_leave"},x={longpoll:"longpoll",websocket:"websocket"},z={complete:4},L="base64url.bearer.combo.";var E=i=>typeof i=="function"?i:function(){return i};var b=class{static request(e,t,s,n,o,r,a){if(p.XDomainRequest){let h=new p.XDomainRequest;return this.xdomainRequest(h,e,t,n,o,r,a)}else if(p.XMLHttpRequest){let h=new p.XMLHttpRequest;return this.xhrRequest(h,e,t,s,n,o,r,a)}else{if(p.fetch&&p.AbortController)return this.fetchRequest(e,t,s,n,o,r,a);throw new Error("No suitable XMLHttpRequest implementation found")}}static fetchRequest(e,t,s,n,o,r,a){let h={method:e,headers:s,body:n},l=null;if(o){l=new AbortController;let c=setTimeout(()=>l.abort(),o);h.signal=l.signal}return p.fetch(t,h).then(c=>c.text()).then(c=>this.parseJSON(c)).then(c=>a&&a(c)).catch(c=>{c.name==="AbortError"&&r?r():a&&a(null)}),l}static xdomainRequest(e,t,s,n,o,r,a){return e.timeout=o,e.open(t,s),e.onload=()=>{let h=this.parseJSON(e.responseText);a&&a(h)},r&&(e.ontimeout=r),e.onprogress=()=>{},e.send(n),e}static xhrRequest(e,t,s,n,o,r,a,h){e.open(t,s,!0),e.timeout=r;for(let[l,c]of Object.entries(n))e.setRequestHeader(l,c);return e.onerror=()=>h&&h(null),e.onreadystatechange=()=>{if(e.readyState===z.complete&&h){let l=this.parseJSON(e.responseText);h(l)}},a&&(e.ontimeout=a),e.send(o),e}static parseJSON(e){if(!e||e==="")return null;try{return JSON.parse(e)}catch(t){return console&&console.log("failed to parse JSON response",e),null}}static serialize(e,t){let s=[];for(var n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;let o=t?`${t}[${n}]`:n,r=e[n];typeof r=="object"?s.push(this.serialize(r,o)):s.push(encodeURIComponent(o)+"="+encodeURIComponent(r))}return s.join("&")}static appendParams(e,t){if(Object.keys(t).length===0)return e;let s=e.match(/\?/)?"&":"?";return`${e}${s}${this.serialize(t)}`}};var C=class{constructor(e,t,s,n){this.channel=e,this.event=t,this.payload=s||function(){return{}},this.receivedResp=null,this.timeout=n,this.timeoutTimer=null,this.recHooks=[],this.sent=!1}resend(e){this.timeout=e,this.reset(),this.send()}send(){this.hasReceived("timeout")||(this.startTimeout(),this.sent=!0,this.channel.socket.push({topic:this.channel.topic,event:this.event,payload:this.payload(),ref:this.ref,join_ref:this.channel.joinRef()}))}receive(e,t){return this.hasReceived(e)&&t(this.receivedResp.response),this.recHooks.push({status:e,callback:t}),this}reset(){this.cancelRefEvent(),this.ref=null,this.refEvent=null,this.receivedResp=null,this.sent=!1}matchReceive({status:e,response:t,_ref:s}){this.recHooks.filter(n=>n.status===e).forEach(n=>n.callback(t))}cancelRefEvent(){this.refEvent&&this.channel.off(this.refEvent)}cancelTimeout(){clearTimeout(this.timeoutTimer),this.timeoutTimer=null}startTimeout(){this.timeoutTimer&&this.cancelTimeout(),this.ref=this.channel.socket.makeRef(),this.refEvent=this.channel.replyEventName(this.ref),this.channel.on(this.refEvent,e=>{this.cancelRefEvent(),this.cancelTimeout(),this.receivedResp=e,this.matchReceive(e)}),this.timeoutTimer=setTimeout(()=>{this.trigger("timeout",{})},this.timeout)}hasReceived(e){return this.receivedResp&&this.receivedResp.status===e}trigger(e,t){this.channel.trigger(this.refEvent,{status:e,response:t})}};var y=class{constructor(e,t){this.callback=e,this.timerCalc=t,this.timer=null,this.tries=0}reset(){this.tries=0,clearTimeout(this.timer)}scheduleTimeout(){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.tries=this.tries+1,this.callback()},this.timerCalc(this.tries+1))}};var R=class{constructor(e,t,s){this.state=d.closed,this.topic=e,this.params=E(t||{}),this.socket=s,this.bindings=[],this.bindingRef=0,this.timeout=this.socket.timeout,this.joinedOnce=!1,this.joinPush=new C(this,g.join,this.params,this.timeout),this.pushBuffer=[],this.stateChangeRefs=[],this.rejoinTimer=new y(()=>{this.socket.isConnected()&&this.rejoin()},this.socket.rejoinAfterMs),this.stateChangeRefs.push(this.socket.onError(()=>this.rejoinTimer.reset())),this.stateChangeRefs.push(this.socket.onOpen(()=>{this.rejoinTimer.reset(),this.isErrored()&&this.rejoin()})),this.joinPush.receive("ok",()=>{this.state=d.joined,this.rejoinTimer.reset(),this.pushBuffer.forEach(n=>n.send()),this.pushBuffer=[]}),this.joinPush.receive("error",()=>{this.state=d.errored,this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.onClose(()=>{this.rejoinTimer.reset(),this.socket.hasLogger()&&this.socket.log("channel",`close ${this.topic} ${this.joinRef()}`),this.state=d.closed,this.socket.remove(this)}),this.onError(n=>{this.socket.hasLogger()&&this.socket.log("channel",`error ${this.topic}`,n),this.isJoining()&&this.joinPush.reset(),this.state=d.errored,this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.joinPush.receive("timeout",()=>{this.socket.hasLogger()&&this.socket.log("channel",`timeout ${this.topic} (${this.joinRef()})`,this.joinPush.timeout),new C(this,g.leave,E({}),this.timeout).send(),this.state=d.errored,this.joinPush.reset(),this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.on(g.reply,(n,o)=>{this.trigger(this.replyEventName(o),n)})}join(e=this.timeout){if(this.joinedOnce)throw new Error("tried to join multiple times. 'join' can only be called a single time per channel instance");return this.timeout=e,this.joinedOnce=!0,this.rejoin(),this.joinPush}onClose(e){this.on(g.close,e)}onError(e){return this.on(g.error,t=>e(t))}on(e,t){let s=this.bindingRef++;return this.bindings.push({event:e,ref:s,callback:t}),s}off(e,t){this.bindings=this.bindings.filter(s=>!(s.event===e&&(typeof t=="undefined"||t===s.ref)))}canPush(){return this.socket.isConnected()&&this.isJoined()}push(e,t,s=this.timeout){if(t=t||{},!this.joinedOnce)throw new Error(`tried to push '${e}' to '${this.topic}' before joining. Use channel.join() before pushing events`);let n=new C(this,e,function(){return t},s);return this.canPush()?n.send():(n.startTimeout(),this.pushBuffer.push(n)),n}leave(e=this.timeout){this.rejoinTimer.reset(),this.joinPush.cancelTimeout(),this.state=d.leaving;let t=()=>{this.socket.hasLogger()&&this.socket.log("channel",`leave ${this.topic}`),this.trigger(g.close,"leave")},s=new C(this,g.leave,E({}),e);return s.receive("ok",()=>t()).receive("timeout",()=>t()),s.send(),this.canPush()||s.trigger("ok",{}),s}onMessage(e,t,s){return t}isMember(e,t,s,n){return this.topic!==e?!1:n&&n!==this.joinRef()?(this.socket.hasLogger()&&this.socket.log("channel","dropping outdated message",{topic:e,event:t,payload:s,joinRef:n}),!1):!0}joinRef(){return this.joinPush.ref}rejoin(e=this.timeout){this.isLeaving()||(this.socket.leaveOpenTopic(this.topic),this.state=d.joining,this.joinPush.resend(e))}trigger(e,t,s,n){let o=this.onMessage(e,t,s,n);if(t&&!o)throw new Error("channel onMessage callbacks must return the payload, modified or unmodified");let r=this.bindings.filter(a=>a.event===e);for(let a=0;a<r.length;a++)r[a].callback(o,s,n||this.joinRef())}replyEventName(e){return`chan_reply_${e}`}isClosed(){return this.state===d.closed}isErrored(){return this.state===d.errored}isJoined(){return this.state===d.joined}isJoining(){return this.state===d.joining}isLeaving(){return this.state===d.leaving}};var ue=i=>{let e="",t=new Uint8Array(i),s=t.byteLength;for(let n=0;n<s;n++)e+=String.fromCharCode(t[n]);return btoa(e)},T=class{constructor(e,t){t&&t.length===2&&t[1].startsWith(L)&&(this.authToken=atob(t[1].slice(L.length))),this.endPoint=null,this.token=null,this.skipHeartbeat=!0,this.reqs=new Set,this.awaitingBatchAck=!1,this.currentBatch=null,this.currentBatchTimer=null,this.batchBuffer=[],this.onopen=function(){},this.onerror=function(){},this.onmessage=function(){},this.onclose=function(){},this.pollEndpoint=this.normalizeEndpoint(e),this.readyState=m.connecting,setTimeout(()=>this.poll(),0)}normalizeEndpoint(e){return e.replace("ws://","http://").replace("wss://","https://").replace(new RegExp("(.*)/"+x.websocket),"$1/"+x.longpoll)}endpointURL(){return b.appendParams(this.pollEndpoint,{token:this.token})}closeAndRetry(e,t,s){this.close(e,t,s),this.readyState=m.connecting}ontimeout(){this.onerror("timeout"),this.closeAndRetry(1005,"timeout",!1)}isActive(){return this.readyState===m.open||this.readyState===m.connecting}poll(){let e={Accept:"application/json"};this.authToken&&(e["X-Combo-AuthToken"]=this.authToken),this.ajax("GET",e,null,()=>this.ontimeout(),t=>{if(t){var{status:s,token:n,messages:o}=t;this.token=n}else s=0;switch(s){case 200:o.forEach(r=>{setTimeout(()=>this.onmessage({data:r}),0)}),this.poll();break;case 204:this.poll();break;case 410:this.readyState=m.open,this.onopen({}),this.poll();break;case 403:this.onerror(403),this.close(1008,"forbidden",!1);break;case 0:case 500:this.onerror(500),this.closeAndRetry(1011,"internal server error",500);break;default:throw new Error(`unhandled poll status ${s}`)}})}send(e){typeof e!="string"&&(e=ue(e)),this.currentBatch?this.currentBatch.push(e):this.awaitingBatchAck?this.batchBuffer.push(e):(this.currentBatch=[e],this.currentBatchTimer=setTimeout(()=>{this.batchSend(this.currentBatch),this.currentBatch=null},0))}batchSend(e){this.awaitingBatchAck=!0,this.ajax("POST",{"Content-Type":"application/x-ndjson"},e.join(`
`),()=>this.onerror("timeout"),t=>{this.awaitingBatchAck=!1,!t||t.status!==200?(this.onerror(t&&t.status),this.closeAndRetry(1011,"internal server error",!1)):this.batchBuffer.length>0&&(this.batchSend(this.batchBuffer),this.batchBuffer=[])})}close(e,t,s){for(let o of this.reqs)o.abort();this.readyState=m.closed;let n=Object.assign({code:1e3,reason:void 0,wasClean:!0},{code:e,reason:t,wasClean:s});this.batchBuffer=[],clearTimeout(this.currentBatchTimer),this.currentBatchTimer=null,typeof CloseEvent!="undefined"?this.onclose(new CloseEvent("close",n)):this.onclose(n)}ajax(e,t,s,n,o){let r,a=()=>{this.reqs.delete(r),n()};r=b.request(e,this.endpointURL(),t,s,this.timeout,a,h=>{this.reqs.delete(r),this.isActive()&&o(h)}),this.reqs.add(r)}};var j={HEADER_LENGTH:1,META_LENGTH:4,KINDS:{push:0,reply:1,broadcast:2},encode(i,e){if(i.payload.constructor===ArrayBuffer)return e(this.binaryEncode(i));{let t=[i.join_ref,i.ref,i.topic,i.event,i.payload];return e(JSON.stringify(t))}},decode(i,e){if(i.constructor===ArrayBuffer)return e(this.binaryDecode(i));{let[t,s,n,o,r]=JSON.parse(i);return e({join_ref:t,ref:s,topic:n,event:o,payload:r})}},binaryEncode(i){let{join_ref:e,ref:t,event:s,topic:n,payload:o}=i,r=this.META_LENGTH+e.length+t.length+n.length+s.length,a=new ArrayBuffer(this.HEADER_LENGTH+r),h=new DataView(a),l=0;h.setUint8(l++,this.KINDS.push),h.setUint8(l++,e.length),h.setUint8(l++,t.length),h.setUint8(l++,n.length),h.setUint8(l++,s.length),Array.from(e,u=>h.setUint8(l++,u.charCodeAt(0))),Array.from(t,u=>h.setUint8(l++,u.charCodeAt(0))),Array.from(n,u=>h.setUint8(l++,u.charCodeAt(0))),Array.from(s,u=>h.setUint8(l++,u.charCodeAt(0)));var c=new Uint8Array(a.byteLength+o.byteLength);return c.set(new Uint8Array(a),0),c.set(new Uint8Array(o),a.byteLength),c.buffer},binaryDecode(i){let e=new DataView(i),t=e.getUint8(0),s=new TextDecoder;switch(t){case this.KINDS.push:return this.decodePush(i,e,s);case this.KINDS.reply:return this.decodeReply(i,e,s);case this.KINDS.broadcast:return this.decodeBroadcast(i,e,s)}},decodePush(i,e,t){let s=e.getUint8(1),n=e.getUint8(2),o=e.getUint8(3),r=this.HEADER_LENGTH+this.META_LENGTH-1,a=t.decode(i.slice(r,r+s));r=r+s;let h=t.decode(i.slice(r,r+n));r=r+n;let l=t.decode(i.slice(r,r+o));r=r+o;let c=i.slice(r,i.byteLength);return{join_ref:a,ref:null,topic:h,event:l,payload:c}},decodeReply(i,e,t){let s=e.getUint8(1),n=e.getUint8(2),o=e.getUint8(3),r=e.getUint8(4),a=this.HEADER_LENGTH+this.META_LENGTH,h=t.decode(i.slice(a,a+s));a=a+s;let l=t.decode(i.slice(a,a+n));a=a+n;let c=t.decode(i.slice(a,a+o));a=a+o;let u=t.decode(i.slice(a,a+r));a=a+r;let A=i.slice(a,i.byteLength),_={status:u,response:A};return{join_ref:h,ref:l,topic:c,event:g.reply,payload:_}},decodeBroadcast(i,e,t){let s=e.getUint8(1),n=e.getUint8(2),o=this.HEADER_LENGTH+2,r=t.decode(i.slice(o,o+s));o=o+s;let a=t.decode(i.slice(o,o+n));o=o+n;let h=i.slice(o,i.byteLength);return{join_ref:null,ref:null,topic:r,event:a,payload:h}}};var k=class{constructor(e,t={}){this.stateChangeCallbacks={open:[],close:[],error:[],message:[]},this.channels=[],this.sendBuffer=[],this.ref=0,this.timeout=t.timeout||W,this.transport=t.transport||p.WebSocket||T,this.primaryPassedHealthCheck=!1,this.longPollFallbackMs=t.longPollFallbackMs,this.fallbackTimer=null,this.sessionStore=t.sessionStorage||p&&p.sessionStorage,this.establishedConnections=0,this.defaultEncoder=j.encode.bind(j),this.defaultDecoder=j.decode.bind(j),this.closeWasClean=!1,this.disconnecting=!1,this.binaryType=t.binaryType||"arraybuffer",this.connectClock=1,this.transport!==T?(this.encode=t.encode||this.defaultEncoder,this.decode=t.decode||this.defaultDecoder):(this.encode=this.defaultEncoder,this.decode=this.defaultDecoder);let s=null;v&&v.addEventListener&&(v.addEventListener("pagehide",n=>{this.conn&&(this.disconnect(),s=this.connectClock)}),v.addEventListener("pageshow",n=>{s===this.connectClock&&(s=null,this.connect())})),this.heartbeatIntervalMs=t.heartbeatIntervalMs||3e4,this.rejoinAfterMs=n=>t.rejoinAfterMs?t.rejoinAfterMs(n):[1e3,2e3,5e3][n-1]||1e4,this.reconnectAfterMs=n=>t.reconnectAfterMs?t.reconnectAfterMs(n):[10,50,100,150,200,250,500,1e3,2e3][n-1]||5e3,this.logger=t.logger||null,!this.logger&&t.debug&&(this.logger=(n,o,r)=>{console.log(`${n}: ${o}`,r)}),this.longpollerTimeout=t.longpollerTimeout||2e4,this.params=E(t.params||{}),this.endPoint=`${e}/${x.websocket}`,this.vsn=t.vsn||F,this.heartbeatTimeoutTimer=null,this.heartbeatTimer=null,this.pendingHeartbeatRef=null,this.reconnectTimer=new y(()=>{this.teardown(()=>this.connect())},this.reconnectAfterMs),this.authToken=t.authToken}getLongPollTransport(){return T}replaceTransport(e){this.connectClock++,this.closeWasClean=!0,clearTimeout(this.fallbackTimer),this.reconnectTimer.reset(),this.conn&&(this.conn.close(),this.conn=null),this.transport=e}protocol(){return location.protocol.match(/^https/)?"wss":"ws"}endPointURL(){let e=b.appendParams(b.appendParams(this.endPoint,this.params()),{vsn:this.vsn});return e.charAt(0)!=="/"?e:e.charAt(1)==="/"?`${this.protocol()}:${e}`:`${this.protocol()}://${location.host}${e}`}disconnect(e,t,s){this.connectClock++,this.disconnecting=!0,this.closeWasClean=!0,clearTimeout(this.fallbackTimer),this.reconnectTimer.reset(),this.teardown(()=>{this.disconnecting=!1,e&&e()},t,s)}connect(e){e&&(console&&console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"),this.params=E(e)),!(this.conn&&!this.disconnecting)&&(this.longPollFallbackMs&&this.transport!==T?this.connectWithFallback(T,this.longPollFallbackMs):this.transportConnect())}log(e,t,s){this.logger&&this.logger(e,t,s)}hasLogger(){return this.logger!==null}onOpen(e){let t=this.makeRef();return this.stateChangeCallbacks.open.push([t,e]),t}onClose(e){let t=this.makeRef();return this.stateChangeCallbacks.close.push([t,e]),t}onError(e){let t=this.makeRef();return this.stateChangeCallbacks.error.push([t,e]),t}onMessage(e){let t=this.makeRef();return this.stateChangeCallbacks.message.push([t,e]),t}ping(e){if(!this.isConnected())return!1;let t=this.makeRef(),s=Date.now();this.push({topic:"combo",event:"heartbeat",payload:{},ref:t});let n=this.onMessage(o=>{o.ref===t&&(this.off([n]),e(Date.now()-s))});return!0}transportConnect(){this.connectClock++,this.closeWasClean=!1;let e;this.authToken&&(e=["combo",`${L}${btoa(this.authToken).replace(/=/g,"")}`]),this.conn=new this.transport(this.endPointURL(),e),this.conn.binaryType=this.binaryType,this.conn.timeout=this.longpollerTimeout,this.conn.onopen=()=>this.onConnOpen(),this.conn.onerror=t=>this.onConnError(t),this.conn.onmessage=t=>this.onConnMessage(t),this.conn.onclose=t=>this.onConnClose(t)}getSession(e){return this.sessionStore&&this.sessionStore.getItem(e)}storeSession(e,t){this.sessionStore&&this.sessionStore.setItem(e,t)}connectWithFallback(e,t=2500){clearTimeout(this.fallbackTimer);let s=!1,n=!0,o,r,a=h=>{this.log("transport",`falling back to ${e.name}...`,h),this.off([o,r]),n=!1,this.replaceTransport(e),this.transportConnect()};if(this.getSession(`phx:fallback:${e.name}`))return a("memorized");this.fallbackTimer=setTimeout(a,t),r=this.onError(h=>{this.log("transport","error",h),n&&!s&&(clearTimeout(this.fallbackTimer),a(h))}),this.onOpen(()=>{if(s=!0,!n)return this.primaryPassedHealthCheck||this.storeSession(`phx:fallback:${e.name}`,"true"),this.log("transport",`established ${e.name} fallback`);clearTimeout(this.fallbackTimer),this.fallbackTimer=setTimeout(a,t),this.ping(h=>{this.log("transport","connected to primary after",h),this.primaryPassedHealthCheck=!0,clearTimeout(this.fallbackTimer)})}),this.transportConnect()}clearHeartbeats(){clearTimeout(this.heartbeatTimer),clearTimeout(this.heartbeatTimeoutTimer)}onConnOpen(){this.hasLogger()&&this.log("transport",`${this.transport.name} connected to ${this.endPointURL()}`),this.closeWasClean=!1,this.disconnecting=!1,this.establishedConnections++,this.flushSendBuffer(),this.reconnectTimer.reset(),this.resetHeartbeat(),this.stateChangeCallbacks.open.forEach(([,e])=>e())}heartbeatTimeout(){this.pendingHeartbeatRef&&(this.pendingHeartbeatRef=null,this.hasLogger()&&this.log("transport","heartbeat timeout. Attempting to re-establish connection"),this.triggerChanError(),this.closeWasClean=!1,this.teardown(()=>this.reconnectTimer.scheduleTimeout(),J,"heartbeat timeout"))}resetHeartbeat(){this.conn&&this.conn.skipHeartbeat||(this.pendingHeartbeatRef=null,this.clearHeartbeats(),this.heartbeatTimer=setTimeout(()=>this.sendHeartbeat(),this.heartbeatIntervalMs))}teardown(e,t,s){if(!this.conn)return e&&e();let n=this.connectClock;this.waitForBufferDone(()=>{n===this.connectClock&&(this.conn&&(t?this.conn.close(t,s||""):this.conn.close()),this.waitForSocketClosed(()=>{n===this.connectClock&&(this.conn&&(this.conn.onopen=function(){},this.conn.onerror=function(){},this.conn.onmessage=function(){},this.conn.onclose=function(){},this.conn=null),e&&e())}))})}waitForBufferDone(e,t=1){if(t===5||!this.conn||!this.conn.bufferedAmount){e();return}setTimeout(()=>{this.waitForBufferDone(e,t+1)},150*t)}waitForSocketClosed(e,t=1){if(t===5||!this.conn||this.conn.readyState===m.closed){e();return}setTimeout(()=>{this.waitForSocketClosed(e,t+1)},150*t)}onConnClose(e){let t=e&&e.code;this.hasLogger()&&this.log("transport","close",e),this.triggerChanError(),this.clearHeartbeats(),!this.closeWasClean&&t!==1e3&&this.reconnectTimer.scheduleTimeout(),this.stateChangeCallbacks.close.forEach(([,s])=>s(e))}onConnError(e){this.hasLogger()&&this.log("transport",e);let t=this.transport,s=this.establishedConnections;this.stateChangeCallbacks.error.forEach(([,n])=>{n(e,t,s)}),(t===this.transport||s>0)&&this.triggerChanError()}triggerChanError(){this.channels.forEach(e=>{e.isErrored()||e.isLeaving()||e.isClosed()||e.trigger(g.error)})}connectionState(){switch(this.conn&&this.conn.readyState){case m.connecting:return"connecting";case m.open:return"open";case m.closing:return"closing";default:return"closed"}}isConnected(){return this.connectionState()==="open"}remove(e){this.off(e.stateChangeRefs),this.channels=this.channels.filter(t=>t!==e)}off(e){for(let t in this.stateChangeCallbacks)this.stateChangeCallbacks[t]=this.stateChangeCallbacks[t].filter(([s])=>e.indexOf(s)===-1)}channel(e,t={}){let s=new R(e,t,this);return this.channels.push(s),s}push(e){if(this.hasLogger()){let{topic:t,event:s,payload:n,ref:o,join_ref:r}=e;this.log("push",`${t} ${s} (${r}, ${o})`,n)}this.isConnected()?this.encode(e,t=>this.conn.send(t)):this.sendBuffer.push(()=>this.encode(e,t=>this.conn.send(t)))}makeRef(){let e=this.ref+1;return e===this.ref?this.ref=0:this.ref=e,this.ref.toString()}sendHeartbeat(){this.pendingHeartbeatRef&&!this.isConnected()||(this.pendingHeartbeatRef=this.makeRef(),this.push({topic:"combo",event:"heartbeat",payload:{},ref:this.pendingHeartbeatRef}),this.heartbeatTimeoutTimer=setTimeout(()=>this.heartbeatTimeout(),this.heartbeatIntervalMs))}flushSendBuffer(){this.isConnected()&&this.sendBuffer.length>0&&(this.sendBuffer.forEach(e=>e()),this.sendBuffer=[])}onConnMessage(e){this.decode(e.data,t=>{let{topic:s,event:n,payload:o,ref:r,join_ref:a}=t;r&&r===this.pendingHeartbeatRef&&(this.clearHeartbeats(),this.pendingHeartbeatRef=null,this.heartbeatTimer=setTimeout(()=>this.sendHeartbeat(),this.heartbeatIntervalMs)),this.hasLogger()&&this.log("receive",`${o.status||""} ${s} ${n} ${r&&"("+r+")"||""}`,o);for(let h=0;h<this.channels.length;h++){let l=this.channels[h];l.isMember(s,n,o,a)&&l.trigger(n,o,r,a)}for(let h=0;h<this.stateChangeCallbacks.message.length;h++){let[,l]=this.stateChangeCallbacks.message[h];l(t)}})}leaveOpenTopic(e){let t=this.channels.find(s=>s.topic===e&&(s.isJoined()||s.isJoining()));t&&(this.hasLogger()&&this.log("transport",`leaving duplicate topic "${e}"`),t.leave())}};var V=le(q(),1);function Q(i){let e=Math.round(Date.now()/1e3).toString(),t=i.replace(/(&|\?)vsn=\d*/,"");return t+(t.includes("?")?"&":"?")+"vsn="+e}function xe(i){let e=document.createElement("style"),t=()=>{i.parentNode!==null&&i.parentNode.removeChild(i)},n=(i.textContent||i.innerHTML).replace(/@import\s+(?:url\()?['"]?([^'"\)]+)['"]?\)?/g,(o,r)=>{let a=Q(r);return o.includes("url(")?`@import url("${a}")`:`@import "${a}"`});return e.onerror=t,e.onload=t,i.setAttribute("data-pending-removal",""),e.setAttribute("type","text/css"),e.textContent=n,i.parentNode.insertBefore(e,i.nextSibling),e}function Le(i){let e=document.createElement("link"),t=()=>{i.parentNode!==null&&i.parentNode.removeChild(i)};return e.onerror=t,e.onload=t,i.setAttribute("data-pending-removal",""),e.setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),e.setAttribute("href",Q(i.href)),i.parentNode.insertBefore(e,i.nextSibling),e}function Oe(){navigator.userAgent.toLowerCase().includes("chrome")&&setTimeout(()=>document.body.offsetHeight,25)}function Ne(i,e){let t={type:"full_reload",priority:9,fun:()=>{window[i].location.reload()}};return{css:e?t:{type:"hot_reload",priority:1,fun:()=>{let n=window.parent.document.querySelectorAll("link[rel=stylesheet]:not([data-no-reload]):not([data-pending-removal])");Array.from(n).filter(r=>r.href).forEach(r=>Le(r));let o=window.parent.document.querySelectorAll("style:not([data-no-reload]):not([data-pending-removal])");Array.from(o).filter(r=>r.textContent.includes("@import")).forEach(r=>xe(r)),Oe()}},__default__:t}}var $=class{constructor(e,t,s,n){this.enabledOnce=!1,this.reloadQueue=[],this.socket=new k(e),this.debouncedReload=(0,V.default)(this.reload,t),this.reloadStrategies=Ne(s,n),this.channel=this.socket.channel("combo:live_reload",{}),this.socket.onOpen(()=>{this.enabledOnce||(this.enabledOnce=!0,["complete","loaded","interactive"].includes(parent.document.readyState)?this.dispatchConnected():parent.addEventListener("load",()=>this.dispatchConnected()))}),this.channel.on("reload",o=>{let{type:r}=o;this.scheduleReload(r)})}enable(){this.channel.join(),this.socket.connect()}disable(){this.channel.leave(),this.socket.disconnect(),this.enabledOnce=!1,this.reloadQueue=[]}dispatchConnected(){parent.dispatchEvent(new CustomEvent("combo:live_reloader:connected",{detail:this}))}scheduleReload(e){this.reloadQueue.push(e),this.debouncedReload()}reload(){let t=this.reloadQueue.map(o=>this.getReloadStrategy(o)).reduce((o,r)=>r.priority>o.priority?r:o),{type:s,fun:n}=t;s=="full_reload"&&this.channel.off("reload"),n(),this.reloadQueue=[]}getReloadStrategy(e){return this.reloadStrategies[e]||this.reloadStrategies.__default__}},He=$;return ce(Be);})();
//# sourceMappingURL=live_reloader.min.js.map