@atlaskit/editor-plugin-metrics
Version:
Metrics plugin for @atlaskit/editor-core
35 lines (34 loc) • 1.44 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ActiveSessionTimer = void 0;
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var ACTIVE_SESSION_IDLE_TIME = 5000;
var ActiveSessionTimer = exports.ActiveSessionTimer = /*#__PURE__*/(0, _createClass2.default)(function ActiveSessionTimer(api) {
var _this = this;
(0, _classCallCheck2.default)(this, ActiveSessionTimer);
(0, _defineProperty2.default)(this, "startTimer", function () {
if (_this.timerId) {
clearTimeout(_this.timerId);
}
_this.timerId = window.setTimeout(function () {
if (_this.api) {
var _this$api$metrics;
_this.api.core.actions.execute((_this$api$metrics = _this.api.metrics) === null || _this$api$metrics === void 0 ? void 0 : _this$api$metrics.commands.stopActiveSession());
}
_this.cleanupTimer();
}, ACTIVE_SESSION_IDLE_TIME);
});
(0, _defineProperty2.default)(this, "cleanupTimer", function () {
if (_this.timerId) {
clearTimeout(_this.timerId);
_this.timerId = null;
}
});
this.timerId = null;
this.api = api;
});