# websocket-promise

> A promise-based websocket server

Latest version **1.0.1** (published 2015-08-22) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-08-22 |
| First published | 2015-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | steelbrain |
| Maintainers | steelbrain |

## Links

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

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) latest
- [sb-communication](https://npm.io/package/sb-communication.md) ^3.0.0

## Recent versions

- 1.0.1 (latest) — 2015-08-22
- 1.0.0 — 2015-08-22
- 0.0.3 — 2015-06-26
- 0.0.2 — 2015-06-26
- 0.0.1 — 2015-06-26

## README

WebSocket-Promise
===========
WebSocket-Promise is an extremely lightweight Promise wrapper for native HTML5 WebSockets written in JS. It provides an easy to use API on both the Browser and Server Side.

WebSocket-Promise internally uses [Le-Emitter][Le-Emitter] for the Browser-Sided event emitting part, You can replace it with an EventEmitter of your choice.

#### Hello World
Node
```js
var WebSocketP = require('websocket-promise')
var Server = new WebSocketP({port: 8090})
Server.onConnection(function(Client){
  Client.on('Hello', function(Job){
    console.log(Job.Message) // "World"
    Job.Response = 'World'
  })
})
```
Browser
```js
var Connection = new WebSocketP("ws://localhost:8090")
Connection.Request("Hello", "World").then(function(Response){
  console.log(Response) // "World"
})
```

#### API
```js
enum JobType = {Broadcast, Reply, Request}
type Job = shape(Type => JobType, SubType => string, Message => Mixed, ?ID => String, EXCHANGE => true)
class Server{
  constructor(Options: Object) // Available Options: https://github.com/websockets/ws/blob/master/lib/WebSocketServer.js#L25
  onConnection(Callback: Function<ServerClient>): void
  Broadcast(Type: String, Message: Any): void
}
class ServerClient{
  on(Type: String, Callback: Function): Disposable
  request(Type: String, Message): Promise
  terminate(): void
}
class WebSocketP{ // Available under same name in browser
  on(Type: String, Callback: Function): Disposable
  request(Type: String, Message): Promise
  terminate(): void
}
```

#### License
This project is licensed under the terms of MIT License. See the License file for more info.

[Le-Emitter]:https://github.com/steelbrain/Le-Emitter

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