"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unregisteVirturalCamera = exports.registeVirturalCamera = exports.changeResolutionOfVirturalCamera = exports.pushDataToVirturalCamera = exports.createVirturalCamera = exports.CameraType = void 0;
const addon_1 = require("./addon");
const sudo_prompt_1 = require("@vscode/sudo-prompt");
const path_1 = require("path");
const color_1 = require("@tosee/color");
var CameraType;
(function (CameraType) {
    CameraType[CameraType["RGBA"] = 0] = "RGBA";
    CameraType[CameraType["I420"] = 1] = "I420";
})(CameraType = exports.CameraType || (exports.CameraType = {}));
/**
 * 创建虚拟摄像头
 * @param type 虚拟摄像头输入图片的类型
 * @param width 虚拟摄像头的宽
 * @param height 虚拟摄像头的高
 * @returns
 */
function createVirturalCamera(type, width, height) {
    if (process.platform === 'win32') {
        return addon_1.Addon.createVirturalCamera(type, width, height);
    }
    else {
        console.log((0, color_1.red) `virtualcamera is only support windows now`);
    }
}
exports.createVirturalCamera = createVirturalCamera;
/**
 * 推送数据到虚拟摄像头
 * @param data 输入图片的buffer
 * @param width 输入图片的宽
 * @param height 输入图片的高
 * @returns
 */
function pushDataToVirturalCamera(data, width, height) {
    if (process.platform === 'win32') {
        return addon_1.Addon.pushDataToVirturalCamera(data, width, height);
    }
    else {
        console.log((0, color_1.red) `virtualcamera is only support windows now`);
    }
}
exports.pushDataToVirturalCamera = pushDataToVirturalCamera;
/**
 * 重新设置虚拟摄像头的分辨率
 * @param width 虚拟摄像头的宽
 * @param height 虚拟摄像头的高
 * @returns
 */
function changeResolutionOfVirturalCamera(width, height) {
    if (process.platform === 'win32') {
        return addon_1.Addon.changeResolutionOfVirturalCamera(width, height);
    }
    else {
        console.log((0, color_1.red) `virtualcamera is only support windows now`);
    }
}
exports.changeResolutionOfVirturalCamera = changeResolutionOfVirturalCamera;
/**
 * 注册虚拟摄像头
 * @returns
 */
async function registeVirturalCamera() {
    if (process.platform === 'win32') {
        const x86 = (0, path_1.relative)('.', (0, path_1.resolve)(__dirname, '../libraries/x86/obs-virtualsource.dll'));
        const x64 = (0, path_1.relative)('.', (0, path_1.resolve)(__dirname, '../libraries/x64/obs-virtualsource.dll'));
        return new Promise((resolve, reject) => {
            (0, sudo_prompt_1.exec)(`regsvr32 /u ${x86} /s
        regsvr32 /u ${x64} /s
        regsvr32 ${x86} /s
        regsvr32 ${x64} /s`, {
                name: "Registe Virtual Camera",
            }, (err) => {
                if (err) {
                    reject(err);
                }
                else {
                    resolve();
                }
            });
        });
    }
    else {
        console.log((0, color_1.red) `virtualcamera is only support windows now`);
    }
}
exports.registeVirturalCamera = registeVirturalCamera;
/**
 * 卸载虚拟摄像头
 * @returns
 */
async function unregisteVirturalCamera() {
    if (process.platform === 'win32') {
        const x86 = (0, path_1.relative)('.', (0, path_1.resolve)(__dirname, '../libraries/x86/obs-virtualsource.dll'));
        const x64 = (0, path_1.relative)('.', (0, path_1.resolve)(__dirname, '../libraries/x64/obs-virtualsource.dll'));
        return new Promise((resolve, reject) => {
            (0, sudo_prompt_1.exec)(`regsvr32 /u ${x86} /s
        regsvr32 /u ${x64} /s`, {
                name: "Uninstall Virtual Camera",
            }, (err) => {
                if (err) {
                    reject(err);
                }
                else {
                    resolve();
                }
            });
        });
    }
    else {
        console.log((0, color_1.red) `virtualcamera is only support windows now`);
    }
}
exports.unregisteVirturalCamera = unregisteVirturalCamera;
//# sourceMappingURL=index.js.map