iobroker-community-adapters / castv2-player Goto Github PK
View Code? Open in Web Editor NEWA player based on the new (CASTV2) protocol used by Chromecast
License: MIT License
A player based on the new (CASTV2) protocol used by Chromecast
License: MIT License
Whenever there is an error from the _icyConnection it tries to close the connection and failing to be able to call _closeIcyConnection on line 80 of mediaInfo.js, it crashes.
I'm using event listeners on MediaPlayer for playerStatus and clientStatus and I am getting duplicate events on these listeners.
From what I can tell, the _playerStatus event listener in persistentPlayer is being invoked twice for each status event. Usually this is due to the event listener being registered more than once but I am having a hard time tracking down where it is happening.
Dean
It seems that sometimes a Chromecast device will disconnect from a client connected with this module.
There is a section of code in PersistentClient that looks like it is designed to cater for such events here:
Ie. looks like PersistentClient is supposed to catch any close events and reconnect.
However, the 'client' in this case is not actually a direct 'client' but the a sender class (PlatformSender), which does not actually emit 'close' events and therefore PersistentClient fails to reconnect as I assume it is designed to do.
This manifests itself as issues such as iobroker-community-adapters/ioBroker.chromecast#36
As noted there, a fix is discussed here: thibauts/node-castv2-client#58 (comment), and indeed changing the line referenced above to use the 'inner client' works for me. Ie. change...
//If connection closes afterwards then re-open it again
that._client.once("close", function(){
that._close();
that._connectClient();
});
...should be changed to...
//If connection closes afterwards then re-open it again
that._client.client.once("close", function(){
that._close();
that._connectClient();
});
I get the following crash in my application:
25 Jan 23:10:29 - [info] [google-cast:Central] Central speaker - Detached player
26 Jan 02:42:51 - [warn] [google-cast:Central] Central speaker - Client error: Error: Device timeout
at fn.ontimeout (/data/data/projects/node-red/node-red-contrib-google-cast/node_modules/castv2-client/lib/senders/platform.js:56:26)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at fn.emit (events.js:208:7)
at Timeout.ontimeout [as _onTimeout] (/data/data/projects/node-red/node-red-contrib-google-cast/node_modules/castv2-client/lib/controllers/heartbeat.js:44:10)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
26 Jan 02:42:51 - [info] [google-cast:Central] Central speaker - client disconnected
26 Jan 02:42:51 - [warn] [google-cast:Central] Central speaker - Client error: Error: Device timeout
at fn.ontimeout (/data/data/projects/node-red/node-red-contrib-google-cast/node_modules/castv2-client/lib/senders/platform.js:56:26)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at fn.emit (events.js:208:7)
at Timeout.ontimeout [as _onTimeout] (/data/data/projects/node-red/node-red-contrib-google-cast/node_modules/castv2-client/lib/controllers/heartbeat.js:44:10)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
26 Jan 02:42:51 - [warn] [google-cast:Central] Central speaker - Client error: Error: Device timeout
at fn.ontimeout (/data/data/projects/node-red/node-red-contrib-google-cast/node_modules/castv2-client/lib/senders/platform.js:56:26)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at fn.emit (events.js:208:7)
at Timeout.ontimeout [as _onTimeout] (/data/data/projects/node-red/node-red-contrib-google-cast/node_modules/castv2-client/lib/controllers/heartbeat.js:44:10)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
26 Jan 02:42:51 - [warn] [google-cast:Central] Central speaker - Client error: Error: Device timeout
at fn.ontimeout (/data/data/projects/node-red/node-red-contrib-google-cast/node_modules/castv2-client/lib/senders/platform.js:56:26)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at fn.emit (events.js:208:7)
at Timeout.ontimeout [as _onTimeout] (/data/data/projects/node-red/node-red-contrib-google-cast/node_modules/castv2-client/lib/controllers/heartbeat.js:44:10)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
26 Jan 02:42:58 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:42:58 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:42:58 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:42:58 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:42:59 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:42:59 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:42:59 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:42:59 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:43:01 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:43:01 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:43:01 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:43:01 - [warn] [google-cast:Central] Central speaker - Client error: Error: connect ECONNREFUSED 192.168.1.15:8009
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
26 Jan 02:43:02 - [red] Uncaught Exception:
26 Jan 02:43:02 - Error: read ECONNRESET
at _errnoException (util.js:1022:11)
at TLSWrap.onread (net.js:615:25)
It looks like the exception is slipping through the cracks in _connectClient in persistentClient.js
Has anybody some idea where this error might come from? It appears only if I try to play a url with a group of chromecast speakers...
Is there a way to play/pause currently playing media from Spotify for example? :) I've tried the following code, but it throws an error:
ScannerPromise()(/* Name */).then(device => {
const mediaPlayer = new MediaPlayerClass(device);
mediaPlayer.pausePromise()
})
When running the example code, I only get sound.
"use strict"
let playerName = ".."; //Change to "catstv2-player to execute outside this folder
var ScannerPromise = require(playerName).ScannerPromise();
var MediaPlayer = require(playerName).MediaPlayer();
let mediaPlayer;
//Find device
return ScannerPromise(/* device name - empty-> take first device found*/)
//Create mediaPlayer
.then (function (device) {
mediaPlayer = new MediaPlayer(device);
return Promise.resolve();
})
//Stop player
.then (function () {
return mediaPlayer.stopClientPromise();
})
//Start playing
.then (function () {
return mediaPlayer.playUrlPromise("http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/BigBuckBunnyAudio.mp4")
})
//Wait for the player to start playing
.then( function() {
return new Promise(function (resolve, reject) {
mediaPlayer.once(mediaPlayer.EVENT_PLAYER_PLAYING, function(contentId){
console.log("PLAYING: %s", contentId);
resolve();
process.exit(0);
});
});
});
Output:
Scanner - found device Stua2 (Chromecast) at 192.168.1.71:8009
MediaPlayer - New device Stua2 at 192.168.1.71:8009
PersistentClient - Stua2 - Waiting up to 10000 seconds for connection to chromecast
PersistentClient - Stua2 - Connected client
PersistentClient - Stua2 - Connected client
PersistentPlayer - Stua2 - Try to join player
PersistentClient - Stua2 - Trying to stop client
PersistentPlayer - Stua2 - Connected player
PersistentPlayer - Stua2 - Player joint
PersistentClient - Stua2 - stopped client
PersistentPlayer - Stua2 - client disconnected
PersistentPlayer - Stua2 - Detached player
PersistentPlayer - Stua2 - Try to play url - http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/BigBuckBunnyAudio.mp4
PersistentPlayer - Stua2 - Try to launch default player
PersistentClient - Stua2 - Waiting up to 10000 seconds for connection to chromecast
PersistentClient - Stua2 - Connected client
PersistentClient - Stua2 - Connected client
PersistentPlayer - Stua2 - Try to join player
PersistentPlayer - Stua2 - Connected player
PersistentPlayer - Stua2 - Player joint
PersistentPlayer - Stua2 - Connected player
PersistentPlayer - Stua2 - Default player lauched
PersistentPlayer - Stua2 - Try to play playlist with 1 items
PersistentPlayer - Stua2 - Started playing - http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/BigBuckBunnyAudio.mp4
PersistentPlayer - Stua2 - Playing playlist with 1 items
PLAYING: http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/dash/BigBuckBunnyAudio.mp4
Would be nice if you could cherry pick this commit kmerabet@d63bfe4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.