WebSocketClient.connect vs W3C style WebSocketClient(url, protocol) ?
Hi Firstly, great work. I love this module.
Question : Why have have you implemented the WebSocketClient so that the object is created with no arguments and then opened with a connect method vs the W3C spec of passing the url and protocol arguments to the WebSocket constructor?
eg. //WebSocket-Node connection = WebSocketClient() connection.connect(url, prototcol)
vs // W3C connection = WebSocket(url, protocol)
Many thanks!
Because, being a server-side library in Node.JS, I felt it would be better to follow Node API conventions rather than the browser-style conventions, and the library exposes more functionality and error events than the W3C API. Writing a wrapper to make it behave like the W3C API should be pretty trivial though.
Makes sense.
Agreed - the wrapper was pretty trivial and works fine.
As an aside, my interest is in writing webapps that can run in the browser OR in a headless node client that thinks it is the webapp. The more of the code that is transferrable, the more these webapps can be 'write once / run both ends' even when using fairly advanced features like websockets / webworkers.