UNPKG

actioncable-client-react

Version:

A react wrapper for working with rails actioncable. Requires react v16.3 and above.

14 lines 24.3 kB
module.exports=function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Consumer=e.ActionCableProvider=void 0;var o=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),r=n(1),i=u(r),c=u(n(2)),s=u(n(8));function u(t){return t&&t.__esModule?t:{default:t}}var l=(0,r.createContext)({}),a=l.Provider,f=l.Consumer,p=function(t){function e(t,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n)),r=o.props,i=r.cable,c=r.url,u=r.token;if(i)o.state={cable:i};else{var l=s.default.createConsumer(c,u);o.state={cable:l}}return o}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,r.Component),o(e,[{key:"componentDidUpdate",value:function(t,e){var n=this.props,o=n.cable,r=n.url,i=n.token;if(o!==t.cable||r!==t.url||i!==t.token)if(this.state.cable.disconnect(),o)this.setState({cable:o});else{var c=s.default.createConsumer(r,i);this.setState({cable:c})}}},{key:"componentWillUnmount",value:function(){!this.props.cable&&this.state.cable&&this.state.cable.disconnect()}},{key:"render",value:function(){return i.default.createElement(a,{value:this.state.cable},this.props.children||null)}}]),e}();p.propTypes={cable:c.default.object,url:c.default.string,token:c.default.string,children:c.default.node.isRequired},e.ActionCableProvider=p,e.Consumer=f},function(t,e,n){"use strict";t.exports=n(4)},function(t,e,n){t.exports=n(6)()},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ActionCableProvider=e.ActionCable=void 0;var o,r=n(0),i=n(9),c=(o=i)&&o.__esModule?o:{default:o};e.ActionCable=c.default,e.ActionCableProvider=r.ActionCableProvider},function(t,e,n){"use strict"; /** @license React v16.6.1 * react.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var o=n(5),r="function"==typeof Symbol&&Symbol.for,i=r?Symbol.for("react.element"):60103,c=r?Symbol.for("react.portal"):60106,s=r?Symbol.for("react.fragment"):60107,u=r?Symbol.for("react.strict_mode"):60108,l=r?Symbol.for("react.profiler"):60114,a=r?Symbol.for("react.provider"):60109,f=r?Symbol.for("react.context"):60110,p=r?Symbol.for("react.concurrent_mode"):60111,h=r?Symbol.for("react.forward_ref"):60112,d=r?Symbol.for("react.suspense"):60113,y=r?Symbol.for("react.memo"):60115,b=r?Symbol.for("react.lazy"):60116,v="function"==typeof Symbol&&Symbol.iterator;function m(t){for(var e=arguments.length-1,n="https://reactjs.org/docs/error-decoder.html?invariant="+t,o=0;o<e;o++)n+="&args[]="+encodeURIComponent(arguments[o+1]);!function(t,e,n,o,r,i,c,s){if(!t){if(t=void 0,void 0===e)t=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,o,r,i,c,s],l=0;(t=Error(e.replace(/%s/g,function(){return u[l++]}))).name="Invariant Violation"}throw t.framesToPop=1,t}}(!1,"Minified React error #"+t+"; visit %s for the full message or use the non-minified dev environment for full errors and additional helpful warnings. ",n)}var g={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},S={};function _(t,e,n){this.props=t,this.context=e,this.refs=S,this.updater=n||g}function C(){}function w(t,e,n){this.props=t,this.context=e,this.refs=S,this.updater=n||g}_.prototype.isReactComponent={},_.prototype.setState=function(t,e){"object"!=typeof t&&"function"!=typeof t&&null!=t&&m("85"),this.updater.enqueueSetState(this,t,e,"setState")},_.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},C.prototype=_.prototype;var O=w.prototype=new C;O.constructor=w,o(O,_.prototype),O.isPureReactComponent=!0;var P={current:null,currentDispatcher:null},j=Object.prototype.hasOwnProperty,k={key:!0,ref:!0,__self:!0,__source:!0};function A(t,e,n){var o=void 0,r={},c=null,s=null;if(null!=e)for(o in void 0!==e.ref&&(s=e.ref),void 0!==e.key&&(c=""+e.key),e)j.call(e,o)&&!k.hasOwnProperty(o)&&(r[o]=e[o]);var u=arguments.length-2;if(1===u)r.children=n;else if(1<u){for(var l=Array(u),a=0;a<u;a++)l[a]=arguments[a+2];r.children=l}if(t&&t.defaultProps)for(o in u=t.defaultProps)void 0===r[o]&&(r[o]=u[o]);return{$$typeof:i,type:t,key:c,ref:s,props:r,_owner:P.current}}function R(t){return"object"==typeof t&&null!==t&&t.$$typeof===i}var E=/\/+/g,x=[];function T(t,e,n,o){if(x.length){var r=x.pop();return r.result=t,r.keyPrefix=e,r.func=n,r.context=o,r.count=0,r}return{result:t,keyPrefix:e,func:n,context:o,count:0}}function M(t){t.result=null,t.keyPrefix=null,t.func=null,t.context=null,t.count=0,10>x.length&&x.push(t)}function I(t,e,n){return null==t?0:function t(e,n,o,r){var s=typeof e;"undefined"!==s&&"boolean"!==s||(e=null);var u=!1;if(null===e)u=!0;else switch(s){case"string":case"number":u=!0;break;case"object":switch(e.$$typeof){case i:case c:u=!0}}if(u)return o(r,e,""===n?"."+D(e,0):n),1;if(u=0,n=""===n?".":n+":",Array.isArray(e))for(var l=0;l<e.length;l++){var a=n+D(s=e[l],l);u+=t(s,a,o,r)}else if(a=null===e||"object"!=typeof e?null:"function"==typeof(a=v&&e[v]||e["@@iterator"])?a:null,"function"==typeof a)for(e=a.call(e),l=0;!(s=e.next()).done;)u+=t(s=s.value,a=n+D(s,l++),o,r);else"object"===s&&m("31","[object Object]"==(o=""+e)?"object with keys {"+Object.keys(e).join(", ")+"}":o,"");return u}(t,"",e,n)}function D(t,e){return"object"==typeof t&&null!==t&&null!=t.key?function(t){var e={"=":"=0",":":"=2"};return"$"+(""+t).replace(/[=:]/g,function(t){return e[t]})}(t.key):e.toString(36)}function $(t,e){t.func.call(t.context,e,t.count++)}function W(t,e,n){var o=t.result,r=t.keyPrefix;t=t.func.call(t.context,e,t.count++),Array.isArray(t)?N(t,o,n,function(t){return t}):null!=t&&(R(t)&&(t=function(t,e){return{$$typeof:i,type:t.type,key:e,ref:t.ref,props:t.props,_owner:t._owner}}(t,r+(!t.key||e&&e.key===t.key?"":(""+t.key).replace(E,"$&/")+"/")+n)),o.push(t))}function N(t,e,n,o,r){var i="";null!=n&&(i=(""+n).replace(E,"$&/")+"/"),I(t,W,e=T(e,i,o,r)),M(e)}var U={Children:{map:function(t,e,n){if(null==t)return t;var o=[];return N(t,o,null,e,n),o},forEach:function(t,e,n){if(null==t)return t;I(t,$,e=T(null,null,e,n)),M(e)},count:function(t){return I(t,function(){return null},null)},toArray:function(t){var e=[];return N(t,e,null,function(t){return t}),e},only:function(t){return R(t)||m("143"),t}},createRef:function(){return{current:null}},Component:_,PureComponent:w,createContext:function(t,e){return void 0===e&&(e=null),(t={$$typeof:f,_calculateChangedBits:e,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null}).Provider={$$typeof:a,_context:t},t.Consumer=t},forwardRef:function(t){return{$$typeof:h,render:t}},lazy:function(t){return{$$typeof:b,_ctor:t,_status:-1,_result:null}},memo:function(t,e){return{$$typeof:y,type:t,compare:void 0===e?null:e}},Fragment:s,StrictMode:u,Suspense:d,createElement:A,cloneElement:function(t,e,n){null==t&&m("267",t);var r=void 0,c=o({},t.props),s=t.key,u=t.ref,l=t._owner;if(null!=e){void 0!==e.ref&&(u=e.ref,l=P.current),void 0!==e.key&&(s=""+e.key);var a=void 0;for(r in t.type&&t.type.defaultProps&&(a=t.type.defaultProps),e)j.call(e,r)&&!k.hasOwnProperty(r)&&(c[r]=void 0===e[r]&&void 0!==a?a[r]:e[r])}if(1===(r=arguments.length-2))c.children=n;else if(1<r){a=Array(r);for(var f=0;f<r;f++)a[f]=arguments[f+2];c.children=a}return{$$typeof:i,type:t.type,key:s,ref:u,props:c,_owner:l}},createFactory:function(t){var e=A.bind(null,t);return e.type=t,e},isValidElement:R,version:"16.6.3",__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED:{ReactCurrentOwner:P,assign:o}};U.unstable_ConcurrentMode=p,U.unstable_Profiler=l;var L={default:U},q=L&&U||L;t.exports=q.default||q},function(t,e,n){"use strict"; /* object-assign (c) Sindre Sorhus @license MIT */var o=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;t.exports=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(t){o[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var n,c,s=function(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}(t),u=1;u<arguments.length;u++){for(var l in n=Object(arguments[u]))r.call(n,l)&&(s[l]=n[l]);if(o){c=o(n);for(var a=0;a<c.length;a++)i.call(n,c[a])&&(s[c[a]]=n[c[a]])}}return s}},function(t,e,n){"use strict";var o=n(7);function r(){}t.exports=function(){function t(t,e,n,r,i,c){if(c!==o){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function e(){return t}t.isRequired=t;var n={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return n.checkPropTypes=r,n.PropTypes=n,n}},function(t,e,n){"use strict";t.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(t,e,n){var o,r;(function(){(function(){(function(){var t=[].slice;this.ActionCable={INTERNAL:{message_types:{welcome:"welcome",ping:"ping",confirmation:"confirm_subscription",rejection:"reject_subscription"},default_mount_path:"/cable",protocols:["actioncable-v1-json","actioncable-unsupported"]},WebSocket:window.WebSocket,logger:window.console,createConsumer:function(t){var e;return null==t&&(t=null!=(e=this.getConfig("url"))?e:this.INTERNAL.default_mount_path),new i.Consumer(this.createWebSocketURL(t))},getConfig:function(t){var e;return null!=(e=document.head.querySelector("meta[name='action-cable-"+t+"']"))?e.getAttribute("content"):void 0},createWebSocketURL:function(t){var e;return t&&!/^wss?:/i.test(t)?((e=document.createElement("a")).href=t,e.href=e.href,e.protocol=e.protocol.replace("http","ws"),e.href):t},startDebugging:function(){return this.debugging=!0},stopDebugging:function(){return this.debugging=null},log:function(){var e,n;if(e=1<=arguments.length?t.call(arguments,0):[],this.debugging)return e.push(Date.now()),(n=this.logger).log.apply(n,["[ActionCable]"].concat(t.call(e)))}}}).call(this)}).call(this);var i=this.ActionCable;(function(){(function(){var t=function(t,e){return function(){return t.apply(e,arguments)}};i.ConnectionMonitor=function(){var e,n,o;function r(e){this.connection=e,this.visibilityDidChange=t(this.visibilityDidChange,this),this.reconnectAttempts=0}return r.pollInterval={min:3,max:30},r.staleThreshold=6,r.prototype.start=function(){if(!this.isRunning())return this.startedAt=n(),delete this.stoppedAt,this.startPolling(),document.addEventListener("visibilitychange",this.visibilityDidChange),i.log("ConnectionMonitor started. pollInterval = "+this.getPollInterval()+" ms")},r.prototype.stop=function(){if(this.isRunning())return this.stoppedAt=n(),this.stopPolling(),document.removeEventListener("visibilitychange",this.visibilityDidChange),i.log("ConnectionMonitor stopped")},r.prototype.isRunning=function(){return null!=this.startedAt&&null==this.stoppedAt},r.prototype.recordPing=function(){return this.pingedAt=n()},r.prototype.recordConnect=function(){return this.reconnectAttempts=0,this.recordPing(),delete this.disconnectedAt,i.log("ConnectionMonitor recorded connect")},r.prototype.recordDisconnect=function(){return this.disconnectedAt=n(),i.log("ConnectionMonitor recorded disconnect")},r.prototype.startPolling=function(){return this.stopPolling(),this.poll()},r.prototype.stopPolling=function(){return clearTimeout(this.pollTimeout)},r.prototype.poll=function(){return this.pollTimeout=setTimeout((t=this,function(){return t.reconnectIfStale(),t.poll()}),this.getPollInterval());var t},r.prototype.getPollInterval=function(){var t,n,o,r;return o=(r=this.constructor.pollInterval).min,n=r.max,t=5*Math.log(this.reconnectAttempts+1),Math.round(1e3*e(t,o,n))},r.prototype.reconnectIfStale=function(){if(this.connectionIsStale())return i.log("ConnectionMonitor detected stale connection. reconnectAttempts = "+this.reconnectAttempts+", pollInterval = "+this.getPollInterval()+" ms, time disconnected = "+o(this.disconnectedAt)+" s, stale threshold = "+this.constructor.staleThreshold+" s"),this.reconnectAttempts++,this.disconnectedRecently()?i.log("ConnectionMonitor skipping reopening recent disconnect"):(i.log("ConnectionMonitor reopening"),this.connection.reopen())},r.prototype.connectionIsStale=function(){var t;return o(null!=(t=this.pingedAt)?t:this.startedAt)>this.constructor.staleThreshold},r.prototype.disconnectedRecently=function(){return this.disconnectedAt&&o(this.disconnectedAt)<this.constructor.staleThreshold},r.prototype.visibilityDidChange=function(){if("visible"===document.visibilityState)return setTimeout((t=this,function(){if(t.connectionIsStale()||!t.connection.isOpen())return i.log("ConnectionMonitor reopening stale connection on visibilitychange. visbilityState = "+document.visibilityState),t.connection.reopen()}),200);var t},n=function(){return(new Date).getTime()},o=function(t){return(n()-t)/1e3},e=function(t,e,n){return Math.max(e,Math.min(n,t))},r}()}).call(this),function(){var t,e,n,o,r,c=[].slice,s=function(t,e){return function(){return t.apply(e,arguments)}},u=[].indexOf||function(t){for(var e=0,n=this.length;e<n;e++)if(e in this&&this[e]===t)return e;return-1};o=i.INTERNAL,e=o.message_types,n=o.protocols,r=2<=n.length?c.call(n,0,t=n.length-1):(t=0,[]),n[t++],i.Connection=function(){function t(t){this.consumer=t,this.open=s(this.open,this),this.subscriptions=this.consumer.subscriptions,this.monitor=new i.ConnectionMonitor(this),this.disconnected=!0}return t.reopenDelay=500,t.prototype.send=function(t){return!!this.isOpen()&&(this.webSocket.send(JSON.stringify(t)),!0)},t.prototype.open=function(){return this.isActive()?(i.log("Attempted to open WebSocket, but existing socket is "+this.getState()),!1):(i.log("Opening WebSocket, current state is "+this.getState()+", subprotocols: "+n),null!=this.webSocket&&this.uninstallEventHandlers(),this.webSocket=new i.WebSocket(this.consumer.url,n),this.installEventHandlers(),this.monitor.start(),!0)},t.prototype.close=function(t){var e;if((null!=t?t:{allowReconnect:!0}).allowReconnect||this.monitor.stop(),this.isActive())return null!=(e=this.webSocket)?e.close():void 0},t.prototype.reopen=function(){var t;if(i.log("Reopening WebSocket, current state is "+this.getState()),!this.isActive())return this.open();try{return this.close()}catch(e){return t=e,i.log("Failed to reopen WebSocket",t)}finally{i.log("Reopening WebSocket in "+this.constructor.reopenDelay+"ms"),setTimeout(this.open,this.constructor.reopenDelay)}},t.prototype.getProtocol=function(){var t;return null!=(t=this.webSocket)?t.protocol:void 0},t.prototype.isOpen=function(){return this.isState("open")},t.prototype.isActive=function(){return this.isState("open","connecting")},t.prototype.isProtocolSupported=function(){var t;return t=this.getProtocol(),u.call(r,t)>=0},t.prototype.isState=function(){var t,e;return e=1<=arguments.length?c.call(arguments,0):[],t=this.getState(),u.call(e,t)>=0},t.prototype.getState=function(){var t,e;for(e in WebSocket)if(WebSocket[e]===(null!=(t=this.webSocket)?t.readyState:void 0))return e.toLowerCase();return null},t.prototype.installEventHandlers=function(){var t,e;for(t in this.events)e=this.events[t].bind(this),this.webSocket["on"+t]=e},t.prototype.uninstallEventHandlers=function(){var t;for(t in this.events)this.webSocket["on"+t]=function(){}},t.prototype.events={message:function(t){var n,o,r;if(this.isProtocolSupported())switch(n=(r=JSON.parse(t.data)).identifier,o=r.message,r.type){case e.welcome:return this.monitor.recordConnect(),this.subscriptions.reload();case e.ping:return this.monitor.recordPing();case e.confirmation:return this.subscriptions.notify(n,"connected");case e.rejection:return this.subscriptions.reject(n);default:return this.subscriptions.notify(n,"received",o)}},open:function(){if(i.log("WebSocket onopen event, using '"+this.getProtocol()+"' subprotocol"),this.disconnected=!1,!this.isProtocolSupported())return i.log("Protocol is unsupported. Stopping monitor and disconnecting."),this.close({allowReconnect:!1})},close:function(t){if(i.log("WebSocket onclose event"),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll("disconnected",{willAttemptReconnect:this.monitor.isRunning()})},error:function(){return i.log("WebSocket onerror event")}},t}()}.call(this),function(){var t=[].slice;i.Subscriptions=function(){function e(t){this.consumer=t,this.subscriptions=[]}return e.prototype.create=function(t,e){var n,o,r;return o="object"==typeof(n=t)?n:{channel:n},r=new i.Subscription(this.consumer,o,e),this.add(r)},e.prototype.add=function(t){return this.subscriptions.push(t),this.consumer.ensureActiveConnection(),this.notify(t,"initialized"),this.sendCommand(t,"subscribe"),t},e.prototype.remove=function(t){return this.forget(t),this.findAll(t.identifier).length||this.sendCommand(t,"unsubscribe"),t},e.prototype.reject=function(t){var e,n,o,r,i;for(r=[],e=0,n=(o=this.findAll(t)).length;e<n;e++)i=o[e],this.forget(i),this.notify(i,"rejected"),r.push(i);return r},e.prototype.forget=function(t){var e;return this.subscriptions=function(){var n,o,r,i;for(i=[],n=0,o=(r=this.subscriptions).length;n<o;n++)(e=r[n])!==t&&i.push(e);return i}.call(this),t},e.prototype.findAll=function(t){var e,n,o,r,i;for(r=[],e=0,n=(o=this.subscriptions).length;e<n;e++)(i=o[e]).identifier===t&&r.push(i);return r},e.prototype.reload=function(){var t,e,n,o,r;for(o=[],t=0,e=(n=this.subscriptions).length;t<e;t++)r=n[t],o.push(this.sendCommand(r,"subscribe"));return o},e.prototype.notifyAll=function(){var e,n,o,r,i,c,s;for(n=arguments[0],e=2<=arguments.length?t.call(arguments,1):[],c=[],o=0,r=(i=this.subscriptions).length;o<r;o++)s=i[o],c.push(this.notify.apply(this,[s,n].concat(t.call(e))));return c},e.prototype.notify=function(){var e,n,o,r,i,c,s;for(c=arguments[0],n=arguments[1],e=3<=arguments.length?t.call(arguments,2):[],i=[],o=0,r=(s="string"==typeof c?this.findAll(c):[c]).length;o<r;o++)c=s[o],i.push("function"==typeof c[n]?c[n].apply(c,e):void 0);return i},e.prototype.sendCommand=function(t,e){var n;return n=t.identifier,this.consumer.send({command:e,identifier:n})},e}()}.call(this),function(){i.Subscription=function(){var t;function e(e,n,o){this.consumer=e,null==n&&(n={}),this.identifier=JSON.stringify(n),t(this,o)}return e.prototype.perform=function(t,e){return null==e&&(e={}),e.action=t,this.send(e)},e.prototype.send=function(t){return this.consumer.send({command:"message",identifier:this.identifier,data:JSON.stringify(t)})},e.prototype.unsubscribe=function(){return this.consumer.subscriptions.remove(this)},t=function(t,e){var n,o;if(null!=e)for(n in e)o=e[n],t[n]=o;return t},e}()}.call(this),function(){i.Consumer=function(){function t(t){this.url=t,this.subscriptions=new i.Subscriptions(this),this.connection=new i.Connection(this)}return t.prototype.send=function(t){return this.connection.send(t)},t.prototype.connect=function(){return this.connection.open()},t.prototype.disconnect=function(){return this.connection.close({allowReconnect:!1})},t.prototype.ensureActiveConnection=function(){if(!this.connection.isActive())return this.connection.open()},t}()}.call(this)}).call(this),t.exports?t.exports=i:void 0===(r="function"==typeof(o=i)?o.call(e,n,e,t):o)||(t.exports=r)}).call(this)},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},r=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),i=n(1),c=l(i),s=l(n(2)),u=n(0);function l(t){return t&&t.__esModule?t:{default:t}}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var f=function(t){function e(){var t,n,o;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);for(var r=arguments.length,i=Array(r),c=0;c<r;c++)i[c]=arguments[c];return n=o=a(this,(t=e.__proto__||Object.getPrototypeOf(e)).call.apply(t,[this].concat(i))),o.state={subscribedChannel:null},o.send=function(t){if(!o.state.subscribedChannel)throw new Error("ActionCable component unloaded");o.state.subscribedChannel.send(t)},o.perform=function(t,e){if(!o.state.subscribedChannel)throw new Error("ActionCable component unloaded");o.state.subscribedChannel.perform(t,e)},a(o,n)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,i.PureComponent),r(e,[{key:"componentDidMount",value:function(){var t=this.props,e=t.onReceived,n=t.onInitialized,o=t.onConnected,r=t.onDisconnected,i=t.onRejected,c=t.cable,s=t.channel,u=t.room,l=c.subscriptions.create({channel:s,room:u},{received:function(t){e&&e(t)},initialized:function(){n&&n()},connected:function(){o&&o()},disconnected:function(){r&&r()},rejected:function(){i&&i()}});this.setState({subscribedChannel:l})}},{key:"componentWillUnmount",value:function(){this.state.subscribedChannel&&this.props.cable.subscriptions.remove(this.state.subscribedChannel)}},{key:"render",value:function(){var t=this,e=this.props.children;return i.Children.map(e,function(e){return(0,i.cloneElement)(e,{perform:t.perform,send:t.send})})||null}}]),e}();f.propTypes={onReceived:s.default.func,onInitialized:s.default.func,onConnected:s.default.func,onDisconnected:s.default.func,onRejected:s.default.func,children:s.default.any,cable:s.default.object.isRequired,channel:s.default.string.isRequired,room:s.default.oneOfType([s.default.string,s.default.number])},e.default=function(t){return c.default.createElement(u.Consumer,null,function(e){return c.default.createElement(f,o({},t,{cable:e}))})}}]);