Skip to content
Snippets Groups Projects
Select Git revision
  • 781c375404aa22358587f698245099617e4e0365
  • main default
  • 7.2.0
3 results

main.js

Blame
  • main.js 5.16 KiB
    const {InstanceBase, Regex, runEntrypoint, InstanceStatus} = require('@companion-module/base')
    const UpgradeScripts = require('./upgrades')
    const UpdateActions = require('./actions')
    const UpdateFeedbacks = require('./feedbacks')
    const UpdateVariableDefinitions = require('./variables')
    const WebSocket = require('ws')
    const ProjectUpdate = require("./receive/project_update");
    const Project = require("./project");
    const PadNameUpdate = require("./receive/pad_name_update");
    const PadStatusUpdate = require("./receive/pad_status_update");
    const uuid = require('uuid');
    
    class ModuleInstance extends InstanceBase {
        isInitialized = false
        // language=RegExp
        wsRegex = '^wss?:\\/\\/([\\da-z\\.-]+)(:\\d{1,5})?(?:\\/(.*))?$'
    
        messageHandlers = {
            'project-current': new ProjectUpdate(),
            'pad-name-changed': new PadNameUpdate(),
            'pad-status-changed': new PadStatusUpdate()
        };
    
        currentProject = new Project({});
    
        constructor(internal) {
            super(internal)
        }
    
        async init(config) {
            this.config = config
    
            this.initWebSocket()
            this.isInitialized = true
    
            this.updateActions() // export actions
            this.updateFeedbacks() // export feedbacks
            this.updateVariableDefinitions() // export variable definitions
        }
    
        // When module gets deleted
        async destroy() {
            this.isInitialized = false
    
            if (this.ws) {
                this.ws.close(1000)
                delete this.ws
            }
        }
    
        async configUpdated(config) {
            this.config = config
            this.initWebSocket()
        }
    
        // Return config fields for web config
        getConfigFields() {
            return [
                {
                    type: 'textinput',
                    id: 'host',
                    label: 'PlayWall IP',
                    width: 8,
                    regex: Regex.IP,
                },
                {
                    type: 'textinput',
                    id: 'port',
                    label: 'PlayWall Port',
                    width: 4,