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

@lookingglass/bridge

v0.0.8-alpha.4

Published

Official Looking Glass Library for interacting with Looking Glass holographic displays.

Downloads

22

Readme

Warning Under active development, function signatures and API endpoints may be changed abruptly

🌉 bridge.js

The Bridge.JS library provides an easy way to connect to and leverage all the awesome functionality in Looking Glass Bridge. There are a few key features, including:

  • Casting a hologram to Bridge
  • Casting a Playlist to Bridge
  • Controlling Playback of Holograms & Playlists
  • Editing Parameters of Holograms that are displayed in Bridge

Table of contents

Requirements

Bridge 2.2 or newer.

Note For live examples, checkout our demo site here

Installation

You can import the library via a script tag or via npm. The Bridge.JS library is published to npm here

npm install @lookingglass/bridge

# or install with yarn
yarn add @lookingglass/bridge

Get Started

To get started, Make sure you have Looking Glass Bridge running along with a Looking Glass Display

We strongly recommend using Typescript

import {BridgeClient} from @lookingglass/bridge

const Bridge = BridgeClient.getInstance()

Bridge is a singleton class, meaning only one Bridge object can exist at a time. This is why we use the getInstance() function instead of trying to create a new BridgeClient

Connecting to Bridge

The BridgeClient object will attempt to automatically connect to Bridge when created. You can connect or disconnect to Bridge by running the following:

await Bridge.connect()

await Bridge.disconnect()

You can also check to see if you can connect to Bridge by running

await Bridge.status()

🔑 Key Concepts

Orchestrations

Looking Glass Bridge supports "orchestrations", these are essentially multi-user sessions. This means you can have multiple apps connected to the same orchestration, and get events from one another using the events from Bridge's websocket connection.

Orchestrations can be created by passing a keyword like Orchestration2 or gerald into bridge. Bridge will return an Orchestration Token which is a specific string of characters that can be used internally in the Bridge.JS library.

As a developer, you shouldn't have to worry about this token, since this is always handled in the library for you once an orchestration is created. The only thing you'll need to pass to Bridge if you want an individual session is the string to create the orchestration. If you don't pass a string then a default orchestration will be used with the default keyword.

Holograms

The Bridge.JS Library currently supports two hologram types, Quilts and RGBD, you need to construct the hologram object, then cast it to Bridge.

Note In the examples below we use web based URLs in the uri field, but you can also use a file path location as well.

const quilt = new QuiltHologram({
	uri: "https://s3.amazonaws.com/lkg-blocks/u/9aa4b54a7346471d/steampunk_qs8x13.jpg",
	settings: { rows: 13, columns: 8, aspect: 0.75, viewCount: 8 * 13 },
})

const rgbd = new RGBDHologram({
	uri: "https://dl-dev.blocks.glass/u/b528b9def6aa4986/rgbd.png",
	settings: {
		depthiness: 2.0,
		focus: 0,
		aspect: 1,
		chroma_depth: 0,
		depth_inversion: 0,
		depth_loc: 2,
		depth_cutoff: 1,
		zoom: 1,
	},
})

You can also dynamically create a hologram of either class by using the hologramFactory function. An example using this pattern can be found in the src/react-app/components/HologramForm.tsx component. In that component we utilize a form and allow the user to create a hologram from the UI.

Casting a Hologram

To show a single hologram on the display, you can use the cast function like so:

await Bridge.cast(hologram)

Playlists

Looking Glass Bridge supports playing back Playlists of holograms. Like Orchestrations, Playlists are created by passing a keyword into the createPlaylist function. A Playlist isn't sent to Bridge itself until you play the playlist.

You'll want to add items to your playlist, which you can do with the addItem function.

// create a playlist
const playlist = Bridge.createPlaylist("banana")

// create a hologram to put in the playlist
const quilt = new QuiltHologram({
	uri: "https://s3.amazonaws.com/lkg-blocks/u/9aa4b54a7346471d/steampunk_qs8x13.jpg",
	settings: { rows: 13, columns: 8, aspect: 0.75, viewCount: 8 * 13 },
})
// add the item to the playlist
playlist.addItem = hologram
// play the playlist
await Bridge.play(playlist)

Checking if functions succeeded.

All functions in Bridge.js return an object that contains a success value. Given that most functions are asynchronous, you'll need to store the result as a variable and then check it.

For example:

const cast = await Bridge.cast(hologram)
if (cast.success) {
	console.log("🥳 yay we did it!")
} else {
	console.log("😭")
}

Organization

All files used in the library are in the src/library folder.

Most core functionality is exported as part of the Bridge object, though there are some helper functions that assist in creating hologram and playlist objects.

Responses and Requests to Bridge are strongly typed with the Zod library. These are defined in the schemas folder.

To ensure your file/functionality is exported from the library you must reference the file in index.ts

Files in the react app are in the src/react-app folder.

Developing

Note This readme assumes your development environment is setup and you have node.js and yarn installed. If you don't have yarn, you can also use npm.

To start developing the library, clone this github repo. Then run yarn install

To develop the library run yarn dev This will spin up a minimal react environment that imports the library and supports full typesafety + hot reloading.

To build the library, run yarn library This will also auto-generate documentation via typedoc.

To build the react-app, run yarn build