Resocket is a socket.io
wrapper and middleware for React
and Redux
applications.
It helps you abstract away all the socket.io
implementations in your app.
You can use Resocket separately without using the createResocketMiddleware
to have more control over the socket implementation.
npm install --save resocket
Using socket.io
with React-redux
applications does not allow you to much abstraction and increases complexity.
With Resocket, it provides you with a bit abstraction and leads to a cleaner code.
If you want more abstraction and allow Resocket middleware to do more of the stuff,
all you need is to import createResocketMiddleware
. Resocket only takes a few minutes to get started with.
Middleware
import Resocket, { createResocketMiddleware } from 'resocket';
const socket = Resocket.connect(url, opts);
const resocketMiddleware = createResocketMiddleware(socket, listOfEventsToEmitTo);
const middleware = applyMiddleware(thunk, resocketMiddleware);
Resocket
All you need to do is to call the connect
method on Resocket and use anywhere across your React-redux app.
import { render } from 'react-dom';
import Resocket from 'resocket'
Resocket.connect(url);
//...
render();
http://localhost:9000
optional
These are the default optional parameters.
Default parameters are:auth: true,
reconnection: true,
reconnectionDelay: 1000
You can override them simply by passing for example:
Resocket.connect('http://localhost:3000', {auth: false});
You can also extend the options object with socket.io accepted parameters:
Resocket.connect('http://localhost:3000', {transports: ['polling']});
Note: On passing auth: false
Resocket won't allow a connection to be established. This is useful when you want to allow a connection to be only built after Login or some basic authentication.
No other than socket.io
and of course to React
and Redux
MIT
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。