8000 GitHub - SanchezSeba/resocket: A socket.io wrapper and middleware for react and redux apps.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

SanchezSeba/resocket

 
 

Repository files navigation

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

About

A socket.io wrapper and middleware for react and redux apps.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%
0