From 8c781a4a8d262ef6440d15b9db97cc51186e1e11 Mon Sep 17 00:00:00 2001 From: Josh Hodgson Date: Thu, 19 Jan 2017 23:33:07 +0000 Subject: [PATCH 1/2] Enable subscription WebOS supports the "Subscribe" type. Everything seems to work except for the fact that it would only pass the first response to the callback. I can't see any breaks happening from this as each cmd that gets run (that isn't a subscribe) only gets one response anyway --- lib/remote.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/remote.js b/lib/remote.js index 18b4285..e61e67a 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -199,7 +199,7 @@ Remote.prototype.cmd = function(prefix, type, uri, payload, callback) { try { if( typeof callback === 'function' ) { - this.once(msg.id, function(message) { + this.on(msg.id, function(message) { //console.log('send_command.onMessage', msg.id, message); callback(null, message.payload); }); @@ -414,4 +414,4 @@ Remote.prototype.turnOff = function( callback ) { this.cmd("", "request", "ssap://system/turnOff", null, callback); } -module.exports = Remote; \ No newline at end of file +module.exports = Remote; From 969e235a6c12a50fb85ae32b7effab7dba2d8b40 Mon Sep 17 00:00:00 2001 From: Josh Hodgson Date: Fri, 20 Jan 2017 18:22:08 +0000 Subject: [PATCH 2/2] Performance fix --- lib/remote.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/remote.js b/lib/remote.js index e61e67a..d61d464 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -199,10 +199,17 @@ Remote.prototype.cmd = function(prefix, type, uri, payload, callback) { try { if( typeof callback === 'function' ) { + if(type=='subscribe'){ this.on(msg.id, function(message) { //console.log('send_command.onMessage', msg.id, message); callback(null, message.payload); }); + }else{ + this.once(msg.id, function(message) { + //console.log('send_command.onMessage', msg.id, message); + callback(null, message.payload); + }); + } } this.ws.send(JSON.stringify(msg));