socket.io client api

Client API

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

Exposed as the io global in window if using the standalone build (eg: /socket.io/socket.io.js or the CDN), 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. Passing this option is the equivalent of passing 'force new connection': true.

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

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)

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 (20000)

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_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

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

Events

  • connect. Fired upon connecting.
  • 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值