npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

queued-socket.io

v1.0.5

Published

Socket.io client with offline queue

Downloads

16

Readme

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

| Param | Type | Default | Description | | --- | --- | --- | --- | | event | String | | The event name that needs to be added to the socket. | | data | Object | | The data to send to the socket when the event is triggered. | | priority | Number | 2 | The 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

| Param | Type | Default | Description | | --- | --- | --- | --- | | event | String | | The event name that needs to be added to the socket. | | callback | function | | The callback function that the sockets call when the event is triggered. | | priority | Number | 2 | The priority of the event. |

socket~off(event, priority)

Wrapper around socket.off that adds priority and caching

Kind: inner method of socket
Access: public

| Param | Type | Default | Description | | --- | --- | --- | --- | | event | String | | The event name that needs to be added to the socket. | | priority | Number | 2 | The 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

| Param | Type | Default | Description | | --- | --- | --- | --- | | event | String | | The event name that needs to be added to the socket. | | callback | function | | The callback function that the sockets call when the event is triggered. | | priority | Number | 2 | The 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

| Param | Type | Description | | --- | --- | --- | | uri | String | The connection uri of the host. | | options | Object | Options 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

| Param | Type | Default | Description | | --- | --- | --- | --- | | event | String | | The event name that needs to be added to the socket. | | callback | function | | The callback function that the sockets call when the event is triggered. | | priority | Number | 2 | The 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

| Param | Type | Default | Description | | --- | --- | --- | --- | | event | String | | The event name that needs to be added to the socket. | | callback | function | | The callback function that the sockets call when the event is triggered. | | priority | Number | 2 | The 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

| Param | Type | Default | Description | | --- | --- | --- | --- | | priority | Number | 2 | The 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

| Param | Type | Default | Description | | --- | --- | --- | --- | | event | String | | The event name that needs to be added to the socket. | | priority | Number | 2 | The 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.