flow-monitor
v1.0.5
Published
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
Downloads
193
Maintainers
Readme
About The Project
This library was created to facilitate the use of websocket, focused more specifically on reconnection, with it it is possible to send parameters that can be used for authentication, and if the connection is closed, when the connection is resumed, it will resend the data for authentication again
Getting Started
Installation
First install our library
npm install flow-monitor
Usage
Import the library
import { FlowMonitor } from 'flow-monitor'
instantiate the class
const fMonitor = new FlowMonitor({
twitch: {
headers: {
Authorization: 'OAuth ', // Authorization to get the m3u8 url without ads if you are registered or have turbo, but not a mandatory parameter
}, // optional http request headers,
},
youtube: {
headers: {}, // optional http request headers,
intervalChecker: 10 * 1000, // Time in milliseconds, default is 5000 = 5s
},
})
Connect to channels
fMonitor.connect('LofiGirl', 'youtube')
fMonitor.connect('zvods', 'twitch')
Start monitoring
fMonitor.start()
Event Handling
Returns twitch request errors, such as authentication error when passing authorization
fMonitor.on('twitchError', (error, status, message) => {
console.log(error, status, message)
})
When you call the start function and start
fMonitor.on('start', () => {
console.log('Flow monitor started')
})
When a new channel is connected
fMonitor.on('newChannel', ({ name, platform }) => {
console.log(name, platform)
})
Confirmation when the channel is disconnected using the disconnect
function
fMonitor.on('disconnectChannel', ({ name, platform }) => {
console.log('Channel disconnected', name, platform)
})
When the flow monitor is finished with the close
function
fMonitor.on('close', () => {
console.log('Flow monitor has been closed')
})
These upcoming events all return an object with the current stream information
livedata structure:
export type LMEventTypes = 'streamUp' | 'streamDown' | 'viewerCount' | 'title' | 'category'
export type LMPlatforms = 'twitch' | 'youtube' | 'kick'
export type LMCategory = {
image: string
name: string
id: string
}
export type LMLiveData = {
event?: LMEventTypes
platform: LMPlatforms
channel: string
title: string
category: LMCategory
viewers: number
thumbnail: string
started_at: string
vodId: string
m3u8Url?: string
}
When the broadcast opens, if you connect the channel and it is already live, you will receive the same
fMonitor.on('streamUp', (livedata) => {
console.log('streamUp', livedata)
})
When the transmission is finished
fMonitor.on('streamDown', (livedata) => {
console.log('streamDown', livedata)
})
When the category is changed
fMonitor.on('category', (livedata) => {
console.log('category', livedata)
})
Broadcast title changed
fMonitor.on('title', (livedata) => {
console.log('title', livedata)
})
Viewer count changes
fMonitor.on('viewerCount', (livedata) => {
console.log('viewerCount', livedata)
})
Additional Functions
disconnect
Disconnects a channel from the flow monitorfMonitor.disconnect('@LofiGirl', 'youtube')
close
Removes all channels and stops monitoringfMonitor.close()
livedata
Returns transmission data if already savedfMonitor.livedata('LofiGirl', 'youtube')
License
Distributed under the MIT License. See LICENSE for more information.
Authors
- ZackSB - Master's degree in life - ZackSB - Built flow-monitor