bfsocket.io
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

BFSocket.IO

Realtime application framework client

How to installtion?

# yarn
yarn add bfsocket.io -S --registry=https://registry.npmjs.org/

# npm
npm i bfsocket.io -S --registry=https://registry.npmjs.org/

How to use?

import SocketIO from 'bfsocket.io';

const io = new SocketIO({
  url:'ws://example.com',
  heart: {
    data:{},
    delay: 5000
  }
  ......
})

io.on('your cmd', data => {
  console.log(data)
});

io.emit('your cmd', {});

instantiation options

  • url

    • Socket server URL
    • 要链接socket服务的URL
  • protocols

    • A protocol string or an array containing protocol strings
    • 一个协议字符串/一个包含协议字符串的数组。这些字符串用于指定子协议,这样单个服务器可以实现多个WebSocket子协议(例如,您可能希望一台服务器能够根据指定的协议(protocol)处理不同类型的交互)。如果不指定协议字符串,则假定为空字符串
  • heart

    • Socket send heart data
    • 发送 socket 心跳包
  • heart.data

    • heart data
    • 心跳包数据
  • heart.delay

    • Set how often to send in milliseconds
    • 设置多久发送一次 单位 毫秒
  • session

    • Socket session
  • uniqueid

    • Socket uniqueid (Automatically generated by default)
    • Socket 唯一身份ID (默认自动生成)
  • remillisecond

    • Socket reconnect interval. default 1000ms
    • Socket 重连间隔 单位 ms 默认 1000ms
  • reconnectlimit

    • The maximum number of Socket reconnections. default 10
    • Socket 最大重连次数 默认 10 次

functions

  • io.on<T extends unknown>(event: string, cb: (data: T) => void): void

    • Listen for socket server events
    • 监听socket服务端事件
  • io.emit(event: string, data: SocketIODispatchParams): void

    • Trigger socket server event
    • 触发socket服务端事件
  • io.setHeartData(data: SocketIODispatchParams): void

    • Set heart data
    • 设置心跳发送的数据
  • io.close():void

    • Closed Socket connect and disable reconnect
    • 手动关闭连接 并 停止重连
  • HOOK

    • io.onConnected(fn:() => void)
      • Socket connecnted event
    • io.onDistory(fn: () => void)
      • Socket close event

Package Sidebar

Install

npm i bfsocket.io

Weekly Downloads

6

Version

0.3.0

License

MIT

Unpacked Size

15.4 kB

Total Files

9

Last publish

Collaborators

  • yoneyy