Code Monkey home page Code Monkey logo

extensions-hello-world's Introduction

Extensions-Hello-World

The Simplest Extension in the (Hello) World.

Motivation

The Hello World sample is designed to get you started building a Twitch Extension quickly. It contains all the key parts of a functioning Extension and can be immediately run in the Developer Rig. For a fast guide to get started, visit the Developer Rig documentation.

What's in the Sample

The Hello World Extension provides a simple scenario that demonstrates the end-to-end flow of an Extension. On the frontend, a user clicks a button that can change the color of a circle. Instead of changing the CSS locally, it calls its Extension Backend Service (EBS) to update the color of the circle. That message is then sent via Twitch PubSub to update all clients listening to the PubSub topic.

The sample is broken into two main components:

  1. The Frontend of the Extension, comprised of HTML files for the different extension views and corresponding Javascript files and CSS. The frontend has the following functionality:
    • A button and script that makes a POST call to the EBS to request a color change for the circle
    • A GET call when the Extension is initialized to change the circle to the current color stored on the EBS
    • A listener to Twitch PubSub, that receives color change updates and then updates the circle color
  2. A lightweight EBS that performs the following functionality:
    • Spins up a simple HTTPS server with a POST handler for changing color
    • Validates an Extension JWT
    • Sends a new color message via Twitch PubSub for a specific channel

Using the Sample

The recommended path to using this sample is with the Developer Rig. Use the Developer Rig's extension-init command to clone this repository.

The Developer Rig is able to host the frontend Hello World files, but the EBS must be run and hosted separately.

Setting Up Your Backend Certificates

Twitch Extensions require SSL (TLS).

If you're using the Developer Rig and used it to create this extension, it will have already configured the certificates. Otherwise, you'll need to set up a certificate for local development. This will generate a new certificate (server.crt and server.key) for you and place it in the conf/ directory. This certificate is different from the one used for the Developer Rig.

On MacOS

Navigate to the root of the Hello World extension folder and run npm install and then npm run cert

On Windows

Run the following commands to generate the necessary certificates for your Hello World backend

  1. node scripts/ssl.js
  2. mkdir ../my-extension/conf
  3. mv ssl/selfsigned.crt ../my-extension/conf/server.crt
  4. mv ssl/selfsigned.key ../my-extension/conf/server.key

Running Hello World

If you're using the Developer Rig, it has buttons in its UI to perform the following actions.

To run the EBS, run node services/backend, with the following command line arguments: -c <client id>, -s <secret>, -o <owner id>.

This provides the EBS with your Extension client ID, Extension secret and the user ID of the Extension owner (likely you). These are necessary to validate calls to your EBS and make calls to Twitch services such as PubSub.

If you do not want to pass in command line arguments, you can also directly set the following environment variables: EXT_SECRET, EXT_CLIENT_ID, EXT_OWNER_ID in your code.

You can get your client ID and secret from your Extension Dashboard.

To get the owner ID, you will need to execute a simple CURL command against the Twitch /users endpoint. You'll need your extension client ID as part of the query (this will be made consistent with the Developer Rig shortly, by using owner name).

curl -H "Client-ID: <client id>" -X GET "https://api.twitch.tv/helix/users?login=<owner name>"

Note - If you haven't yet created an extension, you can start that process here.

extensions-hello-world's People

Contributors

tenchumaru avatar colbydude avatar gsmith104 avatar klowner avatar davecusatis avatar

Watchers

Christine avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.