Giter Site home page Giter Site logo

spathizilla / twitchonlinetracker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chris-perez/twitchonlinetracker

0.0 0.0 0.0 43 KB

A TypeScript Node.JS library to track when Twitch.TV streams goes up or down.

TypeScript 45.92% JavaScript 54.08%

twitchonlinetracker's Introduction

Track when Twitch streams go online

Quickstart

Install: npm install --save twitchonlinetracker

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

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

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

// 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
  • 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)
})

twitchonlinetracker's People

Contributors

chris-perez avatar dependabot[bot] avatar megadrive avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.