GithubHelp home page GithubHelp logo

electron-chromecast's Introduction

Electron Chromecast

Join the chat at https://gitter.im/GPMDP/electron-chromecast Build Status

An implementation of the chrome.cast API in electron

Usage

Basic

You must consume electron-chromecast from within your renderer process, preferably in a preload script.

// ES5
require('electron-chromecast');

// ES6
import 'electron-chromecast';

This will inject the chrome.cast variables and the associated methods globally automatically.
By default when requesting a new Session through chrome.cast.requestSession you will be provided an active Session with the first Chromecast Device we find. To change this behaviour read the Advanced section.

Advanced

// ES5
var chromecast = require('electron-chromecast');

chromecast(function (receivers) {
    return new Promise(function (resolve, reject) {
        // Do some logic to choose a receiver, possibly ask the user through a UI
        var chosenReceiver = receivers[0];
        resolve(chosenReceiver);
    });
});

// ES6
import chromecast from 'electron-chromecast';

chromecast(async (receivers) => {
    // Do some logic to choose a receiver, possibly ask the user through a UI
    const chosenReceiver = receivers[0];
    return chosenReceiver;
});

The function returned from electron-chromecast should be called with a single parameter; a function that returns a promise that will eventually resolve with a single receiver. This receiver is the one that will be used by chrome.cast.

Installation

Note: Behind the scenes we use MDNS which has some system requirements, make sure your system has the required dependencies.

TODO

  • All the TODO's in code (We only implemented the functionality required by Google Play Music, however this should be sufficient for MOST applications)

TODO (But totally not needed): The chrome.cast.games API

electron-chromecast's People

Contributors

gitter-badger avatar greenkeeperio-bot avatar jostrander avatar marshallofsound avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

electron-chromecast's Issues

Casts are not updated when switching networks

Currently only showing a cast device from my work network, and it hasn't updated to show my two home chromecasts at home. In theory it should drop the old devices via serviceDown and bring in the new ones via serviceUp however I think the scanning may have stopped when the network dropped, or the laptop went to sleep.

Use yarn.lock?

I've just started using yarn and noticed there is no yarn.lock here. Should we consider using it?

Native API Error

On Ubuntu 17.04
Node versions: v7.10.0, v8.2.1

After installing libavahi-compat-libdnssd-dev, the package installs but throws the warnings:

 *** WARNING *** The program 'electron' uses the Apple Bonjour compatibility layer of Avahi.

  *** WARNING *** Please fix your application to use the native API of Avahi!
  *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=electron>
  *** WARNING *** The program 'electron' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
  *** WARNING *** Please fix your application to use the native API of Avahi!
  *** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=electron&f=DNSServiceRegister>

In electron, these errors are thrown:

Error: getaddrinfo -3008
    at errnoException (../node_modules/mdns/lib/resolver_sequence_tasks.js:199)
    at getaddrinfo_complete (../node_modules/mdns/lib/resolver_sequence_tasks.js:112)
    at GetAddrInfoReqWrap.oncomplete (../node_modules/mdns/lib/resolver_sequence_tasks.js:120)

Anyone else have this problem?

I just can't understand how it works

Can you please me more specific in docs so everyone can understand how to use it?

In my case the chrome.cast.requestSession always sends an error with CANCEL code:

error: Error { code: 'CANCEL', description: null, details: {} }
whoops! there was an error TypeError: Cannot read property 'substring' of undefined
at _class._normalizeService (/Users/silvagc/Projetos/pessoal/salao/projection_app/node_modules/node-mdns-easy/dist/browser.js:96:57)
at _class.serviceUp (/Users/silvagc/Projetos/pessoal/salao/projection_app/node_modules/node-mdns-easy/dist/browser.js:74:35)
at emitOne (events.js:96:13)
at emit (events.js:188:7)
at internal.onMessage (/Users/silvagc/Projetos/pessoal/salao/projection_app/node_modules/mdns-js/lib/browser.js:109:12)
at emitThree (events.js:116:13)
at emit (events.js:194:7)
at Socket. (/Users/silvagc/Projetos/pessoal/salao/projection_app/node_modules/mdns-js/lib/networking.js:142:10)
at emitTwo (events.js:106:13)
at Socket.emit (events.js:191:7)

Music becomes unpaused when chromecast disconnects from inactivity (emitting the wrong event on disconnect?)

MarshallOfSound/Google-Play-Music-Desktop-Player-UNOFFICIAL-#3071

