ws icon indicating copy to clipboard operation
ws copied to clipboard

Support for React.JS

Open rajiff opened this issue 9 years ago • 6 comments

From documents, its not clear how to use this library in React.JS (in ES6)

Please drop a example about the same

rajiff avatar Mar 21 '17 19:03 rajiff

It works like any other Node.js package. In the browser you have to use the native WebSocket object not ws.

lpinca avatar Mar 21 '17 19:03 lpinca

@lpinca Thanks

An example would help (it can be incorporated to this if needed as Pull Request https://github.com/rajiff/ws-react-demo)

That means, in WS we also don't have support for any channel/room/namespace concept?

rajiff avatar Mar 21 '17 19:03 rajiff

That means, in WS we also don't have support for any channel/room/namespace concept?

Yes, that's correct.

As for the examples, there are a lot of results if you search "react websocket example" on google.

lpinca avatar Mar 21 '17 19:03 lpinca

@lpinca : I update my repo now with working version, please have a look and suggest

What is the suggestion if we want to send data to specific client sockets only? only emit on that socket object alone?

rajiff avatar Mar 21 '17 20:03 rajiff

Here's another example; I'm using the React Context API to share the connection between all components:

https://github.com/DestinyTheGame/anubis/blob/master/components/websocket/index.js

3rd-Eden avatar Mar 21 '17 20:03 3rd-Eden

Thanks @3rd-Eden

I now got it updated https://github.com/rajiff/ws-react-demo/blob/master/public/components/WebSocketClient.jsx, a fully functional react ws client with 'WS' as server

Going to try this with socket.io also as i need pvt channels/rooms

rajiff avatar Mar 22 '17 03:03 rajiff