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 🙏

© 2025 – Pkg Stats / Ryan Hefner

socketgd

v1.0.12

Published

Guaranteed delivery for socket.io

Downloads

942

Readme

socketgd

Guaranteed delivery for socket.io. Works in node and in the browser.

Huh?

socketgd is a wrapper around socket.io sockets that provides reliable message delivery. It tracks messages sent over the socket, and waits for acks to be received from the other end indicating that the messages were handled successfully.

Client Usage

var SocketGD = require('socketgd').SocketGD;

// in the browser
// <script src="socketgd.js"></script>

// create the socket.io socket
var socket = io(url, config);

// wrap the socket with socketgd
var socketgd = new SocketGD(socket);

// use socketgd instead of the socket
socketgd.on('connect', function() {
  console.log("I'm connected!");
});

socketgd.send('I am sending you a message');
socketgd.emit('your-event', {hi: 'there'});

// ...lets assumes the socket gets disconnected before receiving an ack for 'your-event'
// and we created a new socket...

// set the new socket.
// the un-acked 'your-event' message will be silently sent again
socketgd.setSocket(newSocket);

Server Usage

var SocketGD = require('socketgd').SocketGD;
var socketgd = new SocketGD();

// socket.io server
io.on('connection', function(socket) {

  // set the underlying socket in socketgd.
  // if any already acked messages arrive they will be silently discarded
  socketgd.setSocket(socket);

  socketgd.on('message', function(message, ack, msgId) {
    console.log('Got message ' + message + ' with id ' + msgId);
    // finished handling the message, ack it
    ack();
  });

  socketgd.on('my-event', function(data, ack, msgId) {
    console.log('Got my-event ' + data + ' with id ' + msgId);
    // finished handling the event, ack it
    ack();
  });

});

Reconnection

If the underlying socket is configured for auto reconnect then socketgd will automatically send all un-acked messages to the server whenever the reconnect event is fired.

When the server receives messages it has already acked, they will silently be discarded.

Disconnection

If the underlying socket gets completely disconnected either because reconnect is turned off or socket.io gave up on reconnection attempts, then the application may create a new socket.io socket and provide it to the same socketgd instance to continue communication from the point it terminated.

Providing a new socket to a sockgetd instance initiates the same behavior as the reconnect event. See Reconnection

Server Side Considerations

When a client creates a new socket connection to replace a disconnected one, it's likely that the new socket will end up connecting to a different server instance than the one the client was previously connected to. In such cases, a new socketgd wrapper needs to be created in the server, and the last acked message id needs to be set in it.

socketgd's constructor (as well as the method setLastAcked) enables setting the last acked message id, so if any messages arrive multiple times they can be discarded. It's up to the application to share the last ack id between server instances, such as through redis.

License

The MIT License (MIT)

Copyright (c) 2015-2016 Capriza Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.