Fix direct device control not extending owner timeout.

This commit is contained in:
Simo Kinnunen
2014-06-02 21:03:21 +09:00
parent 9239ee57b4
commit 3ea41c1a4e
4 changed files with 31 additions and 13 deletions

View File

@@ -8,13 +8,27 @@ function ChannelManager() {
util.inherits(ChannelManager, events.EventEmitter)
ChannelManager.prototype.register = function(id, timeout) {
this.channels[id] = {
timeout: timeout
ChannelManager.prototype.register = function(id, options) {
var channel = this.channels[id] = {
timeout: options.timeout
, alias: options.alias
, lastActivity: Date.now()
, timer: null
}
if (channel.alias) {
// The alias can only be active for a single channel at a time
if (this.channels[channel.alias]) {
throw new Error(util.format(
'Cannot create alias "%s" for "%s"; the channel already exists'
, channel.alias
, id
))
}
this.channels[channel.alias] = channel
}
// Set timer with initial check
this.check(id)
}
@@ -24,6 +38,9 @@ ChannelManager.prototype.unregister = function(id) {
if (channel) {
delete this.channels[id]
clearTimeout(channel.timer)
if (channel.alias) {
delete this.channels[channel.alias]
}
}
}