# node-websocket

> parse socket buffer, add event emitter and cookie id

Latest version **0.1.6** (published 2015-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-websocket
pnpm add node-websocket
yarn add node-websocket
bun add node-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.6 |
| Published | 2015-07-19 |
| First published | 2015-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | younger@blog.timehub.cc |
| Maintainers | youngerheart |
| Keywords | websocket, node |

## Links

- npm: https://www.npmjs.com/package/node-websocket
- Repository: git@github.com:youngerheart/websocket
- Homepage: https://github.com/youngerheart/websocket
- Issues: https://github.com/youngerheart/websocket/issues
- npm.io page: https://npm.io/package/node-websocket

## 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.6 (latest) — 2015-07-19
- 0.1.5 — 2015-07-19
- 0.1.4 — 2015-07-18
- 0.1.3 — 2015-07-18
- 0.1.2 — 2015-07-18
- 0.1.1 — 2015-07-18
- 0.1.0 — 2015-07-18
- 0.0.9 — 2015-07-16
- 0.0.8 — 2015-07-14
- 0.0.7 — 2015-07-14
- 0.0.6 — 2015-07-13
- 0.0.5 — 2015-07-11
- 0.0.4 — 2015-07-10
- 0.0.3 — 2015-07-10
- 0.0.2 — 2015-07-10
- … 1 more at https://npm.io/package/node-websocket/versions

## README

# websocket

parse socket buffer, add event emitter and cookie id

## download & install
    // in package.json
    "dependencies": {
      "node-websocket": ">=0.0.1"
    }
    $ npm install

## config & run
    
    // in your nodeserver file
    var ws = require('node-websocket').init;
    // bind events
    ws.on('connection', function(socket) {
      console.log(socket.id); // ID in cookie,key: socketId
      ws.on('join', function(data) {
        //send message
        socket.send('yes! it will send to frontend');
      });
    });

    // You should emit server's close event and delete socket object when frontend exit
    ws.on('close', function(socketId) {
      console.log('close ' + socketId);
      delete sockets[socketId];
    });
    
    // you need start server in the end
    ws.start(8000);

## emit in frondend
    // you need creat socket object first
    socket.send(JSON.stringify({
      event: 'join',
      data: {
        room: room
      }
    }));

## all arguments & events & methods

* Server.prototype.start(port)

* Server 'connection' event, emit when connect success, create socket object in callback

* Server 'close' event, emit when a socket ended, return socketId.

* Server.prototype.on(eventName, callback);

* Server.prototype.emit(eventName, data);

* socket.id, ID in cookie,key: socketId

* Socket.prototype.send(data);

* Socket.prototype.close(data);

## bug && suggestion?
[Tell Me Please~](https://github.com/youngerheart/websocket/issues)

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