npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

connector-twitch-irc

v1.0.0

Published

This connector is for twitch, you can do the connection for token for IRC

Downloads

3

Readme

👋🏼 Connector Twitch IRC

This component is thought out for do connection on twitch easily.

NOTE: You need use the documentation of Tmi.js and Twitch

🚀 Getting Started

Install the component

npm i connector-twitch-irc

Imported the component connector-twitch-irc

import { connectToStream, connectTwitch } from 'connector-twitch-irc';

Set your client ID of the app twitch

const clientID_ = 'my client ID';

Set the link redirect for get the permissions of twitch on you app

<button onClick={(() => {
            location.href = `https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=${clientID_}&redirect_uri=${location.origin}&scope=chat%3Aread+chat%3Aedit`
          })}>
        Twitch
</button>

Use the functions connectTwitch and connectToStream for that you can connect on twitch stream

  const [connect, setConnect] = useState({});

  useEffect(() => {
    try {

      let session = sessionStorage.getItem('access_token');
      let token = '';

      if (!_loadingEffect) {
        if (session != null && session != undefined) {
          token = session;
          connectTwitch(session, setConnect);
        }
        else {
          token = location.hash.split('=')[1].split('&')[0];
          connectToStream(token, clientID_, setConnect);
        }

      }
    } catch (error) {

    }

  }, []);

✨ Scope of Twitch

the scope for this example is 'chat%3Aread+chat%3Aedit' (It is for read and edit message chat). I you need another permissions you need check of documentation of Twitch.

💻 Connect with sessionStorage

We need to use connectTwitch. This method use the sessionStorage as session variable. The variable session is an object where this variable has follow properties.

user: where you get the user session.

myToken: where you have the token.

📱 Connect without sessionStorage

We need to use connectToStream. This method has as parameter the token from hash link.

💻 Client ID

The client id is getted from twitch Developer Console. You can enter in the follow link : Twitch Develope

👨🏼‍💻 setConnect

The set connect in the case of React js is for get the variable connect. In the case of Vanilla Js is an any function where you get as parameter an connector.

🤓 Code of Example with React JS

import { connectToStream, connectTwitch } from 'connector-twitch-irc';
import { useEffect, useState } from "react";

const _loadingEffect = false;

const clientID_ = 'my client ID';

export default function Home() {

  const [connect, setConnect] = useState({});

  useEffect(() => {
    try {

      let session = sessionStorage.getItem('access_token');
      let token = '';

      if (!_loadingEffect) {
        if (session != null && session != undefined) {
          token = session;
          connectTwitch(session, setConnect);
        }
        else {
          token = location.hash.split('=')[1].split('&')[0];
          connectToStream(token, clientID_, setConnect);
        }

      }
    } catch (error) {

    }

  }, []);

  useEffect(() => {
    console.log(connect);
  }, [connect])

  return (
    <>
      <main className={`${styles.main} ${inter.className}`}>
        <button onClick={(
          () => {
            location.href = `https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=${clientID_}&redirect_uri=${location.origin}&scope=chat%3Aread+chat%3Aedit`
          })
        }>Twitch</button>
      </main>
    </>
  );
}