import * as pjlink from 'pjlink'

import { IntegrationAPI } from "../../IntegrationApi";

module.exports = (Api: IntegrationAPI) => {


    Api.registerConnectionValidator('pjlink', (validatorAPI) => {
        var ip = validatorAPI.properties.ip;
        var port = validatorAPI.properties.port;
        var password = validatorAPI.properties.password;

        var beamer = new pjlink(ip, port, password);
        beamer.getClass((err, classNumber) => {
            if (!err)
                validatorAPI.setInstance(beamer)


            validatorAPI.callback(err == undefined, err == undefined ? null : 'Unable to connect to projector: ' + err)
        });
    })
}