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 = const tracker = 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 StreamDatatracker // Make sure you listen for errorstracker
NOTE: If you don't pass start: true
in the options, you must call tracker.start()
to start polling.
TwitchOnlineTracker API
TwitchOnlineTrackerOptions)
const tracker = new TwitchOnlineTracker(options:Create a new TwitchOnlineTracker
instance. It takes a TwitchOnlineTrackerOptions interface:
client_id
string required Your Twitch app's client idtrack
string[] An array of the channels you wish to track on startuppollInterval
number The amount of time in seconds between pollsdebug
boolean If true, output debug information to consolestart
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.
StreamData) { })
tracker.on('live', function (streamData:When a stream is found to be live, fires this event. The callback function provides a StreamData parameter.
Example:
tracker
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
tracker.on('error', function (error) { })
Fires this event on error. Make sure you capture this event.
Example:
tracker