@braind/adventure
Simple WebSocket client
Last updated 2 years ago by kocisov .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @braind/adventure 
SYNC missed versions from official npm registry.

Adventure npm Code Climate gzip size

Simple WebSocket client with dead-simple Redux integration

Installation

# yarn
yarn add @braind/adventure

# npm
npm install @braind/adventure --save

Usage

import adventureClient from '@braind/adventure';
import store from './redux/store';

const adventure = new adventureClient({
  debug: [boolean] default is false,
  handleError: [function] optional,
  handleMessage: [function] optional,
  maxReconectAttempts: [number] default is 3,
  reconnect: [boolean] default is false,
  reconnectInterval: [number] default is 5000ms,
  reduxDispatcher: [function] optional,
  responseType: [json, text] default is json,
  url: [string => 'ws://localhost:3000'] required
});

function handleMessage(message) {
  console.log(message);

  if (message === 'Ping' || message.type === 'Ping') {
    adventure.send('Pong');
  }
}

function reduxDispatcher(message) {
  const { type, data: payload } = message;

  switch(type) {
    case 'RECEIVED_INFO':
      store.dispatch({
        type: 'RECEIVED_INFO',
        payload
      });

    default:
      console.log('Received unspecified action type');
  }
}

const currentSocketNumber = adventure.socketNumber();
const nextSocketNumber = adventure.nextSocketNumber();
const lastSocketNumber = adventure.lastSocketNumber();

Current Tags

  • 0.2.6                                ...           latest (2 years ago)

7 Versions

  • 0.2.6                                ...           2 years ago
  • 0.2.5                                ...           2 years ago
  • 0.2.4                                ...           2 years ago
  • 0.2.3                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 7
This Month 10
Last Day 0
Last Week 2
Last Month 3
Dependencies (0)
None
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |