"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractMeetingId = exports.isV2AuthToken = exports.setUrlFromAppHost = exports.setUrl = exports.CLIENT_APP_VERSION = void 0;
const buffer_1 = require("buffer");
const decodeBase64 = (data) => buffer_1.Buffer.from(data, 'base64').toString('ascii');
const configs = {
    dev: {
        apiBase: 'http://localhost:3001',
    },
    testing: {
        apiBase: 'https://api.testing.dyte.in',
    },
    testing2: {
        apiBase: 'https://api.testingv2.dyte.in',
    },
    testing3: {
        apiBase: 'https://api.testingv3.dyte.in',
    },
    testing4: {
        apiBase: 'https://api.testingv4.dyte.in',
    },
    production: {
        apiBase: 'https://api.cluster.dyte.in',
    },
    staging: {
        apiBase: 'https://api.staging.dyte.in',
    },
};
const config = configs.production;
exports.CLIENT_APP_VERSION = '0.5.0';
const setUrl = (url) => {
    config.apiBase = url;
};
exports.setUrl = setUrl;
const setUrlFromAppHost = (host) => {
    if (host.indexOf('testing.dyte.in') > 0) {
        exports.setUrl(configs.testing.apiBase);
    }
    else if (host.indexOf('testingv2.dyte.in') > 0) {
        exports.setUrl(configs.testing2.apiBase);
    }
    else if (host.indexOf('testingv3.dyte.in') > 0) {
        exports.setUrl(configs.testing3.apiBase);
    }
    if (host.indexOf('staging.dyte.in') > 0) {
        exports.setUrl(configs.staging.apiBase);
    }
    else {
        exports.setUrl(configs.production.apiBase);
    }
};
exports.setUrlFromAppHost = setUrlFromAppHost;
function isV2AuthToken(authToken) {
    try {
        const { meetingId } = JSON.parse(decodeBase64(authToken.split('.')[1]));
        if (!meetingId)
            throw Error(`Received V1 auth token ${authToken}`);
        return true;
    }
    catch (ex) {
        return false;
    }
}
exports.isV2AuthToken = isV2AuthToken;
function extractMeetingId(authToken) {
    try {
        const { meetingId } = JSON.parse(atob(authToken.split('.')[1]));
        if (!meetingId)
            throw Error(`Received V1 auth token ${authToken}`);
        return meetingId;
    }
    catch (ex) {
        return '';
    }
}
exports.extractMeetingId = extractMeetingId;
// Default to staging, to enable frontend development without setting
// local backend, set REACT_APP_STAGE = dev if neeeded
exports.default = config;
//# sourceMappingURL=config.js.map