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

tube-socket

v1.0.5

Published

Your gateway to tubes.dev development

Downloads

13

Readme

TubeSocket

A library to support tubes! This wraps a WebSocket functionality and can be used as a websocket with some changes!

Instead of a URL you can just pass your room ID.

import TubeSocket from 'tube-socket';

const conn = new TubeSocket('F3A00E');

conn.addEventListener('message', (evt) => {
  const payload = JSON.parse(evt.data);
  switch(payload.action) {
    case 'chat_message':
      console.log(payload.message);
      break;
  }
});

Features

  • Reconnection. When disconnected, the library will automatically reconnect in 5 seconds and keep trying until a connection is made.
  • Direct Messages. The library adds functionality that will allow clients to directly message each other by using conn.sendJSONTo
  • Leadership. Since you can use tubes.dev without a backend, you need a single source of truth. This library adds a leadership algorithm to sync up the next feature

Installation

npm i tube-socket --save-dev

Constructor

  • TubeSocket(roomID) Returns a newly created TubeSocket object.

Properties

  • TubeSocket.isConnected A boolean value if the client is currently connected.
  • TubeSocket.isLeader A boolean value if the client is currently the leader of all the clients.
  • TubeSocket.clientCount A count of clients that are all connected to the current channel.
  • TubeSocket.onclose An event listener to be called when the connection is closed.
  • TubeSocket.onerror An event listener to be called when an error occurs.
  • TubeSocket.onmessage An event listener to be called when a message is received from the server.
  • TubeSocket.onopen An event listener to be called when the connection is opened.
  • TubeSocket.url The absolute URL of the TubeSocket.

Methods

  • TubeSocket.send(string) Enqueues data to be transmitted.
  • TubeSocket.sendJSON(object) Serializes an object before enqueing the data to be transmitted.
  • TubeSocket.sendJSONTo(client_id, object) Serializes an object and adding a to field, before enqueing the data to be transmitted
  • TubeSocket.sendJSONToLeader(object) Serializes an object and adding a to field directly to the leader, before enqueing the data to be transmitted

Events

Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface.

  • close Fired when a connection with a TubeSocket is closed. Also available via the onclose property
  • error Fired when a connection with a TubeSocket has been closed because of an error, such as when some data couldn't be sent. Also available via the onerror property.
  • message Fired when data is received through a TubeSocket. Also available via the onmessage property.
  • open Fired when a connection with a TubeSocket is opened. Also available via the onopen property.