"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jsonwebtoken_1 = require("jsonwebtoken");
const Config_1 = require("../lib/Config");
const REST_1 = require("./REST");
let matrixToken;
let matrixTokenExpires = 0;
class Matrix extends REST_1.default {
    constructor() {
        super(`${Config_1.default.matrix.baseUrl}/api`);
    }
    get additionalHeaders() {
        if (matrixTokenExpires < Date.now()) {
            matrixToken = (0, jsonwebtoken_1.sign)({ matrixId: 'server/rtsp-proxy' }, Config_1.default.jwt.secret, {
                expiresIn: '2h',
            });
            matrixTokenExpires = Date.now() + 7000000; //2h
        }
        return { Authorization: `Bearer ${matrixToken}`, 'X-Matrix-App': 'rtsp-proxy' };
    }
    get additionalQueries() {
        return {};
    }
}
exports.default = Matrix;
