# fe-reconnect-websocket **Repository Path**: zeusTeam/fe-reconect-websocket ## Basic Information - **Project Name**: fe-reconnect-websocket - **Description**: 具有自动重连功能的 WebSocket - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-04-07 - **Last Updated**: 2022-05-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ReconnectWebSocket =================== 具有自动重连功能的 WebSocket ---------- 如何使用 ------------- cjs 标准: 引入 websocket.cmd.js var rws = new ReconnectingWebSocket(url) amd 标准: 引入 websocket.amd.js var rws = new require('./dist/websocket.amd.js').ReconnectingWebSocket(url) 在 TypeScript 中使用: 引入 src/websocket.ts import * as rws from './src/websocket.ts' let ws = new rws.ReconnectingWebSocket(url) 参数 -- 创建实例的时候支持传入三个参数 url, protocols, options url: 连接的地址 protocols: 数组或字符串,连接使用的协议 options: 连接设置,具体查看 src/websocket.ts 文件 第 43 行 方法 -- open: 打开连接,如果 automaticOpen 为 false. 则需要手动调用此方法 close: 关闭连接 refresh: 重新打开连接 send: 发送数据 事件 -- onopen: 连接成功 onclose: 断开连接 onconnecting: 连接中 onerror: 发生错误 onmessage: 收到信息 重新编译 -- npm install // 安装所有依赖,仅需要在首次使用的时候执行 npm i gulp-cli -g // 安装 gulp-cli ,仅需要在首次使用的时候执行 gulp // 每次重新编译的时候执行