node-red-contrib-lgtv-with-fullscreen
Version:
Node-RED Nodes to control LG webOS Smart TVs, with browser fullscreen
27 lines (22 loc) • 768 B
JavaScript
module.exports = function (RED) {
function LgtvButtonNode(n) {
RED.nodes.createNode(this, n);
const node = this;
this.tv = n.tv;
this.tvConn = RED.nodes.getNode(this.tv);
if (this.tvConn) {
this.tvConn.register(node);
this.on('close', done => {
node.tvConn.deregister(node, done);
});
node.on('input', msg => {
if (msg.payload && node.tvConn.buttonSocket) {
node.tvConn.buttonSocket.send('button', {name: (String(msg.payload)).toUpperCase()});
}
});
} else {
this.error('No TV Configuration');
}
}
RED.nodes.registerType('lgtv-button', LgtvButtonNode);
};