React-Sockets
Manage sockets connection easily with the react power, is how a orm but of sockets :)
General Schema

How to install?
npm install --save reactsockets
Accepts protocols
WebSockets
Socket.IO (Develop phase)
WebSockets Implementation
Required params
Config params
- KeysTrust
- List of keys that are used to decode the message and update the react state
Example
import React from 'react';
import { WebSockets } from 'reactsockets';
class ChatInput extends WebSockets {
constructor(props) {
super(props);
this.state = {
message: '',
};
this.protocol = 'ws';
this.host = 'localhost';
this.port = 8080;
this.setKeysTrust(['message']);
}
render() {
return (
<div id="chat-input">{this.state.message}</div>
);
}
}
export default ChatInput;
SocketIO Implementation
Required params
Config params
- KeysTrust
- List of keys that are used to decode the message and update the react state
Example
import React from 'react';
import { SocketIO } from 'reactsockets';
class ChatInput extends SocketIO {
constructor(props) {
super(props);
this.state = {
message: '',
};
this.url = 'http://localhost:8080';
this.setKeysTrust([]);
}
render() {
return (
<div id="chat-input">{this.state.message}</div>
);
}
}
export default ChatInput;
KeysTrust
The parametter 'keytrust' must a be an array of strings or array strings/objects
Example
const keysTrust = [
'name',
{ messages: 'storage' },
];
Why objects?
With a object you are define type of keys, type are:
- Storage
- All values with this keys are save in a array
- Increment
- Increment previous value with the new received value
- Decrement
- Decrement previous value with the new received value
Code example
WebSockets
https://github.com/Sansossio/ReactSockets-Chat
SocketIO
https://github.com/Sansossio/ReactSockets-Chat-IO