chromecast-api
Advanced tools
Comparing version 0.2.6 to 0.3.1
/* global module */ | ||
module.exports = require('./lib/Browser.js') | ||
module.exports = require('./lib/client.js') |
{ | ||
"name": "chromecast-api", | ||
"version": "0.2.6", | ||
"description": "Chromecast streaming module all in JS", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alxhotel/chromecast-api.git" | ||
}, | ||
"keywords": [ | ||
"chromecast", | ||
"googlecast", | ||
"stream", | ||
"streaming", | ||
"torrentv" | ||
], | ||
"author": { | ||
"name": "Alex", | ||
"email": "alxmorais8@msn.com" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Carlos Guerrero", | ||
"email": "guerrerocarlos@gmail.com" | ||
} | ||
], | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/alxhotel/chromecast-api/issues" | ||
}, | ||
"homepage": "https://github.com/alxhotel/chromecast-api", | ||
"dependencies": { | ||
"castv2-client": "1.2.0", | ||
"debug": "4.1.1", | ||
"multicast-dns": "7.2.0", | ||
"node-ssdp": "4.0.0", | ||
"inherits": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"standard": "latest" | ||
} | ||
"name": "chromecast-api", | ||
"version": "0.3.1", | ||
"description": "Chromecast streaming module all in JS", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alxhotel/chromecast-api.git" | ||
}, | ||
"keywords": [ | ||
"chromecast", | ||
"googlecast", | ||
"cast", | ||
"media", | ||
"device", | ||
"stream", | ||
"streaming", | ||
"torrent" | ||
], | ||
"author": { | ||
"name": "Alex", | ||
"email": "alxmorais8@msn.com" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/alxhotel/chromecast-api/issues" | ||
}, | ||
"homepage": "https://github.com/alxhotel/chromecast-api", | ||
"dependencies": { | ||
"castv2-client": "1.2.0", | ||
"debug": "^4.1.1", | ||
"dns-txt": "^2.0.2", | ||
"mime": "^2.3.1", | ||
"multicast-dns": "^7.2.0", | ||
"node-ssdp": "^4.0.0", | ||
"xml2js": "^0.4.23", | ||
"youtube-remote": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"standard": "latest" | ||
} | ||
} |
206
README.md
@@ -5,9 +5,8 @@ chromecast-api | ||
[![NPM Version](https://img.shields.io/npm/v/chromecast-api.svg)](https://www.npmjs.com/package/chromecast-api) | ||
[![Travis Build](https://travis-ci.org/alxhotel/chromecast-api.svg?branch=master)](https://travis-ci.org/alxhotel/chromecast-api) | ||
[![Build Status](https://img.shields.io/travis/com/alxhotel/chromecast-api/master.svg)](https://travis-ci.com/alxhotel/chromecast-api) | ||
[![Dependency Status](https://david-dm.org/alxhotel/chromecast-api/status.svg)](https://david-dm.org/alxhotel/chromecast-api) | ||
[![Standard - Javascript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
chromecast-api is a javascript client library for googlecast's remote playback protocol to play any (compatible) content in the Chromecast device. | ||
**chromecast-api** is a NodeJS module to play any content in your Chromecast device. | ||
Supported media formats: MP4, JPG and PNG files. | ||
## Installation | ||
@@ -22,48 +21,28 @@ | ||
```js | ||
var ChromecastAPI = require('chromecast-api') | ||
const ChromecastAPI = require('chromecast-api') | ||
var browser = new ChromecastAPI.Browser() | ||
const client = new ChromecastAPI() | ||
browser.on('deviceOn', function (device) { | ||
var urlMedia = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4'; | ||
client.on('device', function (device) { | ||
var mediaURL = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4'; | ||
device.play(urlMedia, 0, function () { | ||
console.log('Playing in your chromecast') | ||
setTimeout(function () { | ||
//Pause the video | ||
device.pause(function () { | ||
console.log('Paused') | ||
}) | ||
}, 20000) | ||
setTimeout(function () { | ||
//Stop video | ||
device.stop(function () { | ||
console.log('Stopped') | ||
}) | ||
}, 30000) | ||
setTimeout(function () { | ||
//Close the streaming | ||
device.close(function () { | ||
console.log('Closed') | ||
}) | ||
}, 40000) | ||
device.play(mediaURL, function (err) { | ||
if (!err) console.log('Playing in your chromecast') | ||
}) | ||
}) | ||
``` | ||
## Supported Apps | ||
- Media (video and audio) | ||
- Youtube videos | ||
## Subtitles and Cover | ||
To include subtitles and a cover image, use an Object instead of a string in the *play method*: | ||
To include subtitles and a cover image, use an Object instead of a string in the function `play(mediaObject)`: | ||
```js | ||
const ChromecastAPI = require('chromecast-api') | ||
var ChromecastAPI = require('chromecast-api') | ||
var browser = new ChromecastAPI.Browser() | ||
var media = { | ||
const media = { | ||
url : 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4', | ||
@@ -95,3 +74,3 @@ subtitles: [ | ||
fontGenericFamily: 'SANS_SERIF', // can be: "SANS_SERIF", "MONOSPACED_SANS_SERIF", "SERIF", "MONOSPACED_SERIF", "CASUAL", "CURSIVE", "SMALL_CAPITALS", | ||
//windowColor: '#00000000', // see http://dev.w3.org/csswg/css-color/#hex-notation | ||
//windowColor: '#AA00FFFF', // see http://dev.w3.org/csswg/css-color/#hex-notation | ||
//windowRoundedCornerRadius: 10, // radius in px | ||
@@ -102,69 +81,108 @@ //windowType: 'ROUNDED_CORNERS' // can be: "NONE", "NORMAL", "ROUNDED_CORNERS" | ||
browser.on('deviceOn', function (device) { | ||
const client = new ChromecastAPI() | ||
// Starting to play Big Buck Bunny exactly at second #0 with example subtitles and cover | ||
device.play(media, 0, function () { | ||
console.log('Playing in your chromecast') | ||
client.on('device', function (device) { | ||
device.play(media, function (err) { | ||
if (!err) console.log('Playing in your chromecast') | ||
}) | ||
} | ||
``` | ||
setTimeout(function () { | ||
device.subtitlesOff(function (err,status) { | ||
if (err) console.log('Subtitles off: ERROR') | ||
else console.log('Subtitles off: SUCCESS') | ||
}) | ||
}, 20000) | ||
## API | ||
setTimeout(function () { | ||
device.changeSubtitles(1, function (err, status) { | ||
if (err) console.log("Subtitles restored and in spanish: ERROR") | ||
else console.log("Subtitles restored and in spanish: SUCCESS") | ||
}) | ||
}, 25000) | ||
#### `const client = new ChromecastAPI()` | ||
setTimeout(function () { | ||
device.pause(function () { | ||
console.log('Paused: SUCCESS') | ||
}) | ||
}, 30000) | ||
Initialize the client to start searching for chromecast devices. | ||
setTimeout(function () { | ||
device.unpause(function () { | ||
console.log('Resumed: SUCCESS') | ||
}) | ||
}, 40000) | ||
#### `client.on('device', callback)` | ||
setTimeout(function () { | ||
device.changeSubtitles(0, function (err, status) { | ||
if (err) console.log("Change to english subtitles: ERROR") | ||
else console.log("Change to english subtitles: SUCCESS") | ||
}) | ||
}, 45000) | ||
Listen for new devices by passing `callback(device)` in the callback parameter. | ||
setTimeout(function () { | ||
console.log('Increase subtitles size') | ||
device.changeSubtitlesSize(2, function (err, status) { | ||
if (err) console.log("Increase subtitles: ERROR") | ||
else console.log("Increase subtitles: SUCCESS") | ||
}) | ||
}, 50000) | ||
With the `Device` object you can now interact with your Chromecast. | ||
setTimeout(function () { | ||
device.seek(10,function (err) { | ||
if (err) console.log('Seek forward: ERROR') | ||
else console.log('Seek forward: SUCCESS') | ||
}) | ||
}, 60000) | ||
This is an example of the attributes of `device`: | ||
``` | ||
{ | ||
name: 'Chromecast-e363e7-3e23e2e-3e2e-23e34e._googlecast._tcp.local', // Unique identifier | ||
friendlyName: 'Bobby', // The name you gave to your chromecast | ||
host: '192.168.1.10' // Local IP address | ||
} | ||
``` | ||
setTimeout(function () { | ||
device.changeSubtitlesSize(1.2, function (err, status) { | ||
if (err) console.log("Decrease subtitles: ERROR") | ||
else console.log("Decrease subtitles: SUCCESS") | ||
}) | ||
}, 70000) | ||
#### `client.update()` | ||
}) | ||
}) | ||
Trigger the mDNS and SSDP search again. Warning: the `device` event will trigger again (it might return the same device). | ||
#### `device.play(mediaURL [, opts], callback)` | ||
Use this function to play any media in the chromecast device. Make sure `mediaURL` is accessible by the chromecast. | ||
Pass an attribute `startTime` in the `opts` object to set where to start an audio or video content (in seconds). | ||
``` | ||
{ | ||
startTime: 120 // Start the content at the 2 minute mark | ||
} | ||
``` | ||
## Acknowledgement | ||
This is based on [chromecast-js](https://github.com/guerrerocarlos/chromecast-js) by [@guerrerocarlos](https://github.com/guerrerocarlos) | ||
#### `device.pause(callback)` | ||
Pause the media. | ||
#### `device.resume(callback)` | ||
Resume the media. | ||
#### `device.stop(callback)` | ||
Stop playing the media. | ||
#### `device.seek(seconds, callback)` | ||
Seekk forward `seconds` in time. | ||
#### `device.seekTo(specificTime, callback)` | ||
Seek to the `specificTime` in seconds. | ||
#### `device.setVolume(level, callback)` | ||
Set the volume to a specific `level` (from 0.0 to 1.0). | ||
#### `device.changeSubtitles(index, callback)` | ||
Change the subtitles by passing the index of the subtitle you want based on the list you passed before. | ||
#### `device.changeSubtitlesSize(fontSize, callback)` | ||
Choose the subtitles font size with `fontSize`. The default is `1.0`. | ||
#### `device.subtitlesOff(callback)` | ||
Turn the subtitles off. | ||
#### `device.close(callback)` | ||
Close the connection with the device. | ||
#### `device.on('connected', callback)` | ||
Event emitted when the client is connected to the device. | ||
#### `device.on('finished', callback)` | ||
Event emitted when the media (audio or video) has finished. | ||
#### `device.on('status', callback)` | ||
Event emitted when the device has a new status: `callback(status)`. | ||
## Additional information | ||
* Supported Media: https://developers.google.com/cast/docs/media | ||
* Receiver Apps: https://developers.google.com/cast/docs/receiver_apps | ||
## License | ||
MIT. Copyright (c) [Alex](https://github.com/alxhotel) | ||
@@ -1,17 +0,12 @@ | ||
var ChromecastAPI = require('../index.js') | ||
const ChromecastAPI = require('../index.js') | ||
var devices = [] | ||
var client = new ChromecastAPI() | ||
var browser = new ChromecastAPI.Browser() | ||
console.log('Searching for devices') | ||
browser.on('deviceOn', function (device) { | ||
if (!devices[device.host]) { | ||
devices[device.host] = device | ||
console.log('Found chromecast: `' + device.config.name + '` at ' + device.host) | ||
} | ||
client.on('device', function (device) { | ||
console.log('Found chromecast: `' + device.friendlyName + '` at ' + device.host) | ||
device.play('https://2.img-dpreview.com/files/p/sample_galleries/6361863532/1584980320.jpg', 0, function () { | ||
console.log('Playing in chromecast: ' + device.config.name) | ||
device.play('https://2.img-dpreview.com/files/p/sample_galleries/6361863532/1584980320.jpg', function () { | ||
console.log('Playing in chromecast: ' + device.friendlyName) | ||
@@ -21,2 +16,4 @@ setTimeout(function () { | ||
console.log('Closed') | ||
client.destroy() | ||
}) | ||
@@ -23,0 +20,0 @@ }, 10000) |
@@ -1,17 +0,12 @@ | ||
var ChromecastAPI = require('../index.js') | ||
const ChromecastAPI = require('../index.js') | ||
var devices = [] | ||
var client = new ChromecastAPI() | ||
var browser = new ChromecastAPI.Browser() | ||
console.log('Searching for devices') | ||
browser.on('deviceOn', function (device) { | ||
if (!devices[device.host]) { | ||
devices[device.host] = device | ||
console.log('Found chromecast: `' + device.config.name + '` at ' + device.host) | ||
} | ||
client.on('device', function (device) { | ||
console.log('Found chromecast: `' + device.friendlyName + '` at ' + device.host) | ||
device.play('https://file-examples.com/wp-content/uploads/2017/10/file_example_PNG_500kB.png', 0, function () { | ||
console.log('Playing in chromecast: ' + device.config.name) | ||
device.play('https://file-examples.com/wp-content/uploads/2017/10/file_example_PNG_500kB.png', function () { | ||
console.log('Playing in chromecast: ' + device.friendlyName) | ||
@@ -21,2 +16,4 @@ setTimeout(function () { | ||
console.log('Closed') | ||
client.destroy() | ||
}) | ||
@@ -23,0 +20,0 @@ }, 10000) |
/** | ||
* Test for device and connection reuse. | ||
* Recommended to be run with DEBUG=castv2 to see underlying protocol communication. | ||
*/ | ||
@@ -8,3 +7,3 @@ | ||
var browser = new ChromecastAPI.Browser() | ||
var client = new ChromecastAPI() | ||
@@ -21,4 +20,4 @@ var media = { | ||
browser.on('deviceOn', function (device) { | ||
device.play(media, 0, function () { | ||
client.on('device', function (device) { | ||
device.play(media, function () { | ||
console.log('Playing in your chromecast') | ||
@@ -25,0 +24,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
37121
21
844
185
8
3
+ Addeddns-txt@^2.0.2
+ Addedmime@^2.3.1
+ Addedxml2js@^0.4.23
+ Addedyoutube-remote@^1.0.0
+ Added@leichtgewicht/ip-codec@2.0.5(transitive)
+ Addedbuffer-indexof@1.1.1(transitive)
+ Addeddebug@4.3.4(transitive)
+ Addeddns-packet@5.6.1(transitive)
+ Addeddns-txt@2.0.2(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedmime@2.6.0(transitive)
+ Addedms@2.1.2(transitive)
+ Addedmulticast-dns@7.2.5(transitive)
+ Addedneedle@3.3.1(transitive)
+ Addednode-ssdp@4.0.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsax@1.3.0(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)
+ Addedyoutube-remote@1.1.0(transitive)
- Removedinherits@^2.0.1
- Removeddebug@4.1.1(transitive)
- Removeddns-packet@4.2.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmulticast-dns@7.2.0(transitive)
- Removednode-ssdp@4.0.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
Updateddebug@^4.1.1
Updatedmulticast-dns@^7.2.0
Updatednode-ssdp@^4.0.0