# websocket-js **Repository Path**: yushia/websocket-js ## Basic Information - **Project Name**: websocket-js - **Description**: websocket封装,更高效,可拓展,支持自动重连、手动销毁和多个连接 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-11-15 - **Last Updated**: 2023-05-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # websocket-easy-js > A client-websocket written in TypeScript for browser-applications. Focus is on simplicity, reliability and extensibility. > It provides convenient features to automatically reconnect, Support multiple connections at the same time and Manual destruction. ## install ``` npm install websocket-easy-js --save or yarn add websocket-easy-js ``` ## Usage ``` import { Socket } from 'websocket-easy-js' // 参数配置,见下面参数属性 let config = { .... } // 创建对象 this.wbSocket = new Socket(config) // 连接 this.wbSocket.connection() // 发送信息 this.wbSocket.sendMessage(message) //关闭(销毁) this.wbSocket.close() ... ``` ## config 对象属性说明 config对象中有以下属性 |属性 | 类型 | 默认值 | 描述 | |--|--|--|--| | url | string | null | 必填,链接的通道的地址 | | heartTime | number | 5000 | 心跳时间间隔 | | heartMsg |string | 'ping' | 心跳信息| | isReconnect | boolean | true | 是否自动重连 | | reconnectTime |number | 2000 | 重连时间间隔 | | reconnectCount | number | -1 | 重连次数 -1 则不限制 | | openCb | function |- | 连接成功的回调 | |closeCb | function | -| 关闭的回调 | |messageCb | function | - | 消息的回调 | | errorCb | function | - | 错误的回调 |