castv2-client
Advanced tools
Comparing version 0.0.2 to 0.0.4
@@ -6,2 +6,3 @@ var util = require('util'); | ||
var DEFAULT_INTERVAL = 5; // seconds | ||
var TIMEOUT_FACTOR = 3; // timeouts after 3 intervals | ||
@@ -12,2 +13,4 @@ function HeartbeatController(client, sourceId, destinationId) { | ||
this.interval = null; | ||
this.timeout = null; | ||
this.intervalValue = DEFAULT_INTERVAL; | ||
@@ -35,2 +38,15 @@ this.on('message', onmessage); | ||
HeartbeatController.prototype.ping = function() { | ||
var self = this; | ||
this.once('pong', onpong); | ||
function onpong() { | ||
clearTimeout(self.timeout); | ||
self.timeout = setTimeout(ontimeout, self.intervalValue * 1000 * TIMEOUT_FACTOR); | ||
} | ||
function ontimeout() { | ||
self.emit('timeout'); | ||
} | ||
this.send({ type: 'PING' }); | ||
@@ -41,3 +57,7 @@ }; | ||
var self = this; | ||
if(intervalValue) { | ||
this.intervalValue = intervalValue; | ||
} | ||
function oninterval() { | ||
@@ -47,3 +67,3 @@ self.ping(); | ||
this.interval = setInterval(oninterval, (intervalValue || DEFAULT_INTERVAL) * 1000); | ||
this.interval = setInterval(oninterval, this.intervalValue * 1000); | ||
this.ping(); | ||
@@ -54,4 +74,5 @@ }; | ||
clearInterval(this.interval); | ||
clearTimeout(this.timeout); | ||
}; | ||
module.exports = HeartbeatController; |
@@ -59,2 +59,6 @@ var util = require('util'); | ||
data.activeTrackIds = (typeof options.activeTrackIds !== 'undefined') | ||
? options.activeTrackIds | ||
: []; | ||
data.media = media; | ||
@@ -94,2 +98,11 @@ | ||
MediaController.prototype.seek = function(currentTime, callback) { | ||
var data = { | ||
type: 'SEEK', | ||
currentTime: currentTime | ||
}; | ||
this.sessionRequest(data, callback); | ||
}; | ||
module.exports = MediaController; |
@@ -45,2 +45,6 @@ var util = require('util'); | ||
DefaultMediaReceiver.prototype.seek = function(currentTime, callback) { | ||
this.media.seek.apply(this.media, arguments); | ||
}; | ||
module.exports = DefaultMediaReceiver; |
@@ -53,2 +53,8 @@ var util = require('util'); | ||
self.heartbeat.once('timeout', ontimeout); | ||
function ontimeout() { | ||
self.emit('error', new Error('Device timeout')); | ||
} | ||
self.connection.connect(); | ||
@@ -55,0 +61,0 @@ self.heartbeat.start(); |
{ | ||
"name": "castv2-client", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"description": "A Chromecast client based on the new (CASTV2) protocol", | ||
@@ -10,3 +10,3 @@ "author": "thibauts", | ||
"debug": "~1.0.1", | ||
"castv2": "~0.1.2" | ||
"castv2": "~0.1.4" | ||
}, | ||
@@ -13,0 +13,0 @@ "scripts": { |
@@ -16,2 +16,8 @@ castv2-client | ||
On windows, to avoid native modules dependencies, use | ||
``` bash | ||
$ npm install castv2-client --no-optional | ||
``` | ||
Examples | ||
@@ -46,5 +52,17 @@ -------- | ||
var media = { | ||
// Here you can plug an URL to any mp4, webm, mp3 or jpg file with the proper contentType. | ||
contentId: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4', | ||
contentType: 'video/mp4' | ||
contentType: 'video/mp4', | ||
streamType: 'BUFFERED', // or LIVE | ||
// Title and cover displayed while buffering | ||
metadata: { | ||
type: 0, | ||
metadataType: 0, | ||
title: "Big Buck Bunny", | ||
images: [ | ||
{ url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg' } | ||
] | ||
} | ||
}; | ||
@@ -60,2 +78,10 @@ | ||
console.log('media loaded playerState=%s', status.playerState); | ||
// Seek to 2 minutes avec 15 seconds playing. | ||
setTimeout(function() { | ||
player.seek(2*60, function(err, status) { | ||
// | ||
}); | ||
}, 15000); | ||
}); | ||
@@ -62,0 +88,0 @@ |
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
21433
472
97
Updatedcastv2@~0.1.4