Skip to content

Commit

Permalink
Reconnect on client timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Krüger authored and Stefan Krüger committed Mar 12, 2017
1 parent 6a67f9c commit dc5182d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions harmony/harmony-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,33 @@ module.exports = function (RED) {
var node = this

node.ip = n.ip
createClient(node)
}
RED.nodes.registerType('harmony-server', HarmonyServerNode)

harmonyClient(node.ip).then(function (harmony) {
function createClient (node) {
var harmony = node.harmony
var ip = node.ip
if (harmony && typeof harmony.end !== 'undefined') {
try {
harmony.end()
} catch (e) { }
}
harmonyClient(ip).then(function (harmony) {
node.harmony = harmony
!(function keepAlive () {
harmony.request('getCurrentActivity').timeout(50000).then(function (response) {
setTimeout(keepAlive, 50000)
}).catch(function (e) {
console.log('Disconnected from Harmony Hub: ' + e)
createClient(node)
})
}()) // jshint ignore:line
}).catch(function (err) {
console.log('error: ' + err)
if (err) throw err
})
}
RED.nodes.registerType('harmony-server', HarmonyServerNode)

RED.httpAdmin.get('/harmony/server', function (req, res, next) {
var discover = new HarmonyHubDiscover(61991)
Expand Down

0 comments on commit dc5182d

Please sign in to comment.