Package Exports
- promise-ws
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promise-ws) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
promise-ws
A promise based WebSocket implementation for Node.js. Built on top of ws
Table of Contents
Usage examples
Simple client
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
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
$ npm install promise-wsAPI Reference
promise-ws API is almost the same with ws except that:
websocket.ping([data[, mask]])returns a promisewebsocket.pong([data[, mask]])returns a promisewebsocket.send(data[, options])returns a promise- 🆕
WebSocket.Server.create(options), returns a promise of listenedWebSocket.Serverinstance - 🆕
WebSocket.create(options), returns a promise of openedWebSocketinstance
For more WebSocket API, please checkout the API doc.
License
MIT