Tidy up events

1. Avoid generating two `onclose` calls on explicit `close()`.
2. On disconnect, make the close reason available to `onconnecting`.  (The first connect also fires `onconnecting`, and can be distinguished with `event.code !== undefined` or similar; alternately maybe this should be a "reconnecting" event only?)
3. Correct typo in generation of `error` event.

Note that having the close reasons on `onconnecting` instead of `onclose` means that it's not completely API compatible with `WebSocket`, but then it wasn't before either.
Merge pull request #33 from uecasm/patch-1

Tidy up events