Initial web socket API.

This PR is to a `websocket` feature branch for later merging into `master`.
I changed it to `onClose()` so it looks like code.