"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins_testing_1 = require("@unblocked-web/plugins-testing");
const agent_1 = require("@unblocked-web/agent");
const index_1 = require("../index");
let koaServer;
let pool;
const logger = plugins_testing_1.TestLogger.forTest(module);
beforeEach(plugins_testing_1.Helpers.beforeEach);
beforeAll(async () => {
    pool = new agent_1.Pool({ plugins: [index_1.default] });
    await pool.start();
    plugins_testing_1.Helpers.onClose(() => pool.close(), true);
    koaServer = await plugins_testing_1.Helpers.runKoaServer();
});
afterAll(plugins_testing_1.Helpers.afterAll, 30e3);
afterEach(plugins_testing_1.Helpers.afterEach, 30e3);
test('can use widevine', async () => {
    const agent = pool.createAgent({
        logger,
    });
    plugins_testing_1.Helpers.needsClosing.push(agent);
    const page = await agent.newPage();
    await page.goto(koaServer.baseUrl);
    const accessKey = await page
        .evaluate(`navigator.requestMediaKeySystemAccess('com.widevine.alpha', [{
      initDataTypes: ['cenc'],
      audioCapabilities: [
        {
          contentType: 'audio/mp4;codecs="mp4a.40.2"',
        },
      ],
      videoCapabilities: [
        {
          contentType: 'video/mp4;codecs="avc1.42E01E"',
        },
      ],
    },
  ]).then(x => {
    if (x.keySystem !== 'com.widevine.alpha') throw new Error('Wrong keysystem ' + x.keySystem);
    return x.createMediaKeys();
  }).then(x => {
    return x.constructor.name
  })`)
        .catch((err) => err);
    expect(accessKey).toBe('MediaKeys');
});
test('plays m3u8', async () => {
    const agent = pool.createAgent({
        logger,
    });
    plugins_testing_1.Helpers.needsClosing.push(agent);
    const page = await agent.newPage();
    await page.goto(koaServer.baseUrl);
    const isSupported = await page
        .evaluate(`MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')`)
        .catch((err) => err);
    expect(isSupported).toBe(true);
});
//# sourceMappingURL=media.test.js.map