Socket
Socket
Sign inDemoInstall

promise-ws

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-ws

A Promise-Based WebSocket implementation for Node.js


Version published
Weekly downloads
5.7K
decreased by-16.94%
Maintainers
1
Weekly downloads
 
Created

Readme

Source

promise-ws

Build Status CircleCI Build status Coverage Status PRs Welcome License

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-ws

API Reference

promise-ws API is almost the same with 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 instance

For more WebSocket API, please checkout the API doc.

License

MIT

Keywords

FAQs

Package last updated on 14 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc