All Projects → ryancharris → react-livestream

ryancharris / react-livestream

Licence: other
Embed your Twitch, Mixer or YouTube stream in your website automatically when you're live

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-livestream

elm-twitch-chat
Elm powered Twitch chat using WebSockets
Stars: ✭ 14 (-76.67%)
Mutual labels:  twitch
twitch-chat-raspi-leds
Let to Twitch chat users to interact with RaspberryPi LEDs
Stars: ✭ 16 (-73.33%)
Mutual labels:  twitch
TwitchTest
Bandwidth tester for Twitch
Stars: ✭ 111 (+85%)
Mutual labels:  twitch
CounterStrike-GlobalOffensive-LiveStat-for-OBS-Studio
Showing you LIVEstats of CS:GO in your Stream like OBS-Studio while playing/streaming.
Stars: ✭ 24 (-60%)
Mutual labels:  twitch
pajbot2
pajbot in go
Stars: ✭ 79 (+31.67%)
Mutual labels:  twitch
jChat
jChat is an overlay that allows you to show your Twitch chat on screen with OBS, XSplit, and any other streaming software that supports browser sources.
Stars: ✭ 106 (+76.67%)
Mutual labels:  twitch
Streamlabs Obs
Free and open source streaming software built on OBS and Electron.
Stars: ✭ 3,473 (+5688.33%)
Mutual labels:  twitch
TuxTwitchTalker
Twitch chat bot to help small streamers automate their stream and reduce reliance on third parties
Stars: ✭ 40 (-33.33%)
Mutual labels:  twitch
streamcord
A Discord bot that interacts with the popular streaming service Twitch.tv
Stars: ✭ 83 (+38.33%)
Mutual labels:  twitch
twitch-extension-starter
Kickstarts your Twitch Extension using React
Stars: ✭ 38 (-36.67%)
Mutual labels:  twitch
extensions-js
An Easier way to build Twitch Extensions using this JavaScript library for interfacing with Muxy's extensions backend.
Stars: ✭ 26 (-56.67%)
Mutual labels:  twitch
TwitchMarkovChain
Twitch Bot for generating messages based on what it learned from chat
Stars: ✭ 87 (+45%)
Mutual labels:  twitch
node-twitchbot
Package for easily creating Twitch Bots
Stars: ✭ 13 (-78.33%)
Mutual labels:  twitch
siren
Telegram bot for webcasts alerts
Stars: ✭ 40 (-33.33%)
Mutual labels:  twitch
Youtube-DL-GUI
Graphical User Interace built around youtube-dl CLI
Stars: ✭ 38 (-36.67%)
Mutual labels:  twitch
Cracking The Coding Interview Rust
Cracking the Coding Interview problem solutions in Rust
Stars: ✭ 246 (+310%)
Mutual labels:  twitch
PhantomBot-German-Translation
Deutsche Übersetzung des Twitch Chat Bots PhantomBot
Stars: ✭ 13 (-78.33%)
Mutual labels:  twitch
Twitch-View-Bot
First open-source really working view bot for Twitch
Stars: ✭ 63 (+5%)
Mutual labels:  twitch
mTwitch
Twitch normalizer for mIRC
Stars: ✭ 22 (-63.33%)
Mutual labels:  twitch
coebot-www
A web interface for CoeBot, a Twitch chat bot
Stars: ✭ 12 (-80%)
Mutual labels:  twitch

react-livestream

Automatically embed your livestream in your React app whenever you go live!

This package currently works with the following streaming platforms:

  1. Twitch
  2. Mixer
  3. YouTube

Instructions

react-livestream allows you to use a React component called <ReactLivestream />, which will embed a responsive <iframe> into your site whenever your channel or account is live.

If you are not currently broadcasting, nothing will be rendered in the DOM unless you choose to pass in an optional JSX element as the offlineComponent prop. In this case, that component will render when you're offline.

import React from 'react'
import ReactLivestream from 'react-livestream'

