thibauts / node-castv2-client

A Chromecast client based on the new (CASTV2) protocol
MIT License
648 stars 95 forks source link

handling timeout properly #44

Open Ivshti opened 8 years ago

Ivshti commented 8 years ago

Using mafintosh/chromecasts on top of this module, I keep hitting a very serious issue:

When playing a video, then pausing for N minutes, or simply stopping, and then trying to play again, I get "cannot access .send of undefined", since the socket has been closed.

This is OK to some extent, because we have 'close' events which we can handle.

The weird thing is that 'error' never fires (where var client = new castv2.Client()), not on client, nor client.client, nor on player (where client.launch(castv2.DefaultMediaReceiver, function (err, player) { ... })) It does fire sometimes, a few minutes after the actual close

But how to handle the cases when the connection is closed? A simple reconnect on the same chromecast address does not work - with our without .launch-ing DefaultMediaReceiver. In both cases getStatus keeps returning undefined for status and null as an error. For whatever reason some state is kept somewhere. Or it requires the .play to be called again.

In any case, I haven't find a robust way to re-initiate the connection like nothing happened.

The heartbeat is working properly, but doesn't seem to be helping.

dmythro commented 8 years ago

Got same error recently. And displayed stack trace didn't lead to any of my sources, so not sure even where to check with try ... catch.

Uncaught Exception:
Error: Device timeout
    at HeartbeatController.ontimeout (/app/node_modules/castv2-client/lib/senders/platform.js:56:26)
    at HeartbeatController.g (events.js:260:16)
    at emitNone (events.js:67:13)
    at HeartbeatController.emit (events.js:166:7)
    at ontimeout [as _onTimeout] (/app/node_modules/castv2-client/lib/controllers/heartbeat.js:44:10)
    at Timer.listOnTimeout (timers.js:92:15)
thibauts commented 8 years ago

Can you provide code to reproduce the issue ?

dmythro commented 8 years ago

Sure, just pushed code I was playing with to my Chromecast repo. Probably, you are looking for usage in app/src/services.js.

dmythro commented 8 years ago

P.S. I have few questions for the flow to make UX as flawless and automatic as possible, not sure about some cases event handling, would be happy if you'd ping me via email (should be seen in my profile) to solve them and build +/- stable app out there (didn't find your contact).

thibauts commented 8 years ago

I meant something like the minimal code sample that reproduces the issue. I really don't have enough free time to delve through large codebases.

Anyway I did a search on this repo with the error message you got (https://github.com/thibauts/node-castv2-client/search?utf8=%E2%9C%93&q=Device+timeout) which leads straight to the answer you're looking for. You have to listen to error messages emitted by your client, as the sample code in the README shows, and handle the event properly. This may include destroying the client, re-instanciating another one and putting it in the same state.

I suspect this is the problem you all have here. Once timed-out the playing state is lost on the Chromecast itself and solely reconnecting doesn't make it. This probably won't ever be solved in this module, as the code is receiver-agnostic and can't know the process to put a given app in a given state.

I can understand this is frustrating.

If you think I'm mistaken, provide the minimal code that reproduces your issue and simple instructions to run it. I really can't allocate 1~2 hours every time an issue is opened. I don't even have time to work on my current projects. I'm sure you'll understand.

@z-ax About your UX question, please open an issue and label is as you feel appropriate. I'll try to follow-up. This way it will be simpler and potentially benefit others.

roccomuso commented 8 years ago

Having the same issue!

thibauts commented 7 years ago

My april 3 comment still applies. Please provide a minimal code sample reproducing the issue so we can investigate further.