import e from"@babel/runtime/helpers/classCallCheck";import t from"@babel/runtime/helpers/createClass";import r from"@babel/runtime/helpers/defineProperty";import{io as n}from"socket.io-client";import{IGNORED_ROUTES_REGEXP as o,getHrefDebugField as i,SUBSCRIPTIONS_URL as c}from"./constants.js";import{SubscriptionsClientV2 as s}from"./subscriptions-client.js";import{DummySubscriptionsClient as a}from"./subscriptions-client.dummy.js";function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}var u=function(){function u(){e(this,u)}return t(u,null,[{key:"init",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:c,t=new URL(e).origin;return this.instances.has(t)||this.instances.set(t,this.create(e)),this.instances.get(t)}},{key:"create",value:function(e){if(o.test(window.location.pathname))return new a;var t=n(e,{transports:["websocket"],autoConnect:!0,path:process.env.REACT_APP_SUBSCRIPTIONS_PATH||"/socket.io"}),c=0;return t.on("connect",(function(){(c+=1,t.recovered)||1!==c&&Object.keys(t._callbacks).filter((function(e){return e.startsWith("$data#")})).map((function(e){return e.replace("$data#","")})).forEach((function(e){t.emit("subscribe",function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?p(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({channel:e},i()))}))})),new s(t)}}]),u}();r(u,"instances",new Map);export{u as SubscriptionsClientFactory};
//# sourceMappingURL=subscriptions-client.factory.js.map
