Fix socket error

First of all thanks for making this! (^_^)

This checks if `ps` is defined before trying to send a message. It's hard to reproduce but using [chromecast-player](https://github.com/xat/chromecast-player) I've gotten an error caused by trying to refer to a `null` or `undefined` `ps`, most likely due to network issues but I'm not entirely sure. I tested it playing a few hours of video and got the `Attempted to send message after connection was closed` message a few times so this definitely fixes it, although I think some work still needs to be done on a higher level (i.e in `castv2-client`) to make sure the connection is open before trying to send messages.