# gejianwebsocket

> 使用react-hooks封装的websocket方法

Latest version **0.1.7** (published 2023-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install gejianwebsocket
pnpm add gejianwebsocket
yarn add gejianwebsocket
bun add gejianwebsocket
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.7 |
| Published | 2023-04-03 |
| First published | 2023-04-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | WJF |
| Maintainers | gejianmuchen |

## Links

- npm: https://www.npmjs.com/package/gejianwebsocket
- npm.io page: https://npm.io/package/gejianwebsocket

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^16.14.0

## Recent versions

- 0.1.7 (latest) — 2023-04-03

## README

# SupWebsocket

### 基础介绍

本工具主要是以 ReactHooks 对 WebSocket 进行了一次封装，可以使用 Hooks 来使用 WebSocket。

### 安装

`npm install @supcon/websocket`

### 用法演示

```js
import useWebsocket from '@supcon/websocket/src';

function a() {
  const {
    wsData,  //返回参数
    readyState,  //运行状态
    closeWebSocket,  //关闭连接
    webSocketInit,  //启动连接
    reconnect,  //重连
  } = useWebsocket({
    socketUrl: `/websocket/supWs`,  //socket连接
    isReload: true;  //是否自动重连，默认true
    isLog: true;  //是否显示日志，默认不显示
  });
}
```

### API

_Params_

<table>
    <tr>
        <th>参数</th> 
        <th>说明</th> 
        <th>类型</th> 
        <th>默认值</th>    
    </tr>
    <tr>
        <td>socketUrl</td> 
        <td>socket连接</td> 
        <td>string</td> 
        <td>-</td> 
    </tr>
    <tr>
        <td>isReload</td> 
        <td>是否自动重连</td> 
        <td>boolean</td> 
        <td>true</td> 
    </tr>
    <tr>
        <td>isLog</td> 
        <td>是否显示日志</td> 
        <td>boolean</td> 
        <td>false</td> 
    </tr>
</table>

_Result_

<table>
    <tr>
        <th>参数</th> 
        <th>说明</th> 
        <th>类型</th> 
        <th>其他</th>    
    </tr>
    <tr>
        <td>wsData</td> 
        <td>返回参数</td> 
        <td>unknown</td> 
        <td>-</td> 
    </tr>
    <tr>
        <td>readyState</td> 
        <td>运行状态</td> 
        <td>{ key: number, value: string, message: error }</td> 
        <td>
      { key: 0, value: '正在链接中' }<br>
      { key: 1, value: '已经链接并且可以通讯' }<br>
      { key: 2, value: '连接正在关闭' }<br>
      { key: 3, value: '连接已关闭或者没有链接成功' }<br>
    </td> 
    </tr>
    <tr>
        <td>closeWebSocket</td> 
        <td>关闭连接</td> 
        <td>() => void</td> 
        <td>-</td> 
    </tr>
    <tr>
        <td>webSocketInit</td> 
        <td>启动连接</td> 
        <td>(url:string) => void</td> 
        <td>此处可以传入url，来覆盖初始化的url</td> 
    </tr>
    <tr>
        <td>reconnect</td> 
        <td>重连</td> 
        <td>() => void</td> 
        <td>-</td> 
    </tr>
</table>

---
_Source: https://npm.io/package/gejianwebsocket · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
