FlowMonitor is a library dedicated to simplifying the monitoring of live streams across multiple platforms. With easy integration and real-time notifications, it offers an efficient solution for tracking key events, allowing you to maintain clear control over the status of your live streams.
Explore the docs »
Report Bug
·
Request Feature
- About The Project
- Key Changes in This Version
- Installation
- Quick Start
- Detailed Usage
- Events
- API Reference
- Types
- Contribution
- License
FlowMonitor is a comprehensive library designed for monitoring live streams on Twitch and YouTube. It provides real-time notifications for various events, including streams starting and stopping, changes in view counts, titles, and categories. Its main goal is to provide a simple and efficient way to integrate stream monitoring into your projects.
This version represents a significant refactoring of the library, with a focus on improving the API and event structure.
- New
Loggerclass: For more detailed and configurable logging. - New
Queuesystem: Manages asynchronous operations to prevent race conditions. - New
twitchPlaylistmethod: To fetch the m3u8 playlist for a Twitch stream directly. - Category History: The
categoryproperty on thevodobject is now an array, storing the history of categories for a stream. - More Granular Events: Events now provide more detailed and structured data. For example, the
streamUpevent now passes avodobject with rich information about the stream. - Improved Error Handling: The library now has more specific error events, making it easier to handle issues with Twitch and YouTube connections.
- New
thumbnailevent: A new event to notify when a stream's thumbnail changes. - Direct Fetch Methods: New
fetchTwitchandfetchYoutubemethods to get data on demand.
- API Simplification: The
start()method has been removed. The library now automatically starts monitoring when you connect to a channel. - Event Renaming and Structure:
newChannelis nowconnected.disconnectChannelis nowdisconnected.twitchErroris nowerror.- Events like
streamUp,streamDown,viewCount,title, andcategorynow have a consistent signature, passing thechannelandvodobjects.
- Dependencies:
axiosandasync-lockhave been removed in favor of nativefetchand a newQueueimplementation.eventemitter3is now used for event management.
start()method: No longer needed.livedata()method: You can now get the channel data directly from thechannelsproperty.- YouTube Storyboard: The functionality to extract storyboards from YouTube videos has been removed.
To install FlowMonitor, use npm:
npm install flow-monitorHere's a quick example to get you started with FlowMonitor:
import { FlowMonitor, Logger, LogLevel } from 'flow-monitor';
const fm = new FlowMonitor({
log: new Logger(LogLevel.Info),
youtube: {
intervalChecker: 10000,
headers: { 'User-Agent': 'FlowMonitor' }
},
twitch: {
headers: {
'Client-ID': 'your-twitch-client-id',
'Authorization': 'Bearer your-twitch-token'
}
}
});
fm.on('streamUp', (channel, vod) => {
console.log(`Stream started on channel ${channel.username}`);
});
fm.connect('channel_name', 'twitch');
fm.connect('channel_name', 'youtube');To begin, instantiate the FlowMonitor class with your desired options, as shown in the Quick Start section. This single instance will be used to manage all your channel monitoring.
To start monitoring a specific channel:
fm.connect('channel_name', 'twitch');
fm.connect('channel_name', 'youtube');To stop monitoring a specific channel:
fm.disconnect('channel_name', 'twitch');
fm.disconnect('channel_name', 'youtube');To close all connections and clear all data:
fm.close();FlowMonitor emits several events that you can listen to and respond accordingly:
streamUp: Emitted when a stream starts.streamDown: Emitted when a stream ends.viewCount: Emitted when the view count changes.category: Emitted when the stream's category changes.title: Emitted when the stream's title changes.thumbnail: Emitted when the stream's thumbnail changes.twitchSocketOpen: Emitted when the WebSocket connection to Twitch is opened.twitchSocketClose: Emitted when the WebSocket connection to Twitch is closed.connected: Emitted when a channel is connected.disconnected: Emitted when a channel is disconnected.close: Emitted when a connection is closed.closeTwitch: Emitted when the connection to Twitch is closed.error: Emitted when an error occurs.
fm.on('streamUp', (channel, vod) => {
console.log(`Stream started on channel ${channel.username}`);
});
fm.on('streamDown', (channel, vod) => {
console.log(`Stream ended on channel ${channel.username}`);
});
fm.on('viewCount', (channel, vod, count) => {
console.log(`Channel ${channel.username} now has ${count} viewers`);
});
fm.on('title', (channel, vod, newTitle) => {
console.log(`Channel ${channel.username} changed the title to ${newTitle}`);
});constructor(opts: ClientOptions = {})opts: Options object to configure FlowMonitor.log: Logger instance.youtube: Settings for YouTube monitoring.twitch: Settings for Twitch monitoring.
connect(channel: string, platform: FMPlatforms): Connects to a channel for monitoring.disconnect(channel: string, platform: FMPlatforms): Disconnects from a channel.close(): Closes all connections.closeTwitch(reason?: string): Closes the connection to Twitch.fetchTwitch(channel: string): Fetches data for a Twitch channel.fetchYoutube(videoId: string, channel?: string): Fetches data for a YouTube video.twitchPlaylist(channel: string): Fetches the m3u8 playlist for a Twitch stream.
interface ClientOptions {
log?: Logger;
youtube?: {
intervalChecker?: number;
headers?: HeadersInit;
};
twitch?: {
headers?: HeadersInit;
};
}type FlowMonitorEvents = {
streamUp: [channel: Omit<Channel, 'streams'>, vod: Stream];
streamDown: [channel: Omit<Channel, 'streams'>, vod: Stream];
viewCount: [channel: Omit<Channel, 'streams'>, vod: Stream, count: number];
category: [channel: Omit<Channel, 'streams'>, vod: Stream, newcategory: FMCategory];
title: [channel: Omit<Channel, 'streams'>, vod: Stream, newTitle: string];
thumbnail: [channel: Omit<Channel, 'streams'>, vod: Stream, thumbnail: string];
twitchSocketOpen: [uri: string];
twitchSocketClose: [code: number, reason?: string];
connected: [channel: Channel];
disconnected: [channel: Channel];
close: [code: number, reason: string, wasClean: boolean];
closeTwitch: [reason: string];
error: [event: string];
};type Stream = Omit<FMLiveData, 'event'>;type Streams = Map<string, Stream>;type Channel = {
monitoring?: boolean;
platform: FMPlatforms;
username: string;
userId: string;
streams: Streams;
};type Channels = Map<FMPlatforms, Map<string, Partial<Channel>>>;To contribute to this project, please follow the guidelines described in the CONTRIBUTING.md file.
This project is licensed under the MIT License. See the LICENSE file for more details.
- ZackSB - Master's degree in life - ZackSB - Built flow-monitor