WIP: Ws client code

You do too much in each function.  Break things up.  The pattern should be:

```javascript
// Is the object a response?
if(data.type === SyncMessage.REQUEST) {
  handleRequestMessage(...);
} else if (data.type === SyncMessage.RESPONSE) {
  handleResponseMessage(...);
} else if (data.type === SyncMessage.ERROR) {
  handleErrorMessage(...);
}
```

Then you can move things into separate functions.  Try to separate control flow like this (i.e., choosing paths based on message types) from actual work you want to do once you have the correct path.  It makes understanding the code, and thus maintaining it, a lot easier.