UNPKG

@ewb/reach

Version:
44 lines (43 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReachApi = void 0; const utils_1 = require("../utils"); class ReachApi { constructor(url, opts) { this.url = url; this.opts = opts; this._socketIds = new Set(); this._onLogout = opts.logout; } get socketIds() { return [...this._socketIds]; } set onLogout(fn) { this._onLogout = fn; } headers() { return this.opts.headers || new Headers(); } options() { return this.opts.options || {}; } getCSRFHeaderToken() { if (this.opts.csrf) { const csrfCookie = (0, utils_1.getCookieValue)(this.opts.csrf.cookie); if (csrfCookie) return ['X-CSRF-Token', csrfCookie]; } return null; } logout(response) { if (this._onLogout) this._onLogout(response); } addSocket(id) { this._socketIds.add(id); } deleteSocket(id) { this._socketIds.delete(id); } } exports.ReachApi = ReachApi;