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.
Fix TypeError when no options provided

`TypeError: Cannot read property 'debug' of undefined`
Merge pull request #34 from uecasm/patch-2

Fix TypeError when no options provided
Merge pull request #33 from uecasm/patch-1

Tidy up events
Added option for maxReconnectInterval

Added an extra option to specify the maximum amount of time to wait
before attempting a reconnect.  Defaults to -1, to keep the current
behaviour.
Updated default, added documentation

Now defaults to 30,000.  Removed the -1 magic number.  Added
documentation on use.
Added maxreconnectinterval to ts definition
swapped tab for spaces
Merge pull request #36 from JamesThorpe/doc-ts

Updated ts with new option
Merge branch 'master' into feature/automatic-open-option

Conflicts:
	reconnecting-websocket.js