thibauts / node-castv2-client

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

broken Chromecast Shutdown handling #2

Closed Flyingmana closed 10 years ago

Flyingmana commented 10 years ago

Hi, I use this modul to write a little webapp tracking the state of my chromecast. I noticed some problems when I turn of my TV so the chromecast shuts down, it seems the handling for this is a bit incomplete/incompatible to the actual implementation.

thats the changes I made in my app to make the shutdown happen without endless repeating errors from the still running heartbeat.
https://github.com/Flyingmana/home-media-center/commit/cca450edf71bf44df1c3d94dde0a0ed4ddf3c404

Iam very fresh to nodeJS, but I have the feeling you call some "close()" which are not implemented here https://github.com/thibauts/node-castv2-client/blob/master/lib/senders/platform.js#L41

thibauts commented 10 years ago

A closing connection should emit a close event on the client, see this. Then the code you pointed to should stop the hearbeat and return the platform sender to an idle state. Could you run your code with DEBUG=* node yourapp.js and provide a trace of the shutdown part ?

thibauts commented 10 years ago

One week idle, I close this issue. Feel free to reopen it if needed.

thibauts commented 10 years ago

Found a case where this could happen. Putting the device brutally off-power caused the client to wait for FIN/ACK on the TCP connection and the socket close event never happened (or much, much later). This has been solved by force-closing the socket client-side in castv2 and implementing heartbeat timeout in castv2-client.