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

@ample-launchpad/ui

v0.1.1

Published

A set of React components and utils to launch and tokenize IP + media anywhere.

Downloads

5

Readme

Ample Launchpad | UI Package

A set of React components and utils to launch and tokenize IP + media anywhere.

Quick start

Install dependencies

npm install \
    @ample-launchpad/core \
    @ample-launchpad/client \
    @ample-launchpad/ui

Init launchpad

// @ample-launchpad/ui and @ample-launchpad/client packages are intended to be used in tandem with @near-wallet-selector.
// Please setup wallet selector before using these packages.
// see example/ for a complete @near-wallet-selector + @ample-launchpad integration
import { useState, useEffect } from 'react'
import { walletSelector } from 'your-wallet-selector-setup'
import { Launchpad, setupLaunchpad } from '@ample-launchpad/client'
import { AmpleLaunchpadProvider } from '@ample-launchpad/ui'
import "@ample-launchpad/ui/dist/index.css"


const ExampleApp = () => {
    const [launchpad, setLaunchpad] = useState<Launchpad | undefined>()

    useEffect(() => {
        initLaunchpad()
    }, [])

    const initLaunchpad = async () => {
        if(!walletSelector) return
        const wallet = await walletSelector.wallet()

        const launchpad = await setupLaunchpad({
            wallet,
            // you might want to make these env variables
            network: 'testnet',
            serverUrl: 'https://your-server-deployment.com',
            treasuryAddress: 'treasury.your-near-acc.testnet',
            seriesAddress: 'series.your-near-acc.testnet',
        })

        setLaunchpad(launchpad)
    }

    return <>
        {
            launchpad 
                ? <AmpleLaunchpadProvider launchpad={launchpad} accentColor='purple'> 
                    {/* content here */}
                </AmpleLaunchpadProvider>
                : <div>No launchpad here :(</div>
        }
    </>
}

Hooks

useLaunchpad

This is the main hook to interact with the launchpad, it allows you to access the Launchpad instance created during setup.

import { useLaunchpad } from '@ample-launchpad/ui'
import { IContent } from '@ample-launchpad/client'

const SomeComponent = () => {
    const { getContents } = useLaunchpad()
    const [contents, setContents] = useState<IContent[] | undefined>()

    useEffect(() => {
        fetchContents()
    }, [])

    const fetchContents = async () => {
        const res = await getContents()

        if(res.data.success) setContents(res.data.data)
    }

    if(!contents) return null

    return <>
        {contents.map((c, i) => <div key={i}>{c.title}</div>)}
    </>
}

useStreaming

This hook will take care of the tokengated streaming process by asking the user for a signature to validate wallet ownership, get a jwt with that signature and store the access token for each content in local storage.

Here is an example of how to use the useStreaming hook along with the Livepeer player component:

The following setup is needed to get Livepeer metrics working properly. See https://docs.livepeer.org/developers/guides/get-engagement-analytics-via-api#registering-views for more information

import { useStreaming } from "@ample-launchpad/ui"
import { getSrc } from "@livepeer/react/external";
import * as LivepeerPlayer from "@livepeer/react/player";

interface IProps {
	contentId: string,
	title: string
}
export const CustomPlayer: React.FC<IProps> = ({ contentId, title }) => {
	const { error, streamingUrl, jwt, tryAgain } = useStreaming(contentId)

	if (!streamingUrl) return null

	if (error) return <div>
		<pre>{error}</pre>
		<button onClick={tryAgain}>Try again</button>
	</div>

	return <LivepeerPlayer.Root aspectRatio={null} autoPlay src={getSrc(streamingUrl)} jwt={jwt}>
		<LivepeerPlayer.Container>
			<LivepeerPlayer.Video controls title={title} muted />
		</LivepeerPlayer.Container>
	</LivepeerPlayer.Root>
}

React components

<Launch />

import { Launch } from "@ample-launchpad/ui"

const SomeOtherComponent = () => {
	return <Launch
        onUploadError={(error) => console.error(error)}
		onUploadProgress={(progress) => { console.log({ progress }) }}
		onContentCreated={({ collectionId, contentId }) => { console.log({ collectionId, contentId }) }}
	/>
}

<Royalty />

import { Royalty } from "@ample-launchpad/ui"

const AnotherOne = () => {
    return <Royalty />
}

<Player />

This player component handles only the tokengated side of the streaming process. It is not yet capable of sending metrics to the chosen provider. For integrating a custom player with a per-provider metrics system, please see the useStreaming hook.

import { Player } from "@ample-launchpad/ui"

const contentId = 'some-content-id'
const title = 'Shrek'

const LastFakeComponent = () => {
    return <Player contentId={contentId} title={title} />
}