"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[83354],{67122:function(e,t,n){n.r(t),n(29305),n(32733),n(84701),n(81678),n(44962),n(89336),n(26448),n(4754),n(94),n(36947),n(78557),n(90076),n(45309),n(83994),n(82367);var i=n(44797);function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,l(i.key),i)}}function o(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(e){var t=function(e,t){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,"string");if("object"!=r(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==r(t)?t:t+""}var a=function(){return o((function e(t,n,i,r){s(this,e),this.requestSent=t.getTime(),this.requestReceived=n.getTime(),this.responseSent=i.getTime(),this.responseReceived=r.getTime()}),[{key:"getOffset",value:function(){return(this.requestReceived-this.requestSent+(this.responseSent-this.responseReceived))/2}},{key:"getDelay",value:function(){return this.responseReceived-this.requestSent-(this.responseSent-this.requestReceived)}},{key:"getPing",value:function(){return this.getDelay()/2}}])}(),c=function(){return o((function e(t){s(this,e),this.manager=t,this.pingStop=!0,this.pollingInterval=1e3,this.poller=null,this.pings=0,this.measurement=null,this.measurements=[]}),[{key:"isReady",value:function(){return!!this.measurement}},{key:"getTimeOffset",value:function(){return this.measurement?this.measurement.getOffset():0}},{key:"getPing",value:function(){return this.measurement?this.measurement.getPing():0}},{key:"updateTimeOffset",value:function(e){this.measurements.push(e),this.measurements.length>8&&this.measurements.shift();var t=this.measurements.slice(0);t.sort((function(e,t){return e.getDelay()-t.getDelay()})),this.measurement=t[0]}},{key:"requestPing",value:function(){return console.warn("SyncPlay TimeSync requestPing: override this method!"),Promise.reject(new Error("Not implemented."))}},{key:"internalRequestPing",value:function(){var e=this;this.poller||this.pingStop||(this.poller=setTimeout((function(){e.poller=null,e.requestPing().then((function(t){return e.onPingResponseCallback(t)})).catch((function(t){return e.onPingRequestErrorCallback(t)})).finally((function(){return e.internalRequestPing()}))}),this.pollingInterval))}},{key:"onPingResponseCallback",value:function(e){var t=e.requestSent,n=e.requestReceived,r=e.responseSent,s=e.responseReceived,u=new a(t,n,r,s);this.updateTimeOffset(u),this.pings>=3?this.pollingInterval=6e4:this.pings++,i.A.trigger(this,"update",[null,this.getTimeOffset(),this.getPing()])}},{key:"onPingRequestErrorCallback",value:function(e){console.error(e),i.A.trigger(this,"update",[e,null,null])}},{key:"resetMeasurements",value:function(){this.measurement=null,this.measurements=[]}},{key:"startPing",value:function(){this.pingStop=!1,this.internalRequestPing()}},{key:"stopPing",value:function(){this.pingStop=!0,this.poller&&(clearTimeout(this.poller),this.poller=null)}},{key:"forceUpdate",value:function(){this.stopPing(),this.pollingInterval=1e3,this.pings=0,this.startPing()}},{key:"remoteDateToLocal",value:function(e){return new Date(e.getTime()-this.getTimeOffset())}},{key:"localDateToRemote",value:function(e){return new Date(e.getTime()+this.getTimeOffset())}}])}();t.default=c}}]);