node-red-contrib-lgtv-with-fullscreen
Version:
Node-RED Nodes to control LG webOS Smart TVs, with browser fullscreen
46 lines (38 loc) • 1.38 kB
JavaScript
module.exports = function (RED) {
function LgtvMouseNode(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 (!node.tvConn.buttonSocket) {
return;
}
switch (msg.topic) {
case 'drag':
if (msg.payload) {
node.tvConn.buttonSocket.send('drag', {dx: msg.payload.dx, dy: msg.payload.dy, drag: 1});
}
break;
case 'move':
if (msg.payload) {
node.tvConn.buttonSocket.send('move', {dx: msg.payload.dx, dy: msg.payload.dy});
}
break;
case 'click':
node.tvConn.buttonSocket.send('click');
break;
default:
}
});
} else {
this.error('No TV Configuration');
}
}
RED.nodes.registerType('lgtv-mouse', LgtvMouseNode);
};