# castv2-client

> A Chromecast client based on the new (CASTV2) protocol

Latest version **1.2.0** (published 2016-12-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install castv2-client
pnpm add castv2-client
yarn add castv2-client
bun add castv2-client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2016-12-30 |
| First published | 2014-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 658 |
| Author | thibauts |
| Maintainers | thibauts |
| Keywords | chromecast, castv2 |

## Links

- npm: https://www.npmjs.com/package/castv2-client
- Repository: https://github.com/thibauts/node-castv2-client
- Homepage: https://github.com/thibauts/node-castv2-client#readme
- Issues: https://github.com/thibauts/node-castv2-client/issues
- npm.io page: https://npm.io/package/castv2-client

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^2.2.0
- [castv2](https://npm.io/package/castv2.md) ~0.1.4

## Recent versions

- 1.2.0 (latest) — 2016-12-30
- 1.1.2 — 2016-06-13
- 1.1.1 — 2016-01-06
- 1.1.0 — 2015-04-09
- 0.0.8 — 2014-10-27
- 0.0.7 — 2014-10-22
- 0.0.6 — 2014-10-11
- 0.0.5 — 2014-09-14
- 0.0.4 — 2014-09-03
- 0.0.2 — 2014-07-30
- 0.0.1 — 2014-06-14
- 0.0.0 — 2014-06-14

## README

castv2-client
=============
### A Chromecast client based on the new (CASTV2) protocol

This module implements a Chromecast client over the new (CASTV2) protocol. A sender app for the `DefaultMediaReceiver` application is provided, as well as an `Application` base class and implementations of the basic protocols (see the `controllers` directory) that should make implementing custom senders a breeze.

This implementation tries to stay close and true to the protocol. For details about protocol internals please see [https://github.com/thibauts/node-castv2](https://github.com/thibauts/node-castv2#protocol-description). 

For advanced use, like using [subtitles](https://github.com/thibauts/node-castv2-client/wiki/How-to-use-subtitles-with-the-DefaultMediaReceiver-app) with the DefaultMediaReceiver check the [wiki](https://github.com/thibauts/node-castv2-client/wiki).

Installation
------------

``` bash
$ npm install castv2-client
```

On windows, to avoid native modules dependencies, use

``` bash
$ npm install castv2-client --no-optional
```

Examples
--------

Launching a stream on the device :

``` javascript
var Client                = require('castv2-client').Client;
var DefaultMediaReceiver  = require('castv2-client').DefaultMediaReceiver;
var mdns                  = require('mdns');

var browser = mdns.createBrowser(mdns.tcp('googlecast'));

browser.on('serviceUp', function(service) {
  console.log('found device "%s" at %s:%d', service.name, service.addresses[0], service.port);
  ondeviceup(service.addresses[0]);
  browser.stop();
});

browser.start();

function ondeviceup(host) {

  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 15 seconds playing.
        setTimeout(function() {
          player.seek(2*60, function(err, status) {
            //
          });
        }, 15000);

      });

    });
    
  });

  client.on('error', function(err) {
    console.log('Error: %s', err.message);
    client.close();
  });

}
```

Contributors
------------

* [xat](https://github.com/xat) (Simon Kusterer)
* [angelnu](https://github.com/angelnu) (Angel Nunez Mencias)

---
_Source: https://npm.io/package/castv2-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
