
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
yt-chat-signaler
Advanced tools
A client for connecting to the YouTube Live Chat signaler service to receive real-time events.
A Node.js client for connecting to the YouTube Live Chat signaler service to receive real-time events.
It is designed to be the backbone for bots, chat archives, or any application that needs to listen to YouTube live chat messages programmatically.
npm install yt-chat-signaler
Here's a simple example of how to connect to a YouTube live chat and listen for events.
import { YtChatSignaler } from "yt-chat-signaler";
// The video ID of the YouTube live stream.
const videoId = 'YOUR_YOUTUBE_LIVE_VIDEO_ID';
const client = new YtChatSignaler({
chats: [videoId],
});
client.on('connected', (chatData) => {
console.log(`Successfully connected to chat for video: ${chatData.chatId}`);
});
client.on('data', ({ data, chatData }) => {
console.log(`Received data from ${chatData.chatId}:`, JSON.stringify(data));
// This is where you would parse the 'data' payload to extract chat messages.
});
client.on('connectionError', (error) => {
console.error('An error occurred:', error);
});
client.on('reconnecting', ({ attempts, waitTime }) => {
console.log(`Attempting to reconnect... (Attempt #${attempts}, waiting ${waitTime}ms)`);
});
// Start the client
client.start();
// To stop listening to a specific chat
// client.stop(videoId);
You can pass an options object to the Client
constructor to customize its behavior.
new Client(options)
Option | Type | Default | Description |
---|---|---|---|
chats | string[] | [] | Required. An array of YouTube video IDs for the live chats you want to join. |
apiKey | string | (Internal YouTube Key) | A custom YouTube API key. |
userAgent | string | (Chrome on Linux User-Agent) | A custom User-Agent string for HTTP requests. |
maxReconnectAttempts | number | 5 | Maximum number of reconnection attempts. Set to 0 or a negative number for infinite retries. |
initialReconnectDelayMs | number | 1000 | The initial time in milliseconds to wait before the first reconnection attempt. |
maxReconnectWaitMs | number | 30000 | The maximum time in milliseconds to wait between reconnection attempts. Caps the exponential backoff. |
The client is an EventEmitter
and will emit various events to notify you about the connection status.
connected
: (chatData: Chat)
chatData
contains session information.data
: (payload: { data: any, chatData: Chat, ... })
data
property contains the raw event payload from YouTube, which you can parse to get chat messages, new members, etc.reconnecting
: (payload: { attempts: number, waitTime: number })
connectionError
: (error: Error)
part
: (chatData: Chat)
client.stop()
is called.ping
: (payload: { tms: any, chatData: Chat })
gsessoinId
: (gsessionid: string)
gsessionid
from YouTube's servers.sid
: (sidData: ConnectRPCData)
SID
).refreshCreds
: (payload: { gsessionid: string, key: string, chatData: Chat })
Directly using this package in a browser (e.g., in a React or Vue application) will not work due to CORS (Cross-Origin Resource Sharing) restrictions on YouTube's servers. These APIs are not designed for public, client-side access.
The correct way to use this package for a web application is to run it in a server-side proxy.
yt-chat-signaler
and connects to YouTube.This architecture is more secure and is the standard way to work with such APIs.
FAQs
A client for connecting to the YouTube Live Chat signaler service to receive real-time events.
We found that yt-chat-signaler 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.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.