1.0.1 • Published 5 years ago

meeek-websocket v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

ReSocket

一个JS库,装饰提供连接的WebSocket API,当连接掉线,它将自动重新连接

var ws = new ReSocket('ws://....');

USE

1. 实例化时当作构造函数的参数传入

const socket = new ReSocket(url, protocols, options);

2. 实例化后当作属性设置参数

const socket = new ReSocket(url);
socket.debug = true;
socket.timeoutInterval = 5400;

Options

debug

  • 是否应该记录调试消息,消息被打印到 console.debug().
  • 参数:true or false
  • 默认值:false

automaticOpen

  • 是否在实例化后立即尝试连接. 可以随时使用ws.open()ws.close()打开或关闭连接.
  • 参数:true or false
  • 默认值:true

reconnectInterval

  • 尝试重新连接之前要延迟的毫秒数。
  • 参数:integer
  • 默认值:1000

maxReconnectInterval

  • 尝试重新连接的最大延迟毫秒数
  • 参数:integer
  • 默认值:30000

####reconnectDecay

  • 重新连接延迟的增加速率。【本次10s没有连接上,下次连接时间为15秒】
  • 参数:integer or float
  • 默认值:1.5

timeoutInterval

  • 连接超时时间(以毫秒为单位)。
  • 参数:integer
  • 默认值:2000

maxReconnectAttempts

  • 最大重新连接次数。如果为null将一直重新连接。
  • 参数:integer or null.
  • 默认值:null

binaryType

  • 二进制传输类型
  • 参数:'blob' or 'arraybuffer'.
  • 默认值:'blob'

Methods

ws.open()

  • 打开连接

ws.close(code, reason)

ws.refresh()

  • 如果仍然打开,请刷新连接(先关闭然后重新打开),For example, if the app suspects bad data / missed heart beats, it can try to refresh.

ws.send(data)

  • 通过WebSocket连接将数据传输到服务器。
  • 参数:'String' or 'arraybuffer' or 'blob'
1.0.2

5 years ago

1.0.1

5 years ago