(window.webpackJsonp=window.webpackJsonp||[]).push([[33],{"37Xj":function(e,t,n){"use strict";n.d(t,"a",function(){return _makeFlat});var r=n("wBll");function _makeFlat(e){return function flatt(t){for(var n,o,i,s=[],a=0,c=t.length;a0&&void 0!==arguments[0]?arguments[0]: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}},{key:"onClose",value:function onClose(e){this.on(p.close,e)}},{key:"onError",value:function onError(e){return this.on(p.error,function(t){return e(t)})}},{key:"on",value:function on(e,t){var n=this.bindingRef++;return this.bindings.push({event:e,ref:n,callback:t}),n}},{key:"off",value:function off(e,t){this.bindings=this.bindings.filter(function(n){return!(n.event===e&&("undefined"===typeof t||t===n.ref))})}},{key:"canPush",value:function canPush(){return this.socket.isConnected()&&this.isJoined()}},{key:"push",value:function push(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.timeout;if(t=t||{},!this.joinedOnce)throw new Error("tried to push '".concat(e,"' to '").concat(this.topic,"' before joining. Use channel.join() before pushing events"));var r=new m(this,e,function(){return t},n);return this.canPush()?r.send():(r.startTimeout(),this.pushBuffer.push(r)),r}},{key:"leave",value:function leave(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.timeout;this.rejoinTimer.reset(),this.joinPush.cancelTimeout(),this.state=d.leaving;var n=function onClose(){e.socket.hasLogger()&&e.socket.log("channel","leave ".concat(e.topic)),e.trigger(p.close,"leave")},r=new m(this,p.leave,s({}),t);return r.receive("ok",function(){return n()}).receive("timeout",function(){return n()}),r.send(),this.canPush()||r.trigger("ok",{}),r}},{key:"onMessage",value:function onMessage(e,t,n){return t}},{key:"isMember",value:function isMember(e,t,n,r){return this.topic===e&&(!r||r===this.joinRef()||(this.socket.hasLogger()&&this.socket.log("channel","dropping outdated message",{topic:e,event:t,payload:n,joinRef:r}),!1))}},{key:"joinRef",value:function joinRef(){return this.joinPush.ref}},{key:"rejoin",value:function rejoin(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.timeout;this.isLeaving()||(this.socket.leaveOpenTopic(this.topic),this.state=d.joining,this.joinPush.resend(e))}},{key:"trigger",value:function trigger(e,t,n,r){var o=this.onMessage(e,t,n,r);if(t&&!o)throw new Error("channel onMessage callbacks must return the payload, modified or unmodified");for(var i=this.bindings.filter(function(t){return t.event===e}),s=0;s1&&void 0!==arguments[1]?arguments[1]:{};Object(o.a)(this,Socket),this.stateChangeCallbacks={open:[],close:[],error:[],message:[]},this.channels=[],this.sendBuffer=[],this.ref=0,this.timeout=n.timeout||f,this.transport=n.transport||u.WebSocket||j,this.establishedConnections=0,this.defaultEncoder=C.encode.bind(C),this.defaultDecoder=C.decode.bind(C),this.closeWasClean=!1,this.binaryType=n.binaryType||"arraybuffer",this.connectClock=1,this.transport!==j?(this.encode=n.encode||this.defaultEncoder,this.decode=n.decode||this.defaultDecoder):(this.encode=this.defaultEncoder,this.decode=this.defaultDecoder);var r=null;c&&c.addEventListener&&(c.addEventListener("pagehide",function(e){t.conn&&(t.disconnect(),r=t.connectClock)}),c.addEventListener("pageshow",function(e){r===t.connectClock&&(r=null,t.connect())})),this.heartbeatIntervalMs=n.heartbeatIntervalMs||3e4,this.rejoinAfterMs=function(e){return n.rejoinAfterMs?n.rejoinAfterMs(e):[1e3,2e3,5e3][e-1]||1e4},this.reconnectAfterMs=function(e){return n.reconnectAfterMs?n.reconnectAfterMs(e):[10,50,100,150,200,250,500,1e3,2e3][e-1]||5e3},this.logger=n.logger||null,this.longpollerTimeout=n.longpollerTimeout||2e4,this.params=s(n.params||{}),this.endPoint="".concat(e,"/").concat(v.websocket),this.vsn=n.vsn||h,this.heartbeatTimeoutTimer=null,this.heartbeatTimer=null,this.pendingHeartbeatRef=null,this.reconnectTimer=new y(function(){t.teardown(function(){return t.connect()})},this.reconnectAfterMs)}return Object(i.a)(Socket,[{key:"getLongPollTransport",value:function getLongPollTransport(){return j}},{key:"replaceTransport",value:function replaceTransport(e){this.connectClock++,this.closeWasClean=!0,this.reconnectTimer.reset(),this.sendBuffer=[],this.conn&&(this.conn.close(),this.conn=null),this.transport=e}},{key:"protocol",value:function protocol(){return location.protocol.match(/^https/)?"wss":"ws"}},{key:"endPointURL",value:function endPointURL(){var e=b.appendParams(b.appendParams(this.endPoint,this.params()),{vsn:this.vsn});return"/"!==e.charAt(0)?e:"/"===e.charAt(1)?"".concat(this.protocol(),":").concat(e):"".concat(this.protocol(),"://").concat(location.host).concat(e)}},{key:"disconnect",value:function disconnect(e,t,n){this.connectClock++,this.closeWasClean=!0,this.reconnectTimer.reset(),this.teardown(e,t,n)}},{key:"connect",value:function connect(e){var t=this;e&&(console&&console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"),this.params=s(e)),this.conn||(this.connectClock++,this.closeWasClean=!1,this.conn=new this.transport(this.endPointURL()),this.conn.binaryType=this.binaryType,this.conn.timeout=this.longpollerTimeout,this.conn.onopen=function(){return t.onConnOpen()},this.conn.onerror=function(e){return t.onConnError(e)},this.conn.onmessage=function(e){return t.onConnMessage(e)},this.conn.onclose=function(e){return t.onConnClose(e)})}},{key:"log",value:function log(e,t,n){this.logger(e,t,n)}},{key:"hasLogger",value:function hasLogger(){return null!==this.logger}},{key:"onOpen",value:function onOpen(e){var t=this.makeRef();return this.stateChangeCallbacks.open.push([t,e]),t}},{key:"onClose",value:function onClose(e){var t=this.makeRef();return this.stateChangeCallbacks.close.push([t,e]),t}},{key:"onError",value:function onError(e){var t=this.makeRef();return this.stateChangeCallbacks.error.push([t,e]),t}},{key:"onMessage",value:function onMessage(e){var t=this.makeRef();return this.stateChangeCallbacks.message.push([t,e]),t}},{key:"ping",value:function ping(e){var t=this;if(!this.isConnected())return!1;var n=this.makeRef(),r=Date.now();this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:n});var o=this.onMessage(function(i){i.ref===n&&(t.off([o]),e(Date.now()-r))});return!0}},{key:"clearHeartbeats",value:function clearHeartbeats(){clearTimeout(this.heartbeatTimer),clearTimeout(this.heartbeatTimeoutTimer)}},{key:"onConnOpen",value:function onConnOpen(){this.hasLogger()&&this.log("transport","connected to ".concat(this.endPointURL())),this.closeWasClean=!1,this.establishedConnections++,this.flushSendBuffer(),this.reconnectTimer.reset(),this.resetHeartbeat(),this.stateChangeCallbacks.open.forEach(function(e){return(0,Object(r.a)(e,2)[1])()})}},{key:"heartbeatTimeout",value:function heartbeatTimeout(){var e=this;this.pendingHeartbeatRef&&(this.pendingHeartbeatRef=null,this.hasLogger()&&this.log("transport","heartbeat timeout. Attempting to re-establish connection"),this.triggerChanError(),this.closeWasClean=!1,this.teardown(function(){return e.reconnectTimer.scheduleTimeout()},1e3,"heartbeat timeout"))}},{key:"resetHeartbeat",value:function resetHeartbeat(){var e=this;this.conn&&this.conn.skipHeartbeat||(this.pendingHeartbeatRef=null,this.clearHeartbeats(),this.heartbeatTimer=setTimeout(function(){return e.sendHeartbeat()},this.heartbeatIntervalMs))}},{key:"teardown",value:function teardown(e,t,n){var r=this;if(!this.conn)return e&&e();this.waitForBufferDone(function(){r.conn&&(t?r.conn.close(t,n||""):r.conn.close()),r.waitForSocketClosed(function(){r.conn&&(r.conn.onopen=function(){},r.conn.onerror=function(){},r.conn.onmessage=function(){},r.conn.onclose=function(){},r.conn=null),e&&e()})})}},{key:"waitForBufferDone",value:function waitForBufferDone(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;5!==n&&this.conn&&this.conn.bufferedAmount?setTimeout(function(){t.waitForBufferDone(e,n+1)},150*n):e()}},{key:"waitForSocketClosed",value:function waitForSocketClosed(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;5!==n&&this.conn&&this.conn.readyState!==l.closed?setTimeout(function(){t.waitForSocketClosed(e,n+1)},150*n):e()}},{key:"onConnClose",value:function onConnClose(e){var t=e&&e.code;this.hasLogger()&&this.log("transport","close",e),this.triggerChanError(),this.clearHeartbeats(),this.closeWasClean||1e3===t||this.reconnectTimer.scheduleTimeout(),this.stateChangeCallbacks.close.forEach(function(t){return(0,Object(r.a)(t,2)[1])(e)})}},{key:"onConnError",value:function onConnError(e){this.hasLogger()&&this.log("transport",e);var t=this.transport,n=this.establishedConnections;this.stateChangeCallbacks.error.forEach(function(o){(0,Object(r.a)(o,2)[1])(e,t,n)}),(t===this.transport||n>0)&&this.triggerChanError()}},{key:"triggerChanError",value:function triggerChanError(){this.channels.forEach(function(e){e.isErrored()||e.isLeaving()||e.isClosed()||e.trigger(p.error)})}},{key:"connectionState",value:function connectionState(){switch(this.conn&&this.conn.readyState){case l.connecting:return"connecting";case l.open:return"open";case l.closing:return"closing";default:return"closed"}}},{key:"isConnected",value:function isConnected(){return"open"===this.connectionState()}},{key:"remove",value:function remove(e){this.off(e.stateChangeRefs),this.channels=this.channels.filter(function(t){return t.joinRef()!==e.joinRef()})}},{key:"off",value:function off(e){for(var t in this.stateChangeCallbacks)this.stateChangeCallbacks[t]=this.stateChangeCallbacks[t].filter(function(t){var n=Object(r.a)(t,1)[0];return-1===e.indexOf(n)})}},{key:"channel",value:function channel(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new k(e,t,this);return this.channels.push(n),n}},{key:"push",value:function push(e){var t=this;if(this.hasLogger()){var n=e.topic,r=e.event,o=e.payload,i=e.ref,s=e.join_ref;this.log("push","".concat(n," ").concat(r," (").concat(s,", ").concat(i,")"),o)}this.isConnected()?this.encode(e,function(e){return t.conn.send(e)}):this.sendBuffer.push(function(){return t.encode(e,function(e){return t.conn.send(e)})})}},{key:"makeRef",value:function makeRef(){var e=this.ref+1;return e===this.ref?this.ref=0:this.ref=e,this.ref.toString()}},{key:"sendHeartbeat",value:function sendHeartbeat(){var e=this;this.pendingHeartbeatRef&&!this.isConnected()||(this.pendingHeartbeatRef=this.makeRef(),this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:this.pendingHeartbeatRef}),this.heartbeatTimeoutTimer=setTimeout(function(){return e.heartbeatTimeout()},this.heartbeatIntervalMs))}},{key:"flushSendBuffer",value:function flushSendBuffer(){this.isConnected()&&this.sendBuffer.length>0&&(this.sendBuffer.forEach(function(e){return e()}),this.sendBuffer=[])}},{key:"onConnMessage",value:function onConnMessage(e){var t=this;this.decode(e.data,function(e){var n=e.topic,o=e.event,i=e.payload,s=e.ref,a=e.join_ref;s&&s===t.pendingHeartbeatRef&&(t.clearHeartbeats(),t.pendingHeartbeatRef=null,t.heartbeatTimer=setTimeout(function(){return t.sendHeartbeat()},t.heartbeatIntervalMs)),t.hasLogger()&&t.log("receive","".concat(i.status||""," ").concat(n," ").concat(o," ").concat(s&&"("+s+")"||""),i);for(var c=0;c=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}(t,["wrappedComponentRef"]);return o.a.createElement(u.a,{children:function children(t){return o.a.createElement(e,h({},r,t,{ref:n}))}})};return t.displayName="withRouter("+(e.displayName||e.name)+")",t.WrappedComponent=e,t.propTypes={wrappedComponentRef:s.a.func},c()(t,e)};t.a=l},utat:function(e,t){e.exports=function(e,t,n,r){var o,i=0;return"boolean"!==typeof t&&(r=n,n=t,t=void 0),function wrapper(){var s=this,a=Number(new Date)-i,c=arguments;function exec(){i=Number(new Date),n.apply(s,c)}r&&!o&&exec(),o&&clearTimeout(o),void 0===r&&a>e?exec():!0!==t&&(o=setTimeout(r?function clear(){o=void 0}:exec,void 0===r?e-a:e))}}}}]);