OS: Windows 10

GPMDP Version: 4.5.0

Issue Descriptions: Sorry to be brief here but wanted to bring this up before I forget.
Issue: GPMDP in paused mode resumes music by itself when a connected chromecast device times out and drops connection. This results in current playlist being resumed out of default audio output without me un-pausing playback.
In google-chrome, it is normal for a chromecast to time out and disconnect after a period of inactivity but it does not resume a paused playlist like i've noticed occurs in GPMDP.
Not sure if related to the Windows integration, I do have that enabled and will follow up here if I can track down if any of the settings are related.
Steps to Reproduce:

  1. Connect GPMDP to a chromecast
  2. Start playing music
  3. Pause music
  4. Wait until inactivity timeout period for chromecast to disconnect
  5. Run back to your computer to pause the music coming out of your default playback device which suddenly became unpaused (lol)

Yaser

صرفاً برای امتحان

Unable to add to a project on Ubuntu

I've tried doing npm install --save electron-chromecast and I get the following error:

> [email protected] install /home/mark/Documents/workspace/markbirbeck/sidewinder-viewer/node_modules/mdns
> node-gyp rebuild

make: Entering directory '/home/mark/Documents/workspace/markbirbeck/sidewinder-viewer/node_modules/mdns/build'
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_sd.o
In file included from ../src/dns_sd.cpp:1:0:
../src/mdns.hpp:32:20: fatal error: dns_sd.h: No such file or directory
compilation terminated.

Full details with trace

> [email protected] install /home/mark/Documents/workspace/markbirbeck/sidewinder-viewer/node_modules/mdns
> node-gyp rebuild

make: Entering directory '/home/mark/Documents/workspace/markbirbeck/sidewinder-viewer/node_modules/mdns/build'
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_sd.o
In file included from ../src/dns_sd.cpp:1:0:
../src/mdns.hpp:32:20: fatal error: dns_sd.h: No such file or directory
compilation terminated.
dns_sd_bindings.target.mk:143: recipe for target 'Release/obj.target/dns_sd_bindings/src/dns_sd.o' failed
make: *** [Release/obj.target/dns_sd_bindings/src/dns_sd.o] Error 1
make: Leaving directory '/home/mark/Documents/workspace/markbirbeck/sidewinder-viewer/node_modules/mdns/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Linux 4.4.0-38-generic
gyp ERR! command "/usr/bin/nodejs" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/mark/Documents/workspace/markbirbeck/sidewinder-viewer/node_modules/mdns
gyp ERR! node -v v6.7.0
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok 
npm ERR! Linux 4.4.0-38-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "--save" "electron-chromecast"
npm ERR! node v6.7.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mdns package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs mdns
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls mdns
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/mark/Documents/workspace/markbirbeck/sidewinder-viewer/npm-debug.log

After a bit of poking around, the advice that fixed the problem was to install libavahi-compat-libdnssd-dev:

sudo apt install -y libavahi-compat-libdnssd-dev

I can't think of any cunning way to make this a dependency in 'node world', but it might be worth adding to the documentation.

Error when importing electron-chromecast on mac

Hey there,

I setted up a basic electron project and I get the following error message when importing electron-chromecast.

I am using a Mac with OSx 10.13.2. Any hints?

Thank you!

