Giter Site home page Giter Site logo

ajaxssesocket's People

Contributors

smart--petea avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ajaxssesocket's Issues

Socket#emit(name:String[, ...]):Socket

Emits an event to the socket identified by the string name. Any other parameters can be included.

All datastructures are supported, including `Buffer. JavaScript functions can't be serialized/deserialized.

var io = require('socket.io')();
io.on('connection', function(socket) {
  socket.emit('an event', { some: 'data'});
});

Socket#join(name:String[, fn:Function]):Socket

Adds the socket to the room, and fires optionally a callback fn with err signature (if any).

The socket is automatically a member of a room identified with its session id (see Socket#id).

The mechanics of joining rooms are handled by the Adapter that has been configured (see Server#adapter above), defaulting to socket.io-adapter.

Server#serveClient(v:Boolean):Server

if v is true the attached server (see Server#attach) will serve the clients files. Defaults to true.

This method has no effect after attach is called.

//pass a server ad the `serveClient` option
var io = require('socket.io')(http, { serveClient: false});

//or pass no server and then you can call the method
var io = require('socket.io')();
io.serveClient(false);
io.attach(http);

If no arguments are supplied this method returns the urrent value.

Server()

Creates a new Server. Works with and without new:

var io = require('socket.io')();
//or
var Server = require('socket.io');
var io = new Server();

Namespace

Represents a pool of sockests connected under a given scope identified by a pathname (eg: /chat).

By default the client always connects to /.

minify function

create a github project wich will give you the possiblitiy to minify javascript.

Server#adapter(v:Adapter):Server

Sets the adapter v. Defaults to an instance of the Adapter that ships with socket.io which is memory based. Se socket.io-adapter.

If no arguments are suppliet this method returns the current value.

Socket#request:Request

A getter proxy that returns the reference to the request that originated the underlying engine.io Client. Useful for accessing request headers such as Cookie or User-Agent

Server

Exposed by require('socket.io')

Socket

A Socket is the fundamental class for interacting with browser clients. A Socket belongs to a certains Namespace (by default /) and uses an underlying Client to communicate.

Server#path(v:String):Server

Sets the path v under which engine.io and the satic files will be served. Defaults to /socket.io

If no arguments are supplied this method returns the current value.

server connection like socket.io server

socket.io server have two different approach when is instantiate

  1. it is attached to an http server
var http = require('http');
var app = http.createServer(handler);
app.listen(8080)

var io = require('socket.io')(app)
  1. or it create a server on port
var io = require('socket.io')(8080)
  1. or
var IoServer = require('socket.io')
var io = IoServer.listen(8080)
  1. or
var IoServer = require('socket.io')
var io = new IoServer(8080)

Implement this behaviour. hint:

function Server() { ... }
Server.prototoype.listen = Server;

Client#conn

A reference to the underlying engine.io Socket connection

Socket#to(room:String):Socket Socket#in(room:String):Socket

Sets a modifier for a subsequent event emission that the event will only be broadcasterd to sockets that have joined the given room.

To emit to multiple rooms, you can call to several times.

var io = require('socket.io')();
io.on('connection', function(socket) {
  socket.to('others').emit('an event', { some: 'data'});
});

Socket#leave(name:String[, fn:Function]):Socket

Removes the socket from room, and fires optionally a callback fn with err signature (if any)

Rooms are left autmoatically upon disconnection.

The mechanics of leaving rooms are handled by the Adapter that has been configured (see Server#adapter above), defaulting to socket.io-adapter

Server#of(nsp:String):Namespace

Initializes and retrieves the given Namespace by its pathname identifier nsp.

If the namespace was already initialized it returns it right away.

Socket#conn:Socket

a reference to the underlying Client transport connection (engine.io Socket object)

Socket#id:String

A unique identifier for the socket session, that comes from the underlying Client

Namespace#use(fn:Function):Namespace

Registes a middleware, which is a function that gets executed for every incoming Socket and receives as parameter the socket and a function to optionally defer execution to the next registered middleware

var io = require('socket.io')();
io.use(function(socket, next) {
  if(socket.request.headers.cookie) return next();
  next(new Error('Authentication error'));
});

Errors passed to middleware callbacks are sent as special error packets to clients

Server#emit

Emits an event to all connected clients. The following two are equivalent:

var io = require('socket.io')();
io.sockets.emit('an event sent to all connected clients');
io.emit('an event sent to all connected clients');

For other available methods, see Namespace below

Client

The Client class represnts an incoming transport (engine.io) connection. A Client ca be associated with many multiplexed Socket that belong to different Namespaces

Client#request

A getter proxy that returns the reference tho the request that originated the engine.io connection. Useful for accesing request headers such as Cookie or User-Agent.

Server(opts: Object)

Optionally, the first or second argument see bellow) of the Server constructor cab be an options object.

The following options are supported:

  1. serveClient sets the value for Server#serveClient()
  2. path setsh the value for Server#path()

The same options passed to socket.io are always passed to the engine.io Server that gets created. See engine.io options as reference.

Server#origins(v:String):Server

Sets the allowed origins v. Defaults to any origiins being allowed.

If no arguments are supplied this method returns the current value.

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.