New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

tube-socket

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tube-socket

Your gateway to tubes.dev development

latest
Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

websocket

FAQs

Package last updated on 21 May 2020

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