forked from thibauts/node-castv2-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request thibauts#65 from angelnu/addTests
Add tests
- Loading branch information
Showing
7 changed files
with
325 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules | ||
test* | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
var MYPATH = "../index"; //castv2-client in production | ||
|
||
var Client = require(MYPATH).Client; | ||
var DefaultMediaReceiver = require(MYPATH).DefaultMediaReceiver; | ||
var scanner = require("./lib/scanner"); | ||
|
||
|
||
function ondeviceup(host, callback) { | ||
|
||
var client = new Client(); | ||
|
||
client.connect(host, function() { | ||
console.log('connected, launching app ...'); | ||
|
||
client.launch(DefaultMediaReceiver, function(err, player) { | ||
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', | ||
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' } | ||
] | ||
} | ||
}; | ||
|
||
player.on('status', function(status) { | ||
console.log('status broadcast playerState=%s', status.playerState); | ||
}); | ||
|
||
console.log('app "%s" launched, loading media %s ...', player.session.displayName, media.contentId); | ||
|
||
player.load(media, { autoplay: true }, function(err, status) { | ||
console.log('media loaded playerState=%s', status.playerState); | ||
|
||
// Seek to 2 minutes after 5 seconds playing. | ||
setTimeout(function() { | ||
console.log("seeking"); | ||
player.seek(2*60, function(err, status) { | ||
// Stop after 2 seconds playing | ||
setTimeout(function() { | ||
console.log("Stopping"); | ||
player.stop(function() { | ||
console.log("Done!"); | ||
callback(0); //Done | ||
}); | ||
}, 2000); | ||
|
||
}); | ||
}, 5000); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
client.on('error', function(err) { | ||
console.log('Error: %s', err.message); | ||
client.close(); | ||
callback(err); //Error | ||
}); | ||
|
||
} | ||
|
||
function findAndConnect(callback) { | ||
scanner(function(ip, name, port){ | ||
ondeviceup(ip, callback); | ||
}); | ||
} | ||
|
||
//module for testcase | ||
module.exports = findAndConnect; | ||
|
||
//main | ||
var main = function () { | ||
findAndConnect(function(rc){ | ||
process.exit(rc); | ||
}); | ||
} | ||
if (require.main === module) { | ||
main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
var MYPATH = "../index"; //castv2-client in production | ||
|
||
var Client = require(MYPATH).Client; | ||
var DefaultMediaReceiver = require(MYPATH).DefaultMediaReceiver; | ||
var scanner = require("./lib/scanner"); | ||
|
||
var util = require("util"); | ||
|
||
function connectToDevice(host, callback) { | ||
|
||
var client = new Client(); | ||
|
||
client.connect(host, function() { | ||
console.log('connected, launching app ...'); | ||
|
||
client.launch(DefaultMediaReceiver, function(err, player) { | ||
|
||
var mediaList = [ | ||
{ | ||
autoplay : true, | ||
preloadTime : 3, | ||
startTime : 1, | ||
activeTrackIds : [], | ||
playbackDuration: 2, | ||
media: { | ||
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/BigBuckBunnyAudio.mp4", | ||
contentType: "audio/mpeg", | ||
streamType: 'BUFFERED' | ||
} | ||
}, | ||
{ | ||
autoplay : true, | ||
preloadTime : 3, | ||
startTime : 2, | ||
activeTrackIds : [], | ||
playbackDuration: 2, | ||
media: { | ||
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/ElephantsDreamAudio.mp4", | ||
contentType: "audio/mpeg", | ||
streamType: 'BUFFERED' | ||
} | ||
}, | ||
{ | ||
autoplay : true, | ||
preloadTime : 3, | ||
startTime : 3, | ||
activeTrackIds : [], | ||
playbackDuration: 2, | ||
media: { | ||
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/ForBiggerBlazesAudio.mp4", | ||
contentType: "audio/mpeg", | ||
streamType: 'BUFFERED' | ||
} | ||
} | ||
]; | ||
|
||
console.log('app "%s" launched, loading medias...', player.session.displayName); | ||
|
||
player.on('status', gotStatus); | ||
|
||
//Done re-ordering? | ||
var isDone = false; | ||
|
||
function gotStatus(status) { | ||
console.log('status broadcast = %s', util.inspect(status)," "); | ||
if ( | ||
isDone, | ||
status.idleReason == "FINISHED" && | ||
status.loadingItemId === undefined) | ||
{ | ||
console.log("Done!"); | ||
callback(0); | ||
} | ||
} | ||
|
||
// loads multiple items | ||
player.queueLoad( | ||
mediaList, | ||
{ | ||
startIndex:1, | ||
repeatMode: "REPEAT_OFF" | ||
}, | ||
function(err, status) { | ||
console.log("Loaded QUEUE"); | ||
if (err) { | ||
console.log(util.inspect(err)); | ||
callback(err); //Error | ||
return; | ||
}; | ||
console.log(util.inspect(status)); | ||
player.queueInsert( | ||
[ | ||
{ | ||
autoplay : true, | ||
preloadTime : 4, | ||
startTime : 8, | ||
activeTrackIds : [], | ||
playbackDuration: 2, | ||
media: { | ||
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/ForBiggerEscapesAudio.mp4", | ||
contentType: "audio/mpeg", | ||
streamType: 'BUFFERED', | ||
metadata: { | ||
metadataType: 3, | ||
title: "Original title" | ||
} | ||
} | ||
} | ||
], | ||
function(err, status) { | ||
console.log("Inserted in QUEUE"); | ||
if (err) { | ||
console.log(util.inspect(err)); | ||
callback(err); //Error | ||
return; | ||
}; | ||
console.log(util.inspect(status)); | ||
//Get status before we modify the title bellow | ||
player.getStatus(function (err, status){ | ||
gotStatus(status); | ||
}); | ||
player.queueRemove([2],{currentItemId:0}, function(err, status) { | ||
console.log("Removed from QUEUE"); | ||
if (err) { | ||
console.log(util.inspect(err)); | ||
callback(err); //Error | ||
return; | ||
}; | ||
console.log(util.inspect(status)); | ||
player.queueUpdate( | ||
[ | ||
{ | ||
itemId: 4, | ||
autoplay : true, | ||
preloadTime : 4, | ||
startTime : 4, | ||
activeTrackIds : [], | ||
playbackDuration: 2, | ||
media: { | ||
contentId: "http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/ForBiggerEscapesAudio.mp4", | ||
contentType: "audio/mpeg", | ||
streamType: 'BUFFERED', | ||
metadata: { | ||
metadataType: 3, | ||
title: "Modified title" | ||
} | ||
} | ||
} | ||
], | ||
{currentItemId: 4}, | ||
function(err, status) { | ||
console.log("Updated Item"); | ||
if (err) { | ||
console.log(util.inspect(err)); | ||
callback(err); //Error | ||
return; | ||
}; | ||
console.log(util.inspect(status)); | ||
player.queueReorder([4,3,1], {currentItemId:4}, function(err, status) { | ||
console.log("Reordered QUEUE"); | ||
if (err) { | ||
console.log(util.inspect(err)); | ||
callback(err); | ||
return; | ||
}; | ||
console.log(util.inspect(status)); | ||
//Get status - check that the title from itemId=4 has been modified | ||
player.getStatus(function (err, status){ | ||
gotStatus(status); | ||
isDone = true; | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
client.on('error', function(err) { | ||
console.log('Error: %s', err.message); | ||
client.close(); | ||
callback(err); //Error | ||
}); | ||
|
||
} | ||
|
||
function findAndConnect(callback) { | ||
scanner(function(ip, name, port){ | ||
connectToDevice(ip, callback); | ||
}); | ||
} | ||
|
||
//module for testcase | ||
module.exports = findAndConnect; | ||
|
||
//main | ||
var main = function () { | ||
findAndConnect(function(rc){ | ||
process.exit(rc); | ||
}); | ||
} | ||
if (require.main === module) { | ||
main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var basicExample = require("../examples/basic"); | ||
describe('Basic', function() { | ||
it('base functions', function(done) { | ||
this.timeout(60000); //It usually takes 10 seconds | ||
basicExample(done); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var queueExample = require("../examples/queue"); | ||
describe('Queue', function() { | ||
it('dynamic playlist changes', function(done) { | ||
this.timeout(60000); //It usually takes 25 seconds | ||
queueExample(done); | ||
}); | ||
}); |