Factor out websocket specific code

This will allow to mock the client in tests but might also
be useful for non-websocket implementations of the bus on
other platforms. As a nice side effect the change makes the
code cleaner.