UNPKG

@bbc/sofie-server-core-integration

Version:
60 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CorePinger = void 0; class CorePinger { emitError; doPing; _pingTimeout = null; _connected = false; _destroyed = false; constructor(emitError, doPing) { this.emitError = emitError; this.doPing = doPing; } setConnectedAndTriggerPing(connected) { this._connected = connected; this.triggerPing(); } destroy() { this._destroyed = true; if (this._pingTimeout) { clearTimeout(this._pingTimeout); this._pingTimeout = null; } } triggerPing() { if (this._destroyed) return; if (!this._pingTimeout) { this._pingTimeout = setTimeout(() => { this._pingTimeout = null; this._ping(); }, 90 * 1000); } } triggerDelayPing() { // delay the ping: if (this._pingTimeout) { clearTimeout(this._pingTimeout); this._pingTimeout = null; } this.triggerPing(); } _ping() { if (this._destroyed) return; try { if (this._connected) { this.doPing().catch((e) => this.emitError('_ping' + e)); } } catch (e) { this.emitError('_ping2 ' + e); } if (this._connected) { this.triggerPing(); } } } exports.CorePinger = CorePinger; //# sourceMappingURL=ping.js.map