# socute

> Small and simple routing system for websocket server and client

Latest version **0.1.0** (published 2018-02-09) · MIT license · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2018-02-09 |
| First published | 2018-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 129.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dima Pavlovsky |
| Maintainers | paloskin |

## Links

- npm: https://www.npmjs.com/package/socute
- Repository: https://github.com/dimapaloskin/socute
- Homepage: https://github.com/dimapaloskin/socute#readme
- Issues: https://github.com/dimapaloskin/socute/issues
- npm.io page: https://npm.io/package/socute

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [is-browser](https://npm.io/package/is-browser.md) ^2.0.1

## Recent versions

- 0.1.0 (latest) — 2018-02-09
- 0.0.4 — 2018-02-08
- 0.0.3 — 2018-02-08
- 0.0.2 — 2018-02-08

## README

# Socute

[![Build Status](https://travis-ci.org/dimapaloskin/socute.svg?branch=master)](https://travis-ci.org/dimapaloskin/socute)

> Small and simple routing system for websocket server and client (good with [sockette](https://github.com/lukeed/sockette))

## Install

```sh
npm install socute
```

## Usage

### Server

```js
const WebSocket = require('ws')
const { Server, send } = require('socute')

const handlers = {
  hello: () => {
    console.log('Hello received')
  },

  users: {
    ping: (sender, message) => {
      console.log('Request:', message.reason)
      send(sender, 'users/pong', { reason: 'pong' })
    }
  }
}

const wss = new WebSocket.Server({ port: 31337 })
const socute = new Server(wss, { handlers })

socute.on('connection', (socket, req) => {
  const { origin } = req.headers
  // Close unexpected connections
  if (origin !== 'http://localhost:1234') {
    socket.close()
  }
})
```

### Browser client

```js
const { Client, send } = require('socute')

const handlers = {
  users: {
    pong: (sender, message) => {
      console.log('Response:', message.reason)
    }
  }
}

const ws = new WebSocket('ws://localhost:31337')
const client = new Client(ws, { handlers })
client.on('open', () => {
  send(client, 'hello')
  send(client, 'users/ping', { reason: 'ping' })
})
```

---

MIT

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