"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const core_utils_1 = require("../../../../shared/core-utils");
const server_commands_1 = require("../../../../shared/server-commands");
describe('Test live RTMPS', function () {
    let server;
    let rtmpUrl;
    let rtmpsUrl;
    function createLiveWrapper() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const liveAttributes = {
                name: 'live',
                channelId: server.store.channel.id,
                privacy: 1,
                saveReplay: false
            };
            const { uuid } = yield server.live.create({ fields: liveAttributes });
            const live = yield server.live.get({ videoId: uuid });
            const video = yield server.videos.get({ id: uuid });
            return Object.assign(video, live);
        });
    }
    before(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(120000);
            server = yield (0, server_commands_1.createSingleServer)(1);
            yield (0, server_commands_1.setAccessTokensToServers)([server]);
            yield (0, server_commands_1.setDefaultVideoChannel)([server]);
            yield server.config.updateCustomSubConfig({
                newConfig: {
                    live: {
                        enabled: true,
                        allowReplay: true,
                        transcoding: {
                            enabled: false
                        }
                    }
                }
            });
            rtmpUrl = 'rtmp://' + server.hostname + ':' + server.rtmpPort + '/live';
            rtmpsUrl = 'rtmps://' + server.hostname + ':' + server.rtmpsPort + '/live';
        });
    });
    it('Should enable RTMPS endpoint only', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(240000);
            yield server.kill();
            yield server.run({
                live: {
                    rtmp: {
                        enabled: false
                    },
                    rtmps: {
                        enabled: true,
                        port: server.rtmpsPort,
                        key_file: (0, core_utils_1.buildAbsoluteFixturePath)('rtmps.key'),
                        cert_file: (0, core_utils_1.buildAbsoluteFixturePath)('rtmps.cert')
                    }
                }
            });
            {
                const liveVideo = yield createLiveWrapper();
                (0, chai_1.expect)(liveVideo.rtmpUrl).to.not.exist;
                (0, chai_1.expect)(liveVideo.rtmpsUrl).to.equal(rtmpsUrl);
                const command = (0, server_commands_1.sendRTMPStream)({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey });
                yield (0, server_commands_1.testFfmpegStreamError)(command, true);
            }
            {
                const liveVideo = yield createLiveWrapper();
                const command = (0, server_commands_1.sendRTMPStream)({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey });
                yield (0, server_commands_1.waitUntilLivePublishedOnAllServers)([server], liveVideo.uuid);
                yield (0, server_commands_1.stopFfmpeg)(command);
            }
        });
    });
    it('Should enable both RTMP and RTMPS', function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.timeout(240000);
            yield server.kill();
            yield server.run({
                live: {
                    rtmp: {
                        enabled: true,
                        port: server.rtmpPort
                    },
                    rtmps: {
                        enabled: true,
                        port: server.rtmpsPort,
                        key_file: (0, core_utils_1.buildAbsoluteFixturePath)('rtmps.key'),
                        cert_file: (0, core_utils_1.buildAbsoluteFixturePath)('rtmps.cert')
                    }
                }
            });
            {
                const liveVideo = yield createLiveWrapper();
                (0, chai_1.expect)(liveVideo.rtmpUrl).to.equal(rtmpUrl);
                (0, chai_1.expect)(liveVideo.rtmpsUrl).to.equal(rtmpsUrl);
                const command = (0, server_commands_1.sendRTMPStream)({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey });
                yield (0, server_commands_1.waitUntilLivePublishedOnAllServers)([server], liveVideo.uuid);
                yield (0, server_commands_1.stopFfmpeg)(command);
            }
            {
                const liveVideo = yield createLiveWrapper();
                const command = (0, server_commands_1.sendRTMPStream)({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey });
                yield (0, server_commands_1.waitUntilLivePublishedOnAllServers)([server], liveVideo.uuid);
                yield (0, server_commands_1.stopFfmpeg)(command);
            }
        });
    });
    after(function () {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, server_commands_1.cleanupTests)([server]);
        });
    });
});
//# sourceMappingURL=live-rtmps.js.map