(()=>{function e(r,c,t,e,n,o,s){var u,a,i,l,f,g,p,d;return e.getFlag("e2e")?{subscribe:function(){return c.when()},configure:_.noop,status:_.noop}:(u=new org.cometd.CometD,a={},i={url:e.url("cep/customnotifications"),logLevel:"info",requestHeaders:n.headers(),appendMessageTypeToURL:!1},l=57e4,p=_.cloneDeep(i),d="notification:message",p.url=e.url("cep/notifications"),u.unregisterTransports(),u.registerTransport("long-polling",new o.LongPollingTransport),e=s.getAcceptEmptyMessagesExt(),u.registerExtension(e.name,e),u.configure(_.cloneDeep(i)),{subscribe:function(e){var n,t,o,s=a[e]||{},i=!1;return s.channel||(i=!0,(a[e]=s).channel=e,s.scope=r.$new(!0),s.scope.unsubscribe=angular.bind({},y,s),s.counter=0),s.counter++,o=c.defer(),u.isDisconnected()?(u.handshake(),n=u.addListener("/meta/connect",function(){o.resolve(!0),u.removeListener(n)}),t=u.addListener("/meta/connect",function(e){e.failure&&401===e.failure.httpCode&&(u.disconnect(),u.removeListener(t))}),g=u.addListener("/meta/subscribe",b)):o.resolve(!0),o.promise.then(function(){return i&&(s.comet=u.subscribe(e,angular.bind({},h,s.scope)),f=m()),r=s.scope,c=r.$on,r.$on=function(e){"message"===e&&(e=d);for(var n=arguments.length,t=new Array(1<n?n-1:0),o=1;o<n;o++)t[o-1]=arguments[o];return c.call.apply(c,[r,e].concat(t))},r;var r,c})},configure:function(e){i.requestHeaders=n.headers(),p.requestHeaders=n.headers(),e=_.cloneDeep("debug"===e?p:i),u.configure(e)},status:function(){return u.getStatus()}});function m(){return t(function(){u.getTransport().abort()},l)}function b(e){n=e,e=_.keys(a).filter(function(e){return n.subscription.match(e)});var n,e=a[e[0]];e.scope.$emit("connected"),e.scope.connected=!0}function h(e,n){f&&(t.cancel(),f=m()),e.$emit(d,n)}function y(e){e.counter--,e.counter||(u.unsubscribe(e.comet),delete a[e.channel],_.keys(a).length)||(f&&(t.cancel(f),f=void 0),u.removeListener(g),u.disconnect())}}e.$inject=["$rootScope","$q","$timeout","c8yBase","c8yAuth","c8yLongPollingTransport","c8yCometdExtensions"],angular.module("c8y.core").factory("c8yNotifications",e)})();