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

mrfastdie-twitch-js

v1.0.6

Published

Javascript library for the Twitch Messaging Interface.

Downloads

7

Readme

TwitchJS

Build status Coverage status NPM version NPM downloads GitHub issues GitHub bug issues

A community-centric, community-supported Twitch JavaScript SDK.

Features

  • Aligns with official Twitch IRC documentation
  • Forward-compatible, low-level, minimally-assertive architecture
  • Supports Node environments
  • Supports Browsers
  • Supports TypeScript
  • Connect to multiple channels
  • Chat commands
  • Rate limiter

In progress...

Here are the planned features. If you feel something is missing, create an issue or submit a PR against the next branch.

Documentation

  1. Getting started
  2. Authentication
  3. Examples
  4. Interacting with Twitch chat
  5. Making requests to Twitch API
  6. Reference

Getting started

Module bundler (CJS/ESM)

If you are using a module bundler, such as Webpack, Browserify, or a in a Node environment:

  1. Add TwitchJS to your project:

    npm install --save twitch-js
  2. Import TwitchJS

    // ES2015 syntax
    import TwitchJs from 'twitch-js'
    
    // OR ES5 syntax
    var TwitchJs = require('twitch-js')
    
    const twitchJs = new TwitchJs({ username, token })

Browser (IIFE)

If you are not using a module bundler, precompiled builds are available in the dist folder:

  1. Include a script tag in your HTML:
    <script src="//unpkg.com/twitch-js@>2.0.0-beta.31"></script>
  2. Consume the library:
    <script type="javascript">
      const twitchJs = new window.TwitchJs({ username, token })
    </script>

Authentication

Obtaining a client ID

To obtain a client ID, follow the instructions found in the Twitch Developers documentation.

Obtaining a token

With a client ID, tokens may be generated on behalf of your users.

To quickly get started without a client ID, you may generate token using the following, community-maintained, sites:

  1. Twitch Token Generator
  2. Twitch Chat OAuth Password Generator

Refreshing tokens

To help with refreshing tokens, an onAuthenticationFailure function may be provided to the Messaging and API clients. onAuthenticationFailure() must return a Promise that resolves with the refreshed token. Upon resolution, any actions that yielded an expired token response will be retried with the new, refreshed token.

Handling token refresh example

// Optionally, use fetchUtil to help.
import fetchUtil from 'twitch-js/lib/utils/fetch'

const refreshToken = 'eyJfaWQmNzMtNGCJ9%6VFV5LNrZFUj8oU231/3Aj'
const clientId = 'fooid'
const secret = 'barbazsecret'

const onAuthenticationFailure = () =>
  fetchUtil('https://id.twitch.tv/oauth2/token', {
    method: 'post',
    search: {
      grant_type: 'refresh_token',
      refresh_token: refreshToken,
      client_id: clientId,
      client_secret: clientSecret,
    },
  }).then((response) => response.accessToken)

const token = 'cfabdegwdoklmawdzdo98xt2fo512y'
const username = 'ronni'
const twitchJs = new TwitchJs({ token, username, onAuthenticationFailure })

twitchJs.chat.connect().then((globalUserState) => {
  // Do stuff ...
})

See Refreshing access tokens for more information.

More information

See the Twitch Developers documentation for more information on authentication.

Examples

Examples are provided via CodeSandbox:

Contribution guidelines

If you wish to contribute, please see the CONTRIBUTING doc.

Special thanks

Schmoopiie and all the original contributors of tmi.js.

License

MIT

TwitchJS is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Twitch, or any of its subsidiaries or its affiliates. The name "Twitch" as well as related names, marks, emblems and images are registered trademarks of Twitch.