!function(){"use strict";const n="KH",t="kh_sdk_onload";if(window[n])return;const e=function(){let n=null;const t=[],e={},i=[];let o=null;const c={},s=0,u=1,l=2,r=3;let f=s;const a=3;let h=null,d=0;function p(){d=0,g()}function g(){f!==u&&f!==s||(f===s&&window.addEventListener("online",p,!1),window.navigator.onLine?(f===u&&clearTimeout(h),n=new WebSocket("wss://www.kronehit.at/api/v1/socket/"),n.onopen=function(t){if(t.currentTarget===n){d=0,f=r;let n=[];for(let t in e)e.hasOwnProperty(t)&&e[t].length>0&&n.push(parseInt(t));n.length>0&&w({type:"select_channels",channelIds:n})}},n.onmessage=function(i){if(i.currentTarget===n&&f===r){const n=JSON.parse(i.data);if("configuration"===n.type){if(o&&JSON.stringify(n)===JSON.stringify(o))return;o=n,t.forEach((function(t){O(t,n)}))}else if("playlist_update"===n.type){const t=parseInt(n.channelId);if(isNaN(t))return;const i=c[t];if(i&&JSON.stringify(n)===JSON.stringify(i))return;c[t]=n,void 0!==e[t]&&e[t].forEach((function(t){O(t,n)}))}}},n.onclose=function(t){if(t.currentTarget===n){d++;const n=(e=1e3*a,i=1e3*Math.pow(a,d)+1e3*a,Math.floor(Math.random()*(i-e+1)+e));h=setTimeout((function(){h=null,g()}),n),f=u}var e,i},f=l):f=u)}function w(t){if(f===r){const e=JSON.stringify(t);n.send(e)}}function y(n,t){const e=t.indexOf(n);return-1!==e&&(t.splice(e,1),!0)}function O(n,t){let e=JSON.parse(JSON.stringify(t));"configuration"===e.type?e=e.data:delete e.type,n(e)}return{watch:function(l){let r=!1;const a=[],N=(l=l||{}).onConfiguration,E=l.onPlaylistUpdate;function S(n){if(r||!E)return;const t=[];n.forEach((function(n){function i(){c[n]&&setTimeout((function(){O(E,c[n])}),0)}-1===a.indexOf(n)?(a.push(n),void 0===e[n]&&(e[n]=[]),e[n].push(E),1===e[n].length&&t.push(n),i()):i()})),t.length>0&&w({type:"select_channels",channelIds:t})}function T(n){if(r||!E)return;const t=[];n.forEach((function(n){y(n,a)&&(y(E,e[n]),0===e[n].length&&t.push(n))})),t.length>0&&w({type:"unselect_channels",channelIds:t})}const _={selectChannel:function(n){n&&-1!==a.indexOf(n)||(T(a.slice()),n&&S([n]))},selectChannels:S,unselectChannels:T,unwatch:function(){y(_,i)&&(T(a.slice()),r=!0,N&&y(N,t),i.length||function(){if(f!==s){if(f===u)clearTimeout(h);else{const t=n;n=null,t.close()}window.removeEventListener("online",p,!1),f=s,d=0}}())}};return i.push(_),f===s&&g(),N&&(t.push(N),o&&setTimeout((function(){O(N,o)}),0)),_}}}();window[n]={watch:e.watch},window[t]&&window[t]()}();