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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rbbn/distant

v1.2.0

Published

Control distant applications.

Downloads

117

Readme

Distant

The Distant library is used to control a remote browser-type application via an arbitrary channel.

Features

  • Create remote sessions
  • Monitor remote sessions
  • Send and receive custom user defined messages from the remote session.

Installation

Install using npm:

npm install @distant/distant

or yarn:

yarn add @distant/distant

Basic Usage

To get started, you need to create a controller that is connected to a remote agent.

import { createController } from '@distant/distant'
import { createConnection } from '@distant/distant-web'

const distantWebConnection = createConnection()

const controller = createController(distantWebConnection)

// ... Use the controller

Note that the connection and the controller are maintained separately, it is up to the application to monitor the connection and re-establish the connection if it goes down or fails.

Once we have created the controller we can start by creating a session.

async function startSession(sessionId) {
  try {
    const session = await controller.createSession({
      id: sessionId, // Session id must be an integer
      url: 'https://remoteapp.url',
      timeout: 2000
    })

    // Session is created.
    return session
  } catch (err) {
    console.error(err)
  }
}

With the session we can then start sending and receiving messages. First though we need to register some event listeners in order to get notified of the status of the session as well as messages.

function registerSession(session) {
  session.on('changed', event => {
    // Handle session changed events
  })

  session.on('closed', event => {
    // Handle session closed events
  })

  session.on('message', event => {
    // Handle session message events
  })
}

Now to send a message to the session we simply call session.sendMessage.

function sendMessage(session, message) {
  // In order to send a message we must first encode into a byte array.
  const encoder = new TextEncoder()
  const encodedMessage = encoder.encode(JSON.stringify(message))

  session.sendMessage(encodedMessage)
}

Note: Encoding and decoding is application specific. Distant only deals with Uint8Array (Byte arrays) for messages. Here we use JSON messages encoded with the TextEncoder for example.

Receiving messages works much the same way.

session.on('message', payload => {
  const decoder = new TextDecoder()
  const message = JSON.parse(decoder.decode(payload))

  // Application specific message handling goes here.
})