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

soxx

v2.0.3

Published

The missing microlib for websocket communication in the browser

Downloads

5

Readme

soxx

:zap: The missing microlib for websocket communication in the modern web browser. :cake:

Provides connecting, disconnecting, writing, retrying and listening. Not much else.

Scope

In the interest of size and speed, the scope of this library extends to modern browsers only. Compatibility with older browsers that do not support websockets is not the aim or goal of this lib.

Installation

To install Soxx, you first need to get the lib either from the releases page or via NPM:

npm install soxx

Then, you can either include dist/soxx.js file in your html file as such:

<script src='path/to/soxx.js'></script>

or you can include it via broswerify:

var Soxx = require('soxx')

API

Create

To start a connection, you need to instatiate the lib:

var opts = {
  url:'ws://sockb.in/'
}
var websocket = new Soxx(opts)

Once instantiated, you can connect, assign listeners, and fire events back to the server.

Connect

var opts = {
  url:'ws://sockb.in/',
  onOpen: function(event){
    // do something here
  }
}
var websocket = new Soxx(opts)
websocket.connect()

Once the lib establishes a connection with the websocket server, it will fire onOpen as specified.

Disconnect

var opts = {
  url:'ws://sockb.in/',
  onClose: function(event){
    // do something here
  }
}
var websocket = new Soxx(opts)
websocket.connect()
websocket.disconnect()

Once when you fire disconnect, it will fire onClose as specified.

Write

var opts = {
  url:'ws://sockb.in/'
}
var websocket = new Soxx(opts)
websocket.connect()
var message = 'Hello World!'
websocket.write(message)

Note: message should only be a string.

Listen

var opts = {
  url:'ws://sockb.in/',
  onMessage: function(message){
    // do something with the message
  }
}
var websocket = new Soxx(opts)
websocket.connect()

The message will come in as a raw string, you'll need to do parsing on it as you prefer.

Error Handling & Retry

var opts = {
  url:'ws://sockb.in/',
  retry: {
    count: 5, // number of times to retry as a whole since instantiation
    delay: 1000 // time to wait before retrying connection
  },
  onRetry: function(){
    // do something (this is inline, don't do async here)
  },
  onError: function(eventt){
    // handle error the way you like
  }
}
var websocket = new Soxx(opts)
websocket.connect()

If the connection is dropped or if an error is sent, it will attempt to retry if there is a retry sub-object present.

Changelog

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning and Keep A Changelog.

v2.0.0 | 2016-04-29

branch: release/v2.0.0

REWRITE

This version bump is a complete rewrite. New API, new internals, new everything. Because YOLO.

v1.1.0 | 2015-07-21

branch: release/v1.1.0

| Type | Link | Description | | ---- | ---- | ----------- | | Added | #4 | Added off() functionality |

v1.0.0 | 2015-07-21

branch: release/v1.0.0

| Type | Link | Description | | ---- | ---- | ----------- | | Added | ba18c0c | Added initial files |

License

ISC