UNPKG

xgplayer-mp4

Version:

xgplayer plugin for mp4 transform to fmp4

51 lines (50 loc) 1.36 kB
import { createClass as _createClass, classCallCheck as _classCallCheck } from "../_virtual/_rollupPluginBabelHelpers.js"; var Timer = /* @__PURE__ */ function() { function Timer2(onTick) { _classCallCheck(this, Timer2); this.onTick_ = onTick; this.cancelPending_ = null; } _createClass(Timer2, [{ key: "tickAfter", value: function tickAfter(delayInSeconds) { var _this = this; var callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null; this.stop(); var alive = true; var timeoutId = null; this.cancelPending_ = function() { window.clearTimeout(timeoutId); alive = false; }; var onTick = function onTick2() { if (alive) { _this.onTick_(); if (callback) { callback(); } } }; timeoutId = window.setTimeout(onTick, delayInSeconds * 1e3); return this; } }, { key: "tickEvery", value: function tickEvery(seconds) { var _this2 = this; this.tickAfter(seconds, function() { _this2.tickEvery(seconds); }); } }, { key: "stop", value: function stop() { if (this.cancelPending_) { this.cancelPending_(); this.cancelPending_ = null; } } }]); return Timer2; }(); export { Timer as default };