Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cantonjs/promise-ws
A promise based WebSocket implementation for request-response processing
https://github.com/cantonjs/promise-ws
promise promise-ws socket websockets ws
Last synced: 2 months ago
JSON representation
A promise based WebSocket implementation for request-response processing
- Host: GitHub
- URL: https://github.com/cantonjs/promise-ws
- Owner: cantonjs
- License: mit
- Created: 2017-11-03T09:11:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-14T13:02:19.000Z (over 6 years ago)
- Last Synced: 2024-10-29T07:49:25.931Z (3 months ago)
- Topics: promise, promise-ws, socket, websockets, ws
- Language: JavaScript
- Homepage:
- Size: 156 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# promise-ws
[![Build Status](https://travis-ci.org/cantonjs/promise-ws.svg?branch=master)](https://travis-ci.org/cantonjs/promise-ws)
[![CircleCI](https://circleci.com/gh/cantonjs/promise-ws.svg?style=shield)](https://circleci.com/gh/cantonjs/promise-ws)
[![Build status](https://ci.appveyor.com/api/projects/status/q0rmv88vjfk8m2w5/branch/master?svg=true)](https://ci.appveyor.com/project/cantonjs/promise-ws/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/cantonjs/promise-ws/badge.svg?branch=master)](https://coveralls.io/github/cantonjs/promise-ws?branch=master)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
[![License](https://img.shields.io/badge/license-MIT_License-brightgreen.svg?style=flat)](https://github.com/cantonjs/promise-ws/blob/master/LICENSE.md)A promise based WebSocket implementation for Node.js. Built on top of [ws](https://github.com/websockets/ws)
## Table of Contents
- [Table of Contents](#table-of-contents)
- [Usage examples](#usage-examples)
- [Simple client](#simple-client)
- [Simple server](#simple-server)
- [Installation](#installation)
- [API Reference](#api-reference)
- [License](#license)## Usage examples
### Simple client
```js
import WebSocket from "promise-ws";(async function() {
const ws = await WebSocket.create("ws://www.host.com/path");ws.on("message", function incoming(data) {
console.log(data);
});await ws.send("something");
})();
```### Simple server
```js
import WebSocket from "promise-ws";(async function() {
const wss = await WebSocket.Server.create({ port: 8080 });wss.on("connection", async function connection(ws) {
ws.on("message", function incoming(message) {
console.log("received: %s", message);
});await ws.send("something");
});
})();
```## Installation
```bash
$ npm install promise-ws
```## API Reference
`promise-ws` API is almost the same with [ws](https://github.com/websockets/ws) except that:
- `websocket.ping([data[, mask]])` returns a promise
- `websocket.pong([data[, mask]])` returns a promise
- `websocket.send(data[, options])` returns a promise
- 🆕 `WebSocket.Server.create(options)`, returns a promise of listened `WebSocket.Server` instance
- 🆕 `WebSocket.create(options)`, returns a promise of opened `WebSocket` instanceFor more WebSocket API, please checkout the [API doc](https://github.com/websockets/ws/blob/master/doc/ws.md).
## License
MIT