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

ewents-scan

v1.0.2

Published

This guide provides an example of how to use the `RTCScan` class to manage connections and handle data during a scan session. Below, you'll find installation instructions, initialization options, and method explanations.

Downloads

234

Readme

ewents-scan

This guide provides an example of how to use the RTCScan class to manage connections and handle data during a scan session. Below, you'll find installation instructions, initialization options, and method explanations.

Demo: https://scan.ewents.io/ Video Demo: https://youtu.be/tXeCPb_CR0A

Installation

First, make sure to install the ewents-scan package:

npm install ewents-scan

Using the RTCScan Class

The RTCScan class provides several options and methods to retrieve connection details, monitor connection status, and handle received data.

RTCScan Initialization Options

const rtcscan = new RTCScan('66760d2b14813c0e8b53b4ff', {
  maxFeedback: 10,            // Max number of feedback allowed
  throttleInterval: 2000,      // Time between each scan event (in ms)
  feedbackDuration: 10000,     // Duration of feedback in milliseconds
  isAutoReconnect: true,       // Automatically reconnect if disconnected
}, {
  allowShortUrl: false,        // If true, allows generating a short URL with TTL
  isLog: true,                 // Enables logging for debugging purposes
  shortUrlTTL: 300             // Time-to-live for the short URL in seconds
});

Options Explained:

  • maxFeedback: Maximum number of feedback events allowed.
  • throttleInterval: Minimum interval (in milliseconds) between each scan event.
  • feedbackDuration: Duration for which feedback is active.
  • isAutoReconnect: Automatically reconnect if the connection is lost.

Advanced Configuration

The advanced configuration object includes:

  • allowShortUrl: Allows generating a short URL with a specified TTL (in seconds) for temporary connections.
  • isLog: Enables logging for debugging and monitoring.
  • shortUrlTTL: TTL (in seconds) for the short URL, after which it expires.

Methods

1. Getting Connection Details (with optional QR size)

const { qrImage, url } = await rtcscan.getConnectionDetail(300);

Retrieves the QR code URL (qrImage) and the connection URL (url). Optionally, you can pass qrPxSize to adjust the QR code size (default is 300 pixels).

2. Handling Received Data

rtcscan.onDataReceived((value) => {
  return {
    type: 'success' | 'error',  // Indicates the type of response
    message: 'This is a message',  // The message to be sent
  };
});

Listens for incoming data. You can return a type ('success' or 'error') and a message, though this is optional.

3. Monitoring Connection Status

rtcscan.onIsConnecting(() => setIsLoading(true));
rtcscan.onIsConnected(() => setIsConnected(true));
  • onIsConnecting: Triggered when the session is connecting.
  • onIsConnected: Triggered when the connection is successfully established.

4. Reconnect Functionality

rtcscan.reConnect();

Attempts to manually re-establish the connection if it is lost.

5. Getting the Session ID

const sessionId = rtcscan.getSession();
rtcscan.getSession((id) => console.log(id));  // Optionally pass a callback

Returns the session ID, with an optional callback for handling it when available.

6. Starting Connection with a URL

rtcscan.startConnectionWithUrl('https://scan.ewents.io/connection-url');

Initiates the connection using a specified URL (short or long), allowing flexibility in the URL format.


This overview covers the key methods and options of the RTCScan class, providing control over connection handling, received data, and session management.