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

twitch-player

v2.0.2

Published

A Typescript wrapper for the Twitch embeddable, interactive media player.

Downloads

1,745

Readme

twitch-player

About

twitch-player is a Typescript npm package that provides an easy interaction with the Twitch embeddable, interactive VOD and Clips player.

Currently, the Twitch Development team offers only Javacript support for embedding an interactive media player (see this link). When developing Web apps using Typescript (for example in Angular) it is pretty cumbersome to work with the provided script, without any types support.

Because of this I've released this package, which has the following features:

  • easy setup using npm install :heavy_check_mark:
  • types support for Typescript :heavy_check_mark:
  • tested with Angular :heavy_check_mark:

Setup

npm install

Can be easily installed using npm:

npm i twitch-player

Updating index.html (optional)

Currently, both JS scripts for the Twitch.Player and Twitch.Embed are static files inside package. If you want to use the official Twitch versions you will have to append the following to your index.html file:

<!-- Twitch script for the Twitch.Embed object -->
<script src="https://embed.twitch.tv/embed/v1.js"></script>

<!-- Twitch script for the Twitch.Player object -->
<script src= "https://player.twitch.tv/js/embed/v1.js"></script>

How to use

Creating a new player instance

const player = TwitchPlayer.FromOptions('twitch-player', {
        width: 1280,
        height: 720,
        video: '<video ID here>'
      });
  • In this example, the first argument of the constructor (twitch-player), represents the identifier of the div element where the player will be displayed.

  • The second argument holds all the initialization options for the player, including the width, height and video that will be played

  • For more information please visit the Twitch Developer Reference.

Creating a new Embed instance

const embed = new TwitchEmbed('twitch-player', {
        width: 1280,
        height: 720,
        channel: '<channel ID here>',
        layout: TwitchEmbedLayout.VIDEO_WITH_CHAT
      });
  • The TwitchEmbed object can be used to embed everything, including the chat. It holds a TwitchPlayer instance that can be accessed by calling embed.getPlayer()

  • For more information please visit the Twitch Developer Reference

Interacting with the player

  • Skipping 10 seconds forward: player.seek(player.getCurrentTime() + 10)
  • Pausing: player.pause()
  • Changing volume: player.setVolume(0.7)

Reacting to player events

player.addEventListener(TwitchPlayerEvent.PAUSE, () => {
        console.log('paused');
      });
player.addEventListener(TwitchPlayerEvent.PLAY, () => {
        console.log('started');
      });

Documentation

The documentation for all public classes, members and functions can be found here.

License

This project is available under the MIT license. See the LICENSE file for more information.