# nextjs-websocket

> Reconnecting websocket which is NextJS Compatible

Latest version **1.0.11** (published 2023-01-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install nextjs-websocket
pnpm add nextjs-websocket
yarn add nextjs-websocket
bun add nextjs-websocket
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2023-01-01 |
| First published | 2021-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 30.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | alamorre |
| Maintainers | adam_lamorre |

## Links

- npm: https://www.npmjs.com/package/nextjs-websocket
- Repository: https://github.com/alamorre/nextjs-websocket
- Homepage: https://github.com/alamorre/nextjs-websocket#readme
- Issues: https://github.com/alamorre/nextjs-websocket/issues
- npm.io page: https://npm.io/package/nextjs-websocket

## Dependencies (1)

- [websocket](https://npm.io/package/websocket.md) ^1.0.33

## Recent versions

- 1.0.11 (latest) — 2023-01-01
- 1.0.10 — 2022-12-31
- 1.0.9 — 2022-12-31
- 1.0.8 — 2022-12-29
- 1.0.7 — 2021-10-13
- 1.0.6 — 2021-05-30
- 1.0.5 — 2021-05-30
- 1.0.4 — 2021-05-30
- 1.0.3 — 2021-05-30
- 1.0.2 — 2021-02-25
- 1.0.1 — 2021-02-25
- 1.0.0 — 2021-02-24

## README

# nextjs-websocket

`nextjs-websocket` is a easy-to-use NextJS component for websocket communications.

## Notes

If you need me to build something, just raise an issue:)

This was a fork from react-websocket so s/o to the devs there :)

### Installing

```
npm install --save nextjs-websocket
```

### Usage

```js
import React from 'react'
import { Websocket } from 'nextjs-websocket'

class ProductDetail extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      count: 90
    }
  }

  handleData(data) {
    let result = JSON.parse(data)
    this.setState({ count: this.state.count + result.movement })
  }

  render() {
    return (
      <div>
        Count: <strong>{this.state.count}</strong>
        <Websocket
          url='ws://localhost:8888/live/product/12345/'
          onMessage={this.handleData.bind(this)}
        />
      </div>
    )
  }
}

export default ProductDetail
```

### Properties

#### url

**required**
The url the websocket connection is listening to.

#### onMessage

**required**
The callback called when data is received. Data is `JSON.parse`'d

#### onOpen

The callback called when the connection is successfully opened.

#### onClose

The callback called when the connection is closed either due to server disconnect or network error.

#### debug

default: **false**
Set to **true** to see console logging

#### reconnect

default: **true**

accelerated reconnection time

## License

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmehmetkose%2Fnextjs-websocket.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmehmetkose%2Fnextjs-websocket?ref=badge_large)

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