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

primus-socket.io-client

v2.0.0

Published

Legacy Socket.IO client for the browser and node.js

Downloads

14

Readme

primus-socket.io-client

Version npmBuild StatusDependenciesCoverage StatusIRC channel

This is a fork of the original Socket.IO client's 0.9 codebase. We've forked it to provide additional stability fixes. One of the main reasons we still maintain this fork is that using Socket.IO 1.0 inside of Primus doesn't make sense as Socket.IO 1.0 is just a wrapper around Engine.IO so it makes more sense for our users to use our engine.io transformer instead of supporting Socket.IO 1.0.

Sockets for the rest of us

The socket.io client is basically a simple HTTP Socket interface implementation. It looks similar to WebSocket while providing additional features and leveraging other transports when WebSocket is not supported by the user's browser.

var socket = io.connect('http://domain.com');
socket.on('connect', function () {
  // socket connected
});
socket.on('custom event', function () {
  // server emitted a custom event
});
socket.on('disconnect', function () {
  // socket disconnected
});
socket.send('hi there');

Recipes

Utilizing namespaces (ie: multiple sockets)

If you want to namespace all the messages and events emitted to a particular endpoint, simply specify it as part of the connect uri:

var chat = io.connect('http://localhost/chat');
chat.on('connect', function () {
  // chat socket connected
});

var news = io.connect('/news'); // io.connect auto-detects host
news.on('connect', function () {
  // news socket connected
});

Emitting custom events

To ease with the creation of applications, you can emit custom events outside of the global message event.

var socket = io.connect();
socket.emit('server custom event', { my: 'data' });

Forcing disconnection

var socket = io.connect();
socket.on('connect', function () {
  socket.disconnect();
});

Documentation

io#connect

io.connect(uri, [options]);
Options:
  • resource

    socket.io

    The resource is what allows the socket.io server to identify incoming connections by socket.io clients. In other words, any HTTP server can implement socket.io and still serve other normal, non-realtime HTTP requests.

  • transports

['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling']

A list of the transports to attempt to utilize (in order of preference).

  • 'connect timeout'
5000

The amount of milliseconds a transport has to create a connection before we consider it timed out.

  • 'try multiple transports'
true

A boolean indicating if we should try other transports when the connectTimeout occurs.

  • reconnect
true

A boolean indicating if we should automatically reconnect if a connection is disconnected.

  • 'reconnection delay'
500

The amount of milliseconds before we try to connect to the server again. We are using a exponential back off algorithm for the following reconnections, on each reconnect attempt this value will get multiplied (500 > 1000 > 2000 > 4000 > 8000).

  • 'max reconnection attempts'
10

The amount of attempts should we make using the current transport to connect to the server? After this we will do one final attempt, and re-try with all enabled transport methods before we give up.

Properties:
  • options

    The passed in options combined with the defaults.

  • connected

    Whether the socket is connected or not.

  • connecting

    Whether the socket is connecting or not.

  • reconnecting

    Whether we are reconnecting or not.

  • transport

    The transport instance.

Methods:
  • connect(λ)

    Establishes a connection. If λ is supplied as argument, it will be called once the connection is established.

  • send(message)

    A string of data to send.

  • disconnect

    Closes the connection.

  • on(event, λ)

    Adds a listener for the event event.

  • once(event, λ)

    Adds a one time listener for the event event. The listener is removed after the first time the event is fired.

  • removeListener(event, λ)

    Removes the listener λ for the event event.

Events:
  • connect

    Fired when the connection is established and the handshake successful.

  • connecting(transport_type)

    Fired when a connection is attempted, passing the transport name.

  • connect_failed

    Fired when the connection timeout occurs after the last connection attempt. This only fires if the connectTimeout option is set. If the tryTransportsOnConnectTimeout option is set, this only fires once all possible transports have been tried.

  • message(message)

    Fired when a message arrives from the server

  • close

    Fired when the connection is closed. Be careful with using this event, as some transports will fire it even under temporary, expected disconnections (such as XHR-Polling).

  • disconnect

    Fired when the connection is considered disconnected.

  • reconnect(transport_type,reconnectionAttempts)

    Fired when the connection has been re-established. This only fires if the reconnect option is set.

  • reconnecting(reconnectionDelay,reconnectionAttempts)

    Fired when a reconnection is attempted, passing the next delay for the next reconnection.

  • reconnect_failed

    Fired when all reconnection attempts have failed and we where unsuccessful in reconnecting to the server.

Contributors

Guillermo Rauch <[email protected]>

Arnout Kazemier <[email protected]>

License

MIT