castv2-client
Advanced tools
Comparing version 0.0.8 to 1.1.0
@@ -11,3 +11,3 @@ var util = require('util'); | ||
this.interval = null; | ||
this.pingTimer = null; | ||
this.timeout = null; | ||
@@ -39,13 +39,21 @@ this.intervalValue = DEFAULT_INTERVAL; | ||
this.once('pong', onpong); | ||
function onpong() { | ||
clearTimeout(self.timeout); | ||
self.timeout = setTimeout(ontimeout, self.intervalValue * 1000 * TIMEOUT_FACTOR); | ||
if (this.timeout) { | ||
// We already have a ping in progress. | ||
return; | ||
} | ||
function ontimeout() { | ||
this.timeout = setTimeout(function ontimeout() { | ||
self.emit('timeout'); | ||
} | ||
}, self.intervalValue * 1000 * TIMEOUT_FACTOR); | ||
this.once('pong', function onpong() { | ||
clearTimeout(self.timeout); | ||
self.timeout = null; | ||
self.pingTimer = setTimeout(function() { | ||
self.pingTimer = null; | ||
self.ping(); | ||
}, self.intervalValue * 1000); | ||
}); | ||
this.send({ type: 'PING' }); | ||
@@ -61,7 +69,2 @@ }; | ||
function oninterval() { | ||
self.ping(); | ||
} | ||
this.interval = setInterval(oninterval, this.intervalValue * 1000); | ||
this.ping(); | ||
@@ -71,6 +74,11 @@ }; | ||
HeartbeatController.prototype.stop = function() { | ||
clearInterval(this.interval); | ||
clearTimeout(this.timeout); | ||
if (this.pingTimer) { | ||
clearTimeout(this.pingTimer); | ||
} | ||
if (this.timeout) { | ||
clearTimeout(this.timeout); | ||
} | ||
this.removeAllListeners('pong'); | ||
}; | ||
module.exports = HeartbeatController; |
@@ -50,2 +50,5 @@ var util = require('util'); | ||
if(err) return callback(err); | ||
if(response.type === 'LAUNCH_ERROR') { | ||
return callback(new Error('Launch failed. Reason: ' + response.reason)); | ||
} | ||
callback(null, response.status.applications || []); | ||
@@ -52,0 +55,0 @@ }); |
@@ -22,2 +22,7 @@ var util = require('util'); | ||
self.client.on('error', onerror); | ||
function onerror(err) { | ||
self.emit('error', err); | ||
} | ||
this.client.connect(options, function() { | ||
@@ -31,3 +36,2 @@ | ||
self.client.on('error', onerror); | ||
self.client.once('close', onclose); | ||
@@ -39,6 +43,2 @@ | ||
function onerror(err) { | ||
self.emit('error', err); | ||
} | ||
function onclose() { | ||
@@ -45,0 +45,0 @@ self.heartbeat.stop(); |
{ | ||
"name": "castv2-client", | ||
"version": "0.0.8", | ||
"version": "1.1.0", | ||
"description": "A Chromecast client based on the new (CASTV2) protocol", | ||
@@ -5,0 +5,0 @@ "author": "thibauts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23390
488
2