thibauts / node-castv2-client

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

MediaController calls stop() after Channel already disposed #97

Open i8beef opened 4 years ago

i8beef commented 4 years ago

The MediaController attaches an "onclose" to its own "close" event which will send a session command of STOP through the underlying channel.

However, the MediaController only EMITS a "close" event from its inherited Controller, in response to the Channel having already closed. This will ALWAYS ERROR if the Channel is disposed, and is only missed now because of #96 failing to properly close the channel anyway.

Suggestion: Just remove the "self.stop()" call here. If the channel is already dead, you've already lost your opportunity.

Adding a Controller.close override to the MediaController would allow you to call this stop prior to calling the underlying Controller "close" to run this "STOP" before the channel goes away, but I actually think this would be poor form. It would probably cause issues with multiple instances of DefaultMediaReceiver that share a Client connection from coexisting given that any ONE of them closing would then trigger a media STOP rather than requiring a conscious decision from the calling code to do this prior to the receiver.close: i.e., it removes options rather than doing necessary cleanup.