xat / chromecast-player

simple chromecast player
MIT License
99 stars 20 forks source link

Guard against empty status response #4

Closed parshap closed 9 years ago

parshap commented 9 years ago

I came across an issue where Chromecast responds to a GET_STATUS request with an empty status:

castv2 recv message: protocolVersion=0 sourceId=web-17 destinationId=client-207617 namespace=urn:x-cast:com.google.cast.media data={"type":"MEDIA_STATUS","status":[],"requestId":1}

I'm not sure when exactly this can happen, but for me it happened after casting songza.com and then closing the tab (which causes the Chromecast to stop playing, but the receiver app is still running).

This change guards against this case by checking for the existence of a non-falsey status object.

parshap commented 9 years ago

I've realized this causes the promise given to attach() to never get resolved because now in this case updateStatus(cb) will never call the callback. I've made another change so that the callback is always called.

parshap commented 9 years ago

It still seems that the player object goes in an invalid state when an empty status is received asthis.currentSession becomes undefined, so any API calls via sessionRequest throw an error when accessing session.mediaSessionId.

xat commented 9 years ago

Thanks, merged :)

I'll try if I'm able to reproduce the currentSession undefined problem. I think the main problem is that the module dosn't handle disconnects 100% correctly.