WebSocket-Node icon indicating copy to clipboard operation
WebSocket-Node copied to clipboard

WebSocketClient.connect vs W3C style WebSocketClient(url, protocol) ?

Open FreeLiveTutor opened this issue 13 years ago • 2 comments

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!

FreeLiveTutor avatar Apr 18 '13 12:04 FreeLiveTutor

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.

theturtle32 avatar Jun 24 '13 19:06 theturtle32

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.

FreeLiveTutor avatar Jun 25 '13 10:06 FreeLiveTutor