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

react-native-socket.io-client

v1.4.8

Published

This version is a slightly modified version of the well-known `socket-io-client` in order to add React Native compatibility, including usage with real WebSockets as well as a fallback to long polling.

Downloads

146

Readme

react-native-socket.io-client

This version is a slightly modified version of the well-known socket-io-client in order to add React Native compatibility, including usage with real WebSockets as well as a fallback to long polling.

This repo will follow the normal socket.io client release cycle and will disappear as an underlying issue with the React Native packager disappears.

How to use

A standalone build of react-native-socket.io-client is exposed automatically by the socket.io server as /socket.io/socket.io.js. Alternatively you can serve the file socket.io.js found at the root of this repository.

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io('http://localhost');
  socket.on('connect', function(){});
  socket.on('event', function(data){});
  socket.on('disconnect', function(){});
</script>

Socket.IO is compatible with browserify.

API

IO(url:String, opts:Object):Socket

Exposed as the io namespace in the standalone build, or the result of calling require('socket.io-client').

When called, it creates a new Manager for the given URL, and attempts to reuse an existing Manager for subsequent calls, unless the multiplex option is passed with false.

The rest of the options are passed to the Manager constructor (see below for details).

A Socket instance is returned for the namespace specified by the pathname in the URL, defaulting to /. For example, if the url is http://localhost/users, a transport connection will be established to http://localhost and a Socket.IO connection will be established to /users.

IO#protocol

Socket.io protocol revision number this client works with.

IO#Socket

Reference to the Socket constructor.

IO#Manager

Reference to the Manager constructor.

IO#Emitter

Reference to the Emitter constructor.

Manager(url:String, opts:Object)

A Manager represents a connection to a given Socket.IO server. One or more Socket instances are associated with the manager. The manager can be accessed through the io property of each Socket instance.

The opts are also passed to engine.io upon initialization of the underlying Socket.

Options:

  • reconnection whether to reconnect automatically (true)
  • reconnectionAttempts (Infinity) before giving up
  • reconnectionDelay how long to initially wait before attempting a new reconnection (1000). Affected by +/- randomizationFactor, for example the default initial delay will be between 500 to 1500ms.
  • reconnectionDelayMax maximum amount of time to wait between reconnections (5000). Each attempt increases the reconnection delay by 2x along with a randomization as above
  • randomizationFactor (0.5), 0 <= randomizationFactor <= 1
  • timeout connection timeout before a connect_error and connect_timeout events are emitted (20000)
  • autoConnect by setting this false, you have to call manager.open whenever you decide it's appropriate

Events

  • connect_error. Fired upon a connection error. Parameters:
    • Object error object
  • connect_timeout. Fired upon a connection timeout.
  • reconnect. Fired upon a successful reconnection. Parameters:
    • Number reconnection attempt number
  • reconnect_attempt. Fired upon an attempt to reconnect.
  • reconnecting. Fired upon an attempt to reconnect. Parameters:
    • Number reconnection attempt number
  • reconnect_error. Fired upon a reconnection attempt error. Parameters:
    • Object error object
  • reconnect_failed. Fired when couldn't reconnect within reconnectionAttempts
  • ping. Fired when a ping packet is written out to the server.
  • pong. Fired when a pong is received from the server. Parameters:
    • Number number of ms elapsed since ping packet (i.e.: latency).

The events above are also emitted on the individual sockets that reconnect that depend on this Manager.

Manager#reconnection(v:Boolean):Manager

Sets the reconnection option, or returns it if no parameters are passed.

Manager#reconnectionAttempts(v:Boolean):Manager

Sets the reconnectionAttempts option, or returns it if no parameters are passed.

Manager#reconnectionDelay(v:Boolean):Manager

Sets the reconectionDelay option, or returns it if no parameters are passed.

Manager#reconnectionDelayMax(v:Boolean):Manager

Sets the reconectionDelayMax option, or returns it if no parameters are passed.

Manager#timeout(v:Boolean):Manager

Sets the timeout option, or returns it if no parameters are passed.

Socket

Socket#id:String

A property on the socket instance that is equal to the underlying engine.io socket id.

The property is present once the socket has connected, is removed when the socket disconnects and is updated if the socket reconnects.

Socket#compress(v:Boolean):Socket

Sets a modifier for a subsequent event emission that the event data will only be compressed if the value is true. Defaults to true when you don't call the method.

  socket.compress(false).emit('an event', { some: 'data' });

Events

  • connect. Fired upon a connection including a successful reconnection.
  • error. Fired upon a connection error Parameters:
    • Object error data
  • disconnect. Fired upon a disconnection.
  • reconnect. Fired upon a successful reconnection. Parameters:
    • Number reconnection attempt number
  • reconnect_attempt. Fired upon an attempt to reconnect.
  • reconnecting. Fired upon an attempt to reconnect. Parameters:
    • Number reconnection attempt number
  • reconnect_error. Fired upon a reconnection attempt error. Parameters:
    • Object error object
  • reconnect_failed. Fired when couldn't reconnect within reconnectionAttempts

License

MIT