From fe7785f00353d0afacf2ce61b6de9fc24a9fbd69 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Thu, 25 Jun 2015 16:35:26 +0900 Subject: [PATCH] Keep the same channel for each device. This should make it easier to keep the client side up to date after device death (because there's no need to update it at all). --- lib/units/device/plugins/solo.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/units/device/plugins/solo.js b/lib/units/device/plugins/solo.js index d38ec108..1f5eeae4 100644 --- a/lib/units/device/plugins/solo.js +++ b/lib/units/device/plugins/solo.js @@ -1,3 +1,5 @@ +var crypto = require('crypto') + var syrup = require('stf-syrup') var logger = require('../../../util/logger') @@ -11,7 +13,16 @@ module.exports = syrup.serial() .dependency(require('./identity')) .define(function(options, sub, push, router, identity) { var log = logger.createLogger('device:plugins:solo') - var channel = wireutil.makePrivateChannel() + + // The channel should keep the same value between restarts, so that + // having the client side up to date all the time is not horribly painful. + function makeChannelId() { + var hash = crypto.createHash('sha1') + hash.update(options.serial) + return hash.digest('base64') + } + + var channel = makeChannelId() log.info('Subscribing to permanent channel "%s"', channel) sub.subscribe(channel)