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

@npo/react-player

v0.3.0-beta.2

Published

A React wrapper for the NPO Player

Downloads

134

Readme

NPO React Player

A React wrapper for the @npo/player library.

Getting Started

  1. Install the package
  2. Sign a JWT according to the @npo/player documentation
  3. Import the NpoPlayer component
  4. Add the component to your application
// npm
npm install @npo/react-player

// yarn
yarn add @npo/react-player
import { NpoPlayer } from '@npo/react-player'

export const MyPlayer = () => {
  const { data, isSuccess } = useMyPlayerToken()

  return <NpoPlayer isEnabled={isSuccess} jwt={data?.token} />
}

Next.js

The NPO React Player package is importing the stylesheet from the @npo/player libray. To be able to use this import from an NPM module, you need to to add the NPO React Player to the transpilePackages in the next.config.js.

/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ['@npo/react-player']
}

module.exports = nextConfig

NPO Tag

The NPO React Player package has a dependency on the NPO Tag SDK. This SDK is a private repository. You will need to define an auth token and a registry server to be able to install this dependency.

Available properties

children

You can add children to the NpoPlayer component. The children will be displayd on top of the Player instance.

export const MyPlayer = () => {
  const { data, isError, isLoading } = useMyPlayerToken()

  return (
    <NpoPlayer isEnabled={!isLoading} jwt={data?.token}>
      {isLoading && <MyPlayerLoader />}

      {isError && <MyPlayerError />}
    </NpoPlayer>
  )
}

className

You can add class names as property to the NpoPlayer component to style your player implementation.

export const MyPlayer = () => {
  return <NpoPlayer className='aspect-h-9 aspect-w-16' />
}

handleError

You can add a handleError event handler as property to the NpoPlayer component. This handler returns a statusCode value on which you can customize your error handling.

export const MyPlayer = () => {
  const [showRestrictionError, setShowRestrictionError] = React.useState<boolean>(false)

  const handleError = React.useCallback((statusCode: number) => {
    setShowRestrictionError(statusCode === 450)
  }, [])

  return (
    <NpoPlayer handleError={handleError}>
      {showRestrictionError && <MyRestrictionError />}
    </NpoPlayer>
}

isEnabled

You can add an isEnabled boolean as property to the NpoPlayer component for any dependency that needs to be resolved before the initialization of the player instance.

export const MyPlayer = () => {
  const { isLoadingA } = useMyPlayerDepA()
  const { isLoadingB } = useMyPlayerDepB()

  return <NpoPlayer isEnabled={!isLoadingA && !isLoadingB} />
}

jwt

You have to add the JWT as property to the NpoPlayer component. The JWT is the only required property for the player to play.

export const MyPlayer = () => {
  const { data, isSuccess } = useMyPlayerToken()

  return <NpoPlayer isEnabled={isSuccess} jwt={data?.token} />
}

npoTagInstance

You can add the NPO Tag instance as property to the NpoPlayer component.

import { npoTagInstance } from './npoTag.service.ts'

export const MyPlayer = () => {
  return <NpoPlayer npoTagInstance={npoTagInstance} />
}

playerConfig

You can add a player configuration as property to the NpoPlayer component. The available configuration options can be found in the @npo/player documentation.

export const MyPlayer = () => {
  return <NpoPlayer playerConfig={{ cast: { enable: false } }} />
}

streamOptions

You can add stream options as property to the NpoPlayer component. See all available options in the @npo/player documentation.

export const MyPlayer = () => {
  return <NpoPlayer streamOptions={{ autoplay: true, liveOffset: false, startOffset: 60 }} />
}

Environment variables

You can define three environment variables to run the player. If you define these environment variables, you don't have to add these values to the playerConfig and the streamOptions properties: these will be applied as the default values.

NPO_PLAYER_ANALYTICS_KEY=
NPO_PLAYER_LICENSE_KEY=
NPO_PLAYER_URL=

Next.js

When you are using Next.js you will have to prefix the environment variables with the NEXT_PUBLIC_ prefix for the variables to be available in the browser environment.