
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
flow-monitor
Advanced tools
A lightweight library for monitoring live streams across multiple platforms. Make it easy to follow essential events, such as the start and end of broadcasts, with real-time notifications. The perfect solution for developers looking for a simple and effic
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
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.
Logger
class: For more detailed and configurable logging.Queue
system: Manages asynchronous operations to prevent race conditions.twitchPlaylist
method: To fetch the m3u8 playlist for a Twitch stream directly.category
property on the vod
object is now an array, storing the history of categories for a stream.streamUp
event now passes a vod
object with rich information about the stream.thumbnail
event: A new event to notify when a stream's thumbnail changes.fetchTwitch
and fetchYoutube
methods to get data on demand.start()
method has been removed. The library now automatically starts monitoring when you connect to a channel.newChannel
is now connected
.disconnectChannel
is now disconnected
.twitchError
is now error
.streamUp
, streamDown
, viewCount
, title
, and category
now have a consistent signature, passing the channel
and vod
objects.axios
and async-lock
have been removed in favor of native fetch
and a new Queue
implementation. eventemitter3
is now used for event management.start()
method: No longer needed.livedata()
method: You can now get the channel data directly from the channels
property.To install FlowMonitor, use npm:
npm install flow-monitor
Here'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.
FAQs
A lightweight library for monitoring live streams across multiple platforms. Make it easy to follow essential events, such as the start and end of broadcasts, with real-time notifications. The perfect solution for developers looking for a simple and effic
The npm package flow-monitor receives a total of 5 weekly downloads. As such, flow-monitor popularity was classified as not popular.
We found that flow-monitor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.