# kk-websocket

> To make the same code work seamlessly on Node.js and the browser, the ws and WebSocket wrapper.

Latest version **0.1.9** (published 2018-04-03) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.9 |
| Published | 2018-04-03 |
| First published | 2018-03-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 33 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | @maxyh |
| Maintainers | maxyh |
| Keywords | kk-websocketa, websocket, ws, browser, node |

## Links

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

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) *
- [eventemitter3](https://npm.io/package/eventemitter3.md) *

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.9 (latest) — 2018-04-03
- 0.1.8 — 2018-04-02
- 0.1.7 — 2018-03-25
- 0.1.6 — 2018-03-25
- 0.1.5 — 2018-03-25
- 0.1.4 — 2018-03-23
- 0.1.3 — 2018-03-23
- 0.1.1 — 2018-03-23
- 0.1.0 — 2018-03-22

## README

# kk-websocket

[![Version npm](https://img.shields.io/npm/v/kk-websocket.svg)](https://www.npmjs.com/package/kk-websocket)
[![Linux Build](https://img.shields.io/travis/maxyh/kk-websocket/master.svg)](https://travis-ci.org/maxyh/kk-websocket)
[![Windows Build](https://ci.appveyor.com/api/projects/status/github/maxyh/kk-websocket?branch=master&svg=true)](https://ci.appveyor.com/project/maxyh/kk-websocket)
[![Coverage Status](https://coveralls.io/repos/github/maxyh/kk-websocket/badge.svg?branch=master)](https://coveralls.io/github/maxyh/kk-websocket?branch=master)

## ______Work in Progress. Not Complete.______

Wrapper of ws and WebSocket.

It uses:

- [ws](https://github.com/websockets/ws) on Node
- [global.WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
  in browsers

## Limitations

Before using this module you should know that
[`ws`](https://github.com/websockets/ws/blob/master/doc/ws.md#class-websocket)
is not perfectly API compatible with
[WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket),
you should always test your code against both Node and browsers.

Some major differences:

- no `Server` implementation in browsers

## Usage

You need to install both this package and [ws](https://github.com/websockets/ws):

```bash
> npm i kk-websocket ws
```

Then just require this package:

```js
const WebSocket = require('kk-websocket')

const ws = new WebSocket('wss://echo.websocket.org/', {
  origin: 'https://websocket.org'
});

ws.on('open', function open() {
  console.log('connected');
  ws.send(Date.now());
});

ws.on('close', function close() {
  console.log('disconnected');
});

ws.on('message', function incoming(data) {
  console.log(`Roundtrip time: ${Date.now() - data} ms`);

  setTimeout(function timeout() {
    ws.send(Date.now());
  }, 500);
});
```

## Files

- `.travis.yml`(Travis CI)
  `npm run coveralls`
- `package.json`(NPM)
  - prepublishOnly
    `nps test clean build`
  - coveralls
    `npm run coverage && ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info`
  - coverage
    ```bash
    istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec --exit
    ```
  - test
    `nps test`
  - start
    `nps`
- `package-scripts.js`(NPS)
  - build
  - lint
  - clean
  - test
    - node
    - browser
    - bundle
  - coveralls
  - prebuildDocs
  - buildDocs
  - postbuildDocs
  - prewatchDocs
  - watchDocs
- `karma.conf.js`(Karma)

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