Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

queued-socket.io

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queued-socket.io

Socket.io client with offline queue

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
Maintainers
1
Weekly downloads
 
Created
Source

queued-socket.io

Build Status npm version Coverage Status

Socket.io client with offline queue

Installation

Install using npm:

NPM

npm install queued-socket.io

Basic Usage

const socket = require('queued-socket.io');

// Before there is a socket connection, add events. These will be queued and run after the connection is established.
socket.on('ping', () => console.log('ping'));
socket.on('disconnect', () => console.log('disconnected'));
socket.once('ping', () => console.log('One time ping'));
socket.emit('authentication', { token: 'loginToken' }, 1);

const options = {
  path: '/socket',
  transports: ['websocket']
};

const client = socket.connect('http://localhost:5000', options);

console.log(`Socket is ${socket.isConnected() ? 'connected' : 'disconnected'}`);

API Reference

Socket module

socket~getClient() ⇒

Retrieve the client

Kind: inner method of socket
Returns: socket.io client
Access: public

socket~isConnected() ⇒ Boolean

Check if the socket is connected

Kind: inner method of socket
Returns: Boolean - socket connection status
Access: public

socket~emit(event, data, priority)

Send an event to the socket, when the socket is not connected, add an emit event to the queue.

Kind: inner method of socket
Access: public

ParamTypeDefaultDescription
eventStringThe event name that needs to be added to the socket.
dataObjectThe data to send to the socket when the event is triggered.
priorityNumber2The priority of the event.

socket~on(event, callback, priority)

Wrapper around socket.on that adds priority and caching

Kind: inner method of socket
Access: public

ParamTypeDefaultDescription
eventStringThe event name that needs to be added to the socket.
callbackfunctionThe callback function that the sockets call when the event is triggered.
priorityNumber2The priority of the event.

socket~off(event, priority)

Wrapper around socket.off that adds priority and caching

Kind: inner method of socket
Access: public

ParamTypeDefaultDescription
eventStringThe event name that needs to be added to the socket.
priorityNumber2The priority of the event.

socket~once(event, callback, priority) ⇒

Wrapper around socket.once that adds priority and caching

Kind: inner method of socket
Returns: socket.io client
Access: public

ParamTypeDefaultDescription
eventStringThe event name that needs to be added to the socket.
callbackfunctionThe callback function that the sockets call when the event is triggered.
priorityNumber2The priority of the event.

socket~connect(uri, options) ⇒

Connect to socket.io, if socket is already connected, returns that socket.

Kind: inner method of socket
Returns: socket.io client
Access: public

ParamTypeDescription
uriStringThe connection uri of the host.
optionsObjectOptions object used by socket.io.

Events module

events~add(event, callback, priority)

Adds a socket event to the socket, when the socket is not connected, add the add event to the queue.

Kind: inner method of events
Access: public

ParamTypeDefaultDescription
eventStringThe event name that needs to be added to the socket.
callbackfunctionThe callback function that the sockets call when the event is triggered.
priorityNumber2The priority of the event.

events~once(event, callback, priority)

Adds a single run socket event to the socket, when the socket is not connected, add the once event to the queue.

Kind: inner method of events
Access: public

ParamTypeDefaultDescription
eventStringThe event name that needs to be added to the socket.
callbackfunctionThe callback function that the sockets call when the event is triggered.
priorityNumber2The priority of the event.

events~clear(priority)

Remove all socket events from the socket, when the socket is not connected, add the clear event to the queue.

Kind: inner method of events
Access: public

ParamTypeDefaultDescription
priorityNumber2The priority of the event.

events~get() ⇒ Array.<Object>

Retrieve all registered events

Kind: inner method of events
Returns: Array.<Object> - Registered events
Access: public

events~remove(event, priority)

Remove a socket event from the socket, when the socket is not connected, add a remove event to the queue.

Kind: inner method of events
Access: public

ParamTypeDefaultDescription
eventStringThe event name that needs to be added to the socket.
priorityNumber2The priority of the event.

Debug/logging

queued-socket.io makes use of debug. To see the output in the console run this in the console:

localStorage.debug = 'queued-socket.io*';

Contributing

Please submit all issues and pull requests to the anchorchat/queued-socket.io repository!

Tests

Run tests using npm test.

Releasing

Make sure your working directory is clean!

git checkout master && git fetch && git merge origin/master
npm run prepare
npm version <patch|minor|major> -m '<commit message containing changes for this release>'
git push origin master
git push --tags
npm publish

Support

If you have any problem or suggestion please open an issue here.

Keywords

FAQs

Package last updated on 11 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc