New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

websocket-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket-as-promised

Promise-based WebSocket wrapper

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1K
decreased by-56.9%
Maintainers
1
Weekly downloads
 
Created
Source

websocket-as-promised

Build Status npm license

Promise-based W3C WebSocket wrapper

Installation

npm install websocket-as-promised --save

Usage in browser

const WebSocketAsPromised = require('websocket-as-promised');

const wsp = new WebSocketAsPromised();
wsp.open('ws://echo.websocket.org')
  .then(() => wsp.send({foo: 'bar'}))
  .then(response => console.log(response.id))
  .then(() => wsp.close())
  .catch(e => console.error(e));

Usage in Node.js

As there is no built-in WebSocket client in Node.js, you should use a third-party module. The most popular W3C compatible solution is websocket:

const W3CWebSocket = require('websocket').w3cwebsocket;
const WebSocketAsPromised = require('websocket-as-promised');

const wsp = new WebSocketAsPromised({WebSocket: W3CWebSocket});
wsp.open('ws://echo.websocket.org')
  .then(...)

API

new WebSocketAsPromised(options)
  /**
   * Constructor
   *
   * @param {Object} [options]
   * @param {String} [options.idProp="id"] id property name attached to each message
   * @param {Object} [options.WebSocket=WebSocket] custom WebSocket constructor
   */
.open(url)
  /**
   * Open WebSocket connection
   *
   * @param {String} url
   * @returns {Promise}
   */
.send(data)
  /**
   * Send data and wait for response containing `id` property
   *
   * @param {Object} data
   * @returns {Promise}
   */
.close()
  /**
   * Close WebSocket connection
   *
   * @returns {Promise}
   */
.ws
  /**
   * Returns raw WebSocket instance
   *
   * @returns {WebSocket}
   */

License

MIT @ Vitaliy Potapov

Keywords

FAQs

Package last updated on 23 Jun 2017

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc