"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionKeepAlive = void 0;
var SessionKeepAlive = /** @class */ (function () {
    function SessionKeepAlive(getSession, client, onSessionExpired, check) {
        var _this = this;
        this.check = check;
        this.getSession = getSession;
        this.client = client;
        if (this.check) {
            this.client.getServerSessionTimeout(this.getSession()).then(function (tm) {
                _this.interval = tm / 5 * 1000; //Ping server 5 times each period. Timeout is returned in seconds.
                _this.timeoutID = setTimeout(_this.tick.bind(_this), _this.interval);
            });
        }
    }
    SessionKeepAlive.prototype.dispose = function () {
        clearTimeout(this.timeoutID);
    };
    SessionKeepAlive.prototype.tick = function () {
        var _this = this;
        this.client.getServerSessionTimeout(this.getSession()).then(function (tm) {
            _this.timeoutID = setTimeout(_this.tick.bind(_this), _this.interval);
        });
    };
    SessionKeepAlive.prototype.lastTry = function () {
        if (this.check) {
            return this.client.getServerSessionTimeout(this.getSession());
        }
        else {
            return Promise.resolve(-1);
        }
    };
    return SessionKeepAlive;
}());
exports.SessionKeepAlive = SessionKeepAlive;
//# sourceMappingURL=session-keep-alive.js.map