ProtoBuf.js:348 Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://cast_channel.proto/'.
    at Object.ProtoBuf.Util.Util.fetch (http://localhost:3000/static/js/bundle.js:31789:29)
    at Object.ProtoBuf.loadProtoFile (http://localhost:3000/static/js/bundle.js:35675:42)
    at Object.<anonymous> (http://localhost:3000/static/js/bundle.js:3236:24)
    at Object../node_modules/castv2/lib/proto.js (http://localhost:3000/static/js/bundle.js:3258:30)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at fn (http://localhost:3000/static/js/bundle.js:89:20)
    at Object.<anonymous> (http://localhost:3000/static/js/bundle.js:3034:27)
    at Object../node_modules/castv2/lib/client.js (http://localhost:3000/static/js/bundle.js:3165:30)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at fn (http://localhost:3000/static/js/bundle.js:89:20)
    at Object../node_modules/castv2/index.js (http://localhost:3000/static/js/bundle.js:2939:14)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at fn (http://localhost:3000/static/js/bundle.js:89:20)
    at Object../node_modules/electron-chromecast/build/cast/_Classes/Session.js (http://localhost:3000/static/js/bundle.js:5486:14)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at fn (http://localhost:3000/static/js/bundle.js:89:20)
    at Object.<anonymous> (http://localhost:3000/static/js/bundle.js:5920:16)
    at Object../node_modules/electron-chromecast/build/cast/index.js (http://localhost:3000/static/js/bundle.js:6156:30)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at fn (http://localhost:3000/static/js/bundle.js:89:20)
    at Object.<anonymous> (http://localhost:3000/static/js/bundle.js:7435:13)
    at Object../node_modules/electron-chromecast/build/index.js (http://localhost:3000/static/js/bundle.js:7482:30)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at fn (http://localhost:3000/static/js/bundle.js:89:20)
    at Object../src/App.js (http://localhost:3000/static/js/bundle.js:71971:78)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at fn (http://localhost:3000/static/js/bundle.js:89:20)
    at Object../src/index.js (http://localhost:3000/static/js/bundle.js:72118:63)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at fn (http://localhost:3000/static/js/bundle.js:89:20)
    at Object.0 (http://localhost:3000/static/js/bundle.js:72268:18)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:679:30)
    at ./node_modules/ansi-regex/index.js.module.exports (http://localhost:3000/static/js/bundle.js:725:37)
    at http://localhost:3000/static/js/bundle.js:728:10
index.js:2177 ./node_modules/protobufjs/dist/ProtoBuf.js
Module not found: `/Users/ulilicht/Develop/radiocast/node_modules/protobufjs/node_modules/ByteBuffer/dist/ByteBufferAB.js` does not match the corresponding path on disk `bytebuffer`.
__stack_frame_overlay_proxy_console__ @ index.js:2177
index.js:2177 ./node_modules/protobufjs/node_modules/bytebuffer/dist/ByteBufferAB.js
Module not found: `/Users/ulilicht/Develop/radiocast/node_modules/protobufjs/node_modules/Long/dist/Long.js` does not match the corresponding path on disk `long`.
__stack_frame_overlay_proxy_console__ @ index.js:2177

browser.js blows up inside _normalizeService when service has no fullname or txt

e.g. a service like the one below passed to _normalizeService will fail in two ways: normalizing the name (no service.fullname), and normalizing the txtRecord (no service.txtRecord)

{
  "addresses": [
    "192.168.1.100"
  ],
  "query": [],
  "type": [
    {
      "name": "homekit",
      "protocol": "tcp",
      "subtypes": []
    }
  ],
  "interfaceIndex": 3,
  "networkInterface": "pseudo multicast"
}

incorrect names for network "castable" devices

As requested, I am re-posting this issue here. Thanks for a fantastic product BTW!

The original now closed post is located at:
MarshallOfSound/Google-Play-Music-Desktop-Player-UNOFFICIAL-#1523 (comment)


OS:
Windows 10 (v1607)

Issue Descriptions:
List of "castable" devices is wrong. Here is a listing of the devices on my network (as seen by the chrome browse I am using to write this):

2016-08-24 06_52_45-groove music

However, in the app, when I attempt to cast - this is what appears:

2016-08-24 06_43_58-start

First it appears that the "." in the name of the device is causing the device name to truncate. In addition there is an incorrect number of devices listed - no idea were that's coming from. Interestingly, when select the correct "a" from the list, casting works.

Steps to Reproduce:
Every time I go to cast it shows up. Maybe it's my naming convention (which differentiates video from audio casting devices) but this is the only place I have seen this naming disconnect.

Set up build status / eslint test

Similar to the main project, this should also integrate travis-ci and run eslint tests to check for any major errors before committing / pull requests. It will help clean up the code and keep it clean.

Simple Demo App

Hey, I have been trying to get this to work for a few days now following docs to a tee and all I have been getting are unavailable cast sessions. I was wondering if there was a way that you could do a very simple demo app that could be used as a reference to make it easier for people to work with this.
Thanks!

Receiver List Empty

I'm trying to recreate the CastHelloText-chrome functionality within an Electron app, however, it is not detecting any Chromecast receivers.

I've tried running the CastHelloText-chrome sample on a Chrome browser and it is able to find receivers. But in Electron, I've tried using the default app id given in the sample (794B7BBF) and chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID, but it's still not finding anything.

Trying to use it, I get onError: {"code":"RECEIVER_UNAVAILABLE","description":null,"details":{}}.

Is there anything special regarding ports or networking that I am missing? If there is a sample app using electron-chromcast, that would be appreciated as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.