UNPKG

blackmagic-atem-nodered

Version:
179 lines (159 loc) 6.13 kB
const commandList = require("./commandList.js"); module.exports = { object: function() { return { get: "PrgI", set: "CPgI", cmd: "programInput", data: {}, close() { this.data = {}; }, messageCallbacks: [], initializeData(data, flag, commands, msgCallbacks) { var command = {"payload":{"data":{}}}; this.processData(data, flag, command, commands, false); messageCallbacks = msgCallbacks; }, processData(data, flag, command, commands, sendTallyUpdates=true) { command.payload.cmd = "programInput"; command.payload.data.ME = data[0]; command.payload.data.inputNumber = data.readUInt16BE(2); command.payload.data.videoSource = commands.inputProperty.findInput(data.readUInt16BE(2)); //Add the transition position params if they don't exist if(this.data[command.payload.data.ME] === undefined || this.data[command.payload.data.ME] === null) { command.payload.data.inTransition = false; command.payload.data.framesRemaining = false; command.payload.data.position = false; } //Send the input properties of the updated inputs if(sendTallyUpdates && flag==commandList.flags.initializing) { if(this.messageCallbacks !== undefined) { for(var i = 0; i < messageCallbacks.length; i++) { var msg = { "topic": "command", "payload": { "cmd": this.cmd, "data": this.data } } messageCallbacks[i](msg); } } // for(var i = 0; i < messageCallbacks.length; i++) { // var msg = { // "topic": "command", // "payload": { // "cmd": commands.inputProperty.cmd, // "data": commands.inputProperty.data, // } // } // messageCallbacks[i](msg); // } } this.data[command.payload.data.ME] = command.payload.data; command.payload.data = this.data; if(sendTallyUpdates === true) {commands.tally.updateTallys(commands);} return true; }, sendData(command, commands) { var error = null; var msg = { "direction": "node", "name": this.set, "command": { "payload": { "cmd": this.cmd, "data": "The data was not filled" } } } //If the data is null return the value if(command.payload.data == undefined || command.payload.data == null) {error="The data parameter was null";} else { //Sending a empty ME will return all MEs if(command.payload.data.ME == undefined || command.payload.data.ME == null){ msg.direction = "node"; msg.command.payload.data = this.data; } //Else if the video source is empty return the MEs current video source else if(command.payload.data.videoSource == undefined || command.payload.data.videoSource == null) { msg.direction = "node"; msg.command.payload.data = this.data[command.payload.data.ME]; } //Else set the video source on the ME else { //Find the searcher for the video source videoSource = null; if(command.payload.data.videoSource.id == undefined || command.payload.data.videoSource.id == null) { if(command.payload.data.videoSource.longName == undefined || command.payload.data.videoSource.longName == null) { if(command.payload.data.videoSource.shortName == undefined || command.payload.data.videoSource.shortName == null) { } else {videoSource = command.payload.data.videoSource.shortName; } } else {videoSource = command.payload.data.videoSource.longName;} } else {videoSource = command.payload.data.videoSource.id;} if(videoSource == null){error = "A video source identifier is required (id, shortName, longName)";} else { videoSource = commands.inputProperty.findInput(videoSource); if(videoSource == null) {error = "That video source was not found";} else { if(this.data[command.payload.data.ME] == null) {error = "That ME was not found";} else { //Generate the packet var packet = Buffer.alloc(4).fill(0); packet[0] = command.payload.data.ME; packet.writeInt16BE(videoSource.id, 2); msg.direction = "server"; msg.command.packet = packet; //Check if the input is currently on this ME, if it is don't resend it if(this.data[command.payload.data.ME].videoSource.id == videoSource.id) { var msg = { "direction": "node", "command": { "payload": { "cmd": this.cmd, "data": this.data } } } return msg; } } } } } } if(error != null) { var msg = { "direction": "node", "command": { "payload": { "cmd": this.cmd, "data": error } } } } return msg; }, updateTransitionPosition(ME, inTransition, framesRemaining, position) { if(this.data[ME] !== undefined) { this.data[ME].inTransition = inTransition; this.data[ME].framesRemaining = framesRemaining; this.data[ME].position = position; } }, //What todo once we are connected afterInit(commands) { //Update the video source for(var i in this.data) { this.data[i].videoSource = commands.inputProperty.findInput(this.data[i].inputNumber); } return { "cmd": this.cmd, "data": this.data } } }} }