Socket
Socket
Sign inDemoInstall

twitch-pro

Package Overview
Dependencies
16
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    twitch-pro

A Twitch API Module. To interact with Twitch API!


Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

twitch-pro

twitch-pro is a Node.js library that simplifies interactions with the Twitch API and Twitch IRC chat.

Installation

You can install twitch-pro using npm:

npm install twitch-pro

Usage

Initialize Twitch Client Options

Before using twitch-pro, you need to provide your Twitch client ID and OAuth2 token. Replace "your_client_id" and "your_token" with your actual Twitch client ID and OAuth2 token respectively.

const opts = {
    clientId: "your_client_id", // Replace with your Twitch client ID here
    token: "your_token",  // Replace with your Twitch OAuth2 token here
    nickname: "MaxA_MM" // Your Twitch username
}

Initialize WebSocket Client Options

Similarly, for WebSocket client options, replace "your_token" with your Twitch OAuth2 token.

const wsOpts = {
    token: "your_token", // Replace with your Twitch OAuth2 token here
    nickname: "MaxA_MM" // Your Twitch username
};

Creating Twitch Client and WebSocket Client Instances

You can create instances of the Twitch Client and WebSocket Client using the provided options.

import { Client, Events, WSClient } from "twitch-pro";
import { error, log } from "console";

const client = new Client(opts); // Twitch Client instance
const ws = new WSClient(wsOpts); // WebSocket Client instance

Connecting to Twitch API and IRC Chat

You can connect to the Twitch API and IRC chat by calling the connect() method on the Twitch Client and WebSocket Client instances respectively.

client.connect()
    .then(() => log(`Successfully connected to Twitch API`));

ws.connect();

Registering Event Handlers

You can register event handlers for various WebSocket events such as ready, message, join, close, and error.

ws.on(Events.Ready, async () => {
    log("WebSocket is ready");
    ws.ping();
    ws.join('maxa_mm');
});

ws.on(Events.Message, async (msg) => {
    log(msg.content);
});

// Add handlers for other events: Join, Close, Error

Configuration

Ensure to replace "your_client_id" and "your_token" with your actual Twitch client ID and OAuth2 token respectively. This ensures proper authentication when connecting to Twitch services.

Contributing

Contributions are welcome! If you encounter any bugs or have suggestions for improvements, please feel free to submit issues or pull requests.

License

This project is licensed under the MIT License.

Keywords

FAQs

Last updated on 19 Feb 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc