1 Star 0 Fork 0

贠宝元 / resocket

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

resocket

travis build version MIT License Coverage Status npm

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.

Installation

npm install --save resocket

Influences

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.

Basic Usage

Middleware

import Resocket, { createResocketMiddleware } from 'resocket';

const socket = Resocket.connect(url, opts);
const resocketMiddleware = createResocketMiddleware(socket, listOfEventsToEmitTo);

const middleware = applyMiddleware(thunk, resocketMiddleware);

API docs 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();
  • url: Any url for establishing a socket connection e.g: http://localhost:9000
  • opts: 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.

API docs Resocket

Middleware Example

Thanks

No other than socket.io and of course to React and Redux

License

MIT

空文件

简介

A socket.io wrapper and middleware for react and redux apps. 展开 收起
JavaScript
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/cloudie/resocket.git
git@gitee.com:cloudie/resocket.git
cloudie
resocket
resocket
master

搜索帮助