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

qaap-barge

v2.0.1

Published

JSON-RPC client over WebSockets for Node.js

Downloads

27

Readme

GitHub license Build Status npm
NPM

qaap-barge

(deprecated - please use rpc-websockets)

Barge wraps the "websockets/ws" library providing JSON RPC 2.0 support on top.

Installation

npm install qaap-barge

Examples

var Barge = require('qaap-barge')

// instantiate Barge and connect to an RPC server
var ws = new Barge('ws://localhost:8080/rpc/1.0')

ws.on('open', function() {
  // call an RPC method with parameters
  ws.call('sum', [5, 3]).then(function(result) {
    require('assert').equal(result, 8)
  })

  // send a notification to an RPC server
  ws.notify('openedNewsModule')

  // subscribe to receive an event
  ws.subscribe('feedUpdated')

  ws.on('feedUpdated', function() {
    updateLogic()
  })

  // unsubscribe from an event
  ws.unsubscribe('feedUpdated')

  // close a websocket connection
  ws.close()
})

API

var Barge = require('qaap-barge')
var ws = new Barge('ws://localhost:8080/rpc/1.0')

new Barge(address[, options]) -> Barge

Instantiate a Barge client.

Parameters:

  • address {String}: The URL of the WebSocket server. Defaults to 'ws://localhost:8080/rpc/1.0'.
  • options {Object}: Client options that are also forwarded to ws.
    • autoconnect {Boolean}: Client autoconnect upon Barge class instantiation. Defaults to true.
    • reconnect {Boolean}: Whether client should reconnect automatically once the connection is down. Defaults to true.
    • reconnect_interval {Number}: Time between adjacent reconnects. Defaults to 1000.
    • max_reconnects {Number}: Maximum number of times the client should try to reconnect. Defaults to 5.

ws.call(method[, params]) -> Promise

Calls a registered RPC method on server. Resolves once the response is ready. Throws if an RPC error was received.

Parameters:

  • method {String}: An RPC method name to run on server-side.
  • params {Object|Array}: Optional parameter(s) to be sent along the request.

ws.notify(method[, params])

Sends a JSON-RPC 2.0 notification to server.

Parameters:

  • method {String}: An RPC method name to run on server-side.
  • params {Object|Array}: Optional parameter(s) to be sent along the request.

ws.subscribe(event) -> Promise

Subscribes for a defined event.

Parameters:

  • event {String}: Event name.

ws.unsubscribe(event) -> Promise

Unsubscribes from a defined event.

Parameters:

  • event {String}: Event name.

ws.close([code[, data]])

Closes a WebSocket connection gracefully.

Parameters:

  • code {Number}: Socket close code.
  • data {String}: Optional data to be sent to socket before closing.

Event: 'open'

Emits when the connection is opened and ready for use.

Event: 'error'

  • <Error>

Emits when a socket error is raised.

Event: 'close'

Emits when the connection is closed.

Event: <Notification>

  • <Object>

Emits a notification event a client has subscribed to once the server sends it.

Example:

ws.subscribe('feedUpdated')

ws.on('feedUpdated', handlerFunction)