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

@matsukky/twitchtracker

v1.1.8

Published

A library to help track streamers and fires an event if they go online or offline.

Downloads

14

Readme

Track when Twitch streams go online

Quickstart

Install: npm install --save @matsukky/twitchtracker

Get a Client ID & Client Secret. See Step 1 of the Twitch API Introduction on how to do this.

const { TwitchOnlineTracker } = require('@matsukky/twitchtracker')
const tracker = new TwitchOnlineTracker({
  client_id: "your twitch app client id", // used for api requests
  client_secret: "your twitch app client secret", // used for connect to the api
  track: ['channel1', 'channel2'], // all the channels you want to track
  pollInterval: 30, // how often in between polls in seconds. default 30
  debug: false, // whether to debug to console
  start: true // whether to start immediately. if you don't use this, you must call.
})

// Listen to live event, it returns StreamData
tracker.on('live', streamData => {
  console.log(`${streamData.user_name} just went live!`)
})

// Listen to live end, only returns channel name
tracker.on('offline', function (channel) {
  console.log(`${channel} has gone offline.`)
})

// Make sure you listen for errors
tracker.on('error', error => console.error)

NOTE: If you don't pass start: true in the options, you must call tracker.start() to start polling.

TwitchOnlineTracker API

const tracker = new TwitchOnlineTracker(options: TwitchOnlineTrackerOptions)

Create a new TwitchOnlineTracker instance. It takes a TwitchOnlineTrackerOptions interface:

  • client_id string required Your Twitch app's client id
  • client_secret string required Your Twitch app's client secret
  • track string[] An array of the channels you wish to track on startup
  • pollInterval number The amount of time in seconds between polls
  • debug boolean If true, output debug information to console
  • start boolean If true, start polling immediately

tracker.start()

Starts polling the Twitch API for stream changes.

tracker.stop()

Stops polling the Twitch API for stream changes.

tracker.track(usernamesToTrack: string[])

Adds more streams to track. usernamesToTrack expects an array of strings.

tracker.untrack(usernamesToUntrack: string[])

Stops tracking streams. usernamesToTrack expects an array of strings.

tracker.on('live', function (streamData: StreamData) { })

When a stream is found to be live, fires this event. The callback function provides a StreamData parameter.

Example:

tracker.on('live', function (streamData) {
  console.log(`${streamData.user_name} has started streaming with the title ${streamData.title} at https://twitch.tv/${streamData.user_name} for ${streamData.viewer_count} viewers!`)
})

tracker.on('offline', function (channelName: string) { })

When a stream is found to have gone offline, fires this event. The callback function provides a string.

Example:

tracker.on('offline', function (channel) {
  console.log(`${channel} has gone offline.`)
})

tracker.on('error', function (error) { })

Fires this event on error. Make sure you capture this event.

Example:

tracker.on('error', function (error) {
  throw Error(error)
})