Refactor to work in node.js and the browser

Allows `cpa.js` to be used in node.js and the browser.

This is very similar in approach to the [radiotag.js refactor](https://github.com/ebu/radiotag.js/pull/3). 

I've tested in the [CPA Client](https://github.com/ebu/cpa-client) and in the [node.js tester](https://github.com/andrewn/radiotag-node-tester). I'd appreciate you testing too though.