Socket
Socket
Sign inDemoInstall

bfsocket.io

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bfsocket.io

bfsocket.io is WebSocket client


Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 17 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc