npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rpep-websockets

v1.1.4

Published

Websocket transport for rpep.js

Downloads

9

Readme

rpep-websockets

This is a Websocket transport for rpep.js using theturtle32/WebSocket-Node. RPEP is a simple, light-weight protocol for request-response and stream-event style communication between peers.

Install

yarn install rpep-websockets

Usage

Accessing rpep websockets:

// node.js
var rpepWebsockets = require('rpep-websockets')

// node.js style for the browser (eg webpack)
var rpepWebsockets = require('rpep-websockets/ws.browser')

// amd
require.config({paths: {rpepWebsockets: '../dist/rpep-websockets.umd.js'}})
require(['rpepWebsockets'], function(rpepWebsockets) { /* your code */ })

// global variable
<script src="rpep-websockets.umd.js"></script>
rpepWebsockets; // rpep-websockets.umd.js can define rpepWebsockets globally if you really
             //   want to shun module-based design

API:

  • var transport = rpepWebsockets() - Creates a new instance of the transport (to be passed into rpep's constructor).

  • transport.connect(host, port, [connectionOptions,] rpepOptions) - Connects to a websocket host. These arguments will be passed through to this method from a call to rpep.connect.

    • connectionOptions for node.js - These are theturtle32/WebSocket-Node WebSocketClient options. Important ones being:
      • protocol - (Default: 'ws') Either 'wss' or 'ws'
      • wsProtocols - A string or array of strings representing the websocket-protocols to request.
      • origin
      • headers
      • requestOptions
    • connectionOptions for the browser:
      • binaryType - The binaryType property of a websocket connection. Defaults to "arraybuffer", which is what the theturtle32/WebSocket-Node library used for node.js requires.
      • protocol - (Default: 'ws') Either 'wss' or 'ws'.
    • rpepOptions are pass through arguments that don't affect the operation of this transport.
  • transport.listen(port, [listenerOptions,] rpepOptions, requestHandler) - Listens for websocket connections. These arguments will be passed through to this method from a call to rpep.listen. This method only exists for the node.js version. You can't listen for websocket connections from a browser.

    • port - Optional if listenerOptions.httpServer is passed.
    • listenerOptions- These are theturtle32/WebSocket-Node WebSocketServer options. Important ones being:
      • secure - (Default:false) If true and transportOptions.httpServer is undefined, will create an https server. If transportOptions.httpServer is defined, this is ignored.
      • secureOptions - The options to pass into https.createServer if secure is true.
      • httpServer - If this is defined, uses this server instead of creating a new one. The passed port won't be used. If no http/https server is passed, one will be created internally (http or https is determined by arguments passed to listen). For the browser, there are no transportOptions so none need be passed.
      • httpHandler(request, response) - If this is defined, it is a callback that's called when a normal http/https request comes through.
    • rpepOptions are pass through arguments that don't affect the operation of this transport.

How to Test

  • Test for node: node test/test.node
  • Test for browsers: node test/testServer

License

Released under the MIT license: http://opensource.org/licenses/MIT