"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareViewsVideos = exports.processViewsBuffer = exports.prepareViewsServers = exports.processViewersStats = void 0;
const tslib_1 = require("tslib");
const core_utils_1 = require("../../../shared/core-utils");
const server_commands_1 = require("../../../shared/server-commands");
function processViewersStats(servers) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        yield (0, core_utils_1.wait)(6000);
        for (const server of servers) {
            yield server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } });
            yield server.debug.sendCommand({ body: { command: 'process-video-viewers' } });
        }
        yield (0, server_commands_1.waitJobs)(servers);
    });
}
exports.processViewersStats = processViewersStats;
function processViewsBuffer(servers) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        for (const server of servers) {
            yield server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } });
        }
        yield (0, server_commands_1.waitJobs)(servers);
    });
}
exports.processViewsBuffer = processViewsBuffer;
function prepareViewsServers() {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const servers = yield (0, server_commands_1.createMultipleServers)(2);
        yield (0, server_commands_1.setAccessTokensToServers)(servers);
        yield (0, server_commands_1.setDefaultVideoChannel)(servers);
        yield servers[0].config.updateCustomSubConfig({
            newConfig: {
                live: {
                    enabled: true,
                    allowReplay: true,
                    transcoding: {
                        enabled: false
                    }
                }
            }
        });
        yield (0, server_commands_1.doubleFollow)(servers[0], servers[1]);
        return servers;
    });
}
exports.prepareViewsServers = prepareViewsServers;
function prepareViewsVideos(options) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const { servers } = options;
        const liveAttributes = {
            name: 'live video',
            channelId: servers[0].store.channel.id,
            privacy: 1
        };
        let ffmpegCommand;
        let live;
        let vod;
        if (options.live) {
            live = yield servers[0].live.create({ fields: liveAttributes });
            ffmpegCommand = yield servers[0].live.sendRTMPStreamInVideo({ videoId: live.uuid });
            yield (0, server_commands_1.waitUntilLivePublishedOnAllServers)(servers, live.uuid);
        }
        if (options.vod) {
            vod = yield servers[0].videos.quickUpload({ name: 'video' });
        }
        yield (0, server_commands_1.waitJobs)(servers);
        return { liveVideoId: live === null || live === void 0 ? void 0 : live.uuid, vodVideoId: vod === null || vod === void 0 ? void 0 : vod.uuid, ffmpegCommand };
    });
}
exports.prepareViewsVideos = prepareViewsVideos;
//# sourceMappingURL=views.js.map