Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alxhotel committed Dec 21, 2019
1 parent e5dc39a commit 96a0f5d
Show file tree
Hide file tree
Showing 14 changed files with 2,468 additions and 387 deletions.
31 changes: 1 addition & 30 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,2 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
# NPM
node_modules

# Users Environment Variables
.lock-wscript

# Netbeans
nbproject
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ sudo: false

language: node_js

node_js:
- "node"

install:
- npm install

Expand Down
34 changes: 21 additions & 13 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
Copyright (c) 2016, Alex

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
MIT License

Copyright (c) 2019 Alex

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
197 changes: 96 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ chromecast-api
[![Travis Build](https://travis-ci.org/alxhotel/chromecast-api.svg?branch=master)](https://travis-ci.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 for Googlecast's remote playback protocol to play any (compatible) content in the Chromecast device.

## Installation

Expand All @@ -16,50 +16,25 @@ npm install chromecast-api
## Usage

```js
var ChromecastAPI = require('chromecast-api')

var browser = new ChromecastAPI.Browser()

browser.on('deviceOn', function (device) {
var urlMedia = '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)
const ChromecastAPI = require('chromecast-api')

const client = new ChromecastAPI()

client.on('device', function (device) {
var mediaURL = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4';

device.play(mediaURL, function (err) {
if (!err) console.log('Playing in your chromecast')
})
})

```

## 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

var ChromecastAPI = require('chromecast-api')

var browser = new ChromecastAPI.Browser()
const ChromecastAPI = require('chromecast-api')

var media = {
url : 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4',
Expand Down Expand Up @@ -88,77 +63,97 @@ var media = {
fontStyle: 'BOLD', // can be: "NORMAL", "BOLD", "BOLD_ITALIC", "ITALIC",
fontFamily: 'Droid Sans',
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
//windowType: 'ROUNDED_CORNERS' // can be: "NONE", "NORMAL", "ROUNDED_CORNERS"
}
}

browser.on('deviceOn', function (device) {

// 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')

setTimeout(function () {
device.subtitlesOff(function (err,status) {
if (err) console.log('Subtitles off: ERROR')
else console.log('Subtitles off: SUCCESS')
})
}, 20000)

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)

setTimeout(function () {
device.pause(function () {
console.log('Paused: SUCCESS')
})
}, 30000)

setTimeout(function () {
device.unpause(function () {
console.log('Resumed: SUCCESS')
})
}, 40000)

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)

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)

setTimeout(function () {
device.seek(10,function (err) {
if (err) console.log('Seek forward: ERROR')
else console.log('Seek forward: SUCCESS')
})
}, 60000)

setTimeout(function () {
device.changeSubtitlesSize(1.2, function (err, status) {
if (err) console.log("Decrease subtitles: ERROR")
else console.log("Decrease subtitles: SUCCESS")
})
}, 70000)
const client = new ChromecastAPI()

client.on('device', function (device) {
device.play(media, function (err) {
if (!err) console.log('Playing in your chromecast')
})
})
}
```
## API
#### `const client = new ChromecastAPI()`
Initialize the client to start searching for chromecast devices.
#### `client.on('device', callback)`
Listen for new devices by passing `callback(device)` in the callback parameter.
With the `Device` object you can now interact with your Chromecast.
This is an example of a attributes of `device`:
```json
{
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
}
```
#### `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.
```json
{
seconds: 0,
}
```
## Acknowledgement
This is based on [chromecast-js](https://github.com/guerrerocarlos/chromecast-js) by [@guerrerocarlos](https://github.com/guerrerocarlos)
#### `device.subtitlesOff(callback)`
Turn the subtitles off.
#### `device.pause(callback)`
Pause the media.
#### `device.resume(callback)`
Resume the media.
#### `device.stop(callback)`
Stop playing the media.
#### `device.close(callback)`
Close the connection with the device.
#### `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`.
## License
MIT. Copyright (c) [Alex](https://github.com/alxhotel)
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* global module */

module.exports = require('./lib/Browser.js')
module.exports = require('./lib/client.js')
Loading

0 comments on commit 96a0f5d

Please sign in to comment.