// Optional component to be rendered
// when you're not streaming
function OfflineComponent() {
  return (
    <div>
      <p>I am offline now, but checkout my stream on Fridays at 5 PM EST</p>
    </div>
  )
}

function App() {
  return (
    <div className="App">
      <ReactLivestream
        platform="mixer"
        mixerChannelId
        offlineComponent={OfflineComponent}
      />

      <ReactLivestream platform="twitch" twitchDataUrl twitchUserName />

      <ReactLivestream platform="youtube" youtubeApiKey youtubeChannelId />
    </div>
  )
}

export default App

The component takes these general props:

  • platform - "mixer", "twitch", or "youtube" (required)
  • offlineComponent - A JSX element that renders in place of the <iframe> when the user is not live (optional)

In addition, you need to pass in the following information based on your streaming platform:

  • mixerChannelId - Found in the Network tab of your developer tools when navigating to your Mixer channel. For example, mine is https://mixer.com/api/v1/channels/102402534, so my ID is 102402534
  • twitchDataUrl - An endpoint that handles authenticating with the Twitch API and makes a request for stream infomation about the user specified below.
  • twitchUserName - The username associated with your Twitch account
  • youtubeApiKey - Obtain this from the Google Developers console
  • youtubeChannelId - This can be found in the URL to you YouTube channel. For example, my channel URL is https://www.youtube.com/channel/UCwMTu04flyFwBnLF0-_5H-w, so my channel ID is UCwMTu04flyFwBnLF0-_5H-w

Examples

Currently, it works with the three streaming services mentioned above. Below, are examples of how to use this component for each streaming platform.

Mixer

<ReactLivestream platform="mixer" mixerChannelId={CHANNEL_ID} />

Twitch

<ReactLivestream
  platform="twitch"
  twitchDataUrl="ENDPOINT_URL"
  twitchUserName="USER_NAME"
/>

YouTube

<ReactLivestream
  platform="youtube"
  youtubeApiKey="API_KEY"
  youtubeChannelId="CHANNEL_ID"
/>

Twitch and react-livestream

In April 2020, Twitch changed how their API works and you can no longer make authenticated calls from the client. Because of that, you will need to add some infrastructure to handle server-to-server request.

Currently, I am handling this with a Netlify function. Feel free to copy and paste the snippet below for your own use. Just make sure to swap out the placeholder values.

const fetch = require('node-fetch')
require('dotenv').config()

function getTwitchData(token) {
  console.log('Fetching broadcast info...')

  const apiUrl = 'https://api.twitch.tv/helix/streams?user_login=YOUR_USER_NAME'

  return fetch(apiUrl, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${token}`,
      'Client-ID': process.env.GATSBY_TWITCH_CLIENT_ID
    }
  })
    .then(res => {
      if (res.ok) {
        return res.json()
      } else {
        throw new Error('Unable to authenticate with Twitch API')
      }
    })
    .catch(err => err)
}

exports.handler = async function (event, context) {
  console.log('Requesting token from Twitch API...')

  const TWITCH_API = 'https://id.twitch.tv/oauth2/token'
  const tokenUrl = `${TWITCH_API}?client_id=${process.env.GATSBY_TWITCH_CLIENT_ID}&client_secret=${process.env.GATSBY_TWITCH_CLIENT_SECRET}&grant_type=client_credentials`

  const data = fetch(tokenUrl, {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Client-ID': process.env.GATSBY_TWITCH_CLIENT_ID
    }
  })
    .then(res => {
      if (res.ok) {
        return res.json()
      } else {
        throw new Error('Cannot retrieve access_token from Twitch API')
      }
    })
    .then(async json => {
      const token = json.access_token
      return {
        statusCode: 200,
        body: JSON.stringify(await getTwitchData(token)),
        headers: {
          'Access-Control-Allow-Origin': '*'
        }
      }
    })
    .catch(err => {
      return {
        statusCode: 422,
        body: String(err)
      }
    })

  return data
}

Notes

Built with React and Microbundle.

Maintained by Ryan Harris

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].