Giter VIP home page Giter VIP logo

socket.io-client's Introduction

This Readme corresponds to the upcoming 1.0 release. Please refer to http://socket.io for the current 0.9.x documentation.

socket.io-client

Build Status

How to use

A standalone build of 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 also compatible with component and browserify.

Node.JS (server-side usage)

Add socket.io-client to your package.json and then:

var socket = require('socket.io-client')('http://localhost');
socket.on('connect', function(){
  socket.on('event', function(data){});
  socket.on('disconnect', function(){});
});

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)
  • reconnectionDelay how long to wait before attempting a new reconnection (1000)
  • reconnectionDelayMax maximum amount of time to wait between reconnections (5000). Each attempt increases the reconnection by the amount specified by reconnectionDelay.
  • timeout connection timeout before a connect_error and connect_timeout events are emitted (10000)

Events

  • connect. Fired upon a successful connection.
  • 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_error. Fired upon a reconnection attempt error. Parameters:
    • Object error object
  • reconnect_failed

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

Events

  • connect. Fired upon connecting.
  • error. Fired upon a connection error Parameters:
    • Object error data
  • disconnect. Fired upon a disconnection.

License

MIT

socket.io-client's People

Contributors

3rd-eden avatar bmalehorn avatar chadwhitacre avatar crickeys avatar danielbeardsley avatar defunctzombie avatar dget avatar diegovar avatar dvv avatar einaros avatar fat avatar fat-bot avatar felixge avatar gabehollombe avatar gavinuhma avatar getify avatar grant avatar haykokoryun avatar jdahlq avatar joaojeronimo avatar jugglinmike avatar kevin-roark avatar kreichgauer avatar mixu avatar pgherveou avatar rauchg avatar sfilatov avatar stevesanderson avatar ycarmel avatar zzzaaa avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.