Skip to main content

Twitch Polls Web App

Introduction

The Twitch Polls Web App has been designed to allow Twitch viewers to start predefined polls and vote for specific actions in predefined polls. The outcome of a poll triggers one or more iRacing Live Timing variable value changes. This is the link for the web app: Twitch Polls.

Edit Mode

The application has an Edit mode to build polls and a Run mode for normal operation. Mode can be selected by clicking the Run/Edit button. Settings are automatically saved on exit. If several sets of settings or several simultaneous sessions are required an ?instance=xyz parameter can be added to the URL. For example https://livetiming.sdk-gaming.co.uk/polls.html?instance=settings1 would have different settings than https://livetiming.sdk-gaming.co.uk/polls.html?instance=settings2.

Edit mode user interface:

  • Room name – The room declared in iRacing Live Timing.
  • User name – Represents a user which has been granted access to variables in iRacing Live Timing / F3 Settings / Overlay / Variable Access Credentials. Ensure the user name is entered identically. Set the variable filter to Overlay (to control overlay elements), JumpToEvent (to control showing replays from recorded incidents) and/or IRacing (to control cameras and driver selection).
  • Twitch channel – The Twitch channel the application is listening to and is displaying in the Run page.
  • Message timeout – The time after which chat messages vanish.
  • Polls – Text in JSON format describing polls. Each poll has a name and should have the following properties:
    • help – A small description text
    • actions – A list of actions allowed in the poll. Each action has a name, a help text and a commands string holding statements sent to iRacing Live Timing if the poll succeeds.
    • message – The message that is sent to Twitch chat after the variable is sent to iRacing Live Timing.
    • duration – The time in seconds the poll lasts. Each poll is started as soon as a matching chat message is found. When the poll ends it is waiting for a restart.
    • vote – A permission feature with 3 levels; all, subscriber or mod.
    • reset – A reset feature to switch back to normal operation after the designated time.

Run Mode

In run mode the live Twitch chat is displayed in the upper part of the screen. The lower part displays the current state and results of running polls.

As soon as the Twitch Polls Web App is in run mode it is listening to the chat of the Twitch channel configured in the Edit mode. When a chat message fulfils the following requirements a new poll is started or an existing poll is incremented:

  • Chat message contains 1 or 2 words
  • First word is always a poll name
  • Second word is an action name of the poll
  • If action name is missing, the help text is displayed

In our example logo show or logo hide are valid commands that will be interpreted and displayed in the Poll events window. Operating rules of a poll:

  • When a poll is started the corresponding action (the second word) point count is set to 1.5
  • When a poll is incremented the corresponding action point count has 1 point added
  • When the timeout time of a poll expires the poll ends. The action with the highest point count has its action commands sent to iRacing Live Timing. Then the poll returns to the inactive state waiting to start again.
  • When a viewer changes his mind 1 point is deducted from the previous action point count and 1 point is added to the new action point count

Example Code

In the below example this poll allows viewers to vote for camera selection within iRacing (of course this would only work when the streamer is in Spectator Mode in iRacing).

{
  "cam": {
    "help": "Camera selection: Cockpit, TV1, Gyro or Chopper",
    "actions": {
      "Cockpit": {
        "help": "Votes to show Cockpit Cam",
        "commands": "IRacing.CameraGroupName = 'Cockpit';",
        "message": "Cockpit camera selected!",
        "vote": "all"
      },
      "Gyro": {
        "help": "Votes to show Gyro Cam",
        "commands": "IRacing.CameraGroupName = 'Gyro';",
        "message": "Cockpit camera selected!",
        "vote": "all"
      },
      "Chopper": {
        "help": "Votes to show Choppper",
        "commands": "IRacing.CameraGroupName = 'Chopper';",
        "message": "Cockpit camera selected!",
        "vote": "mod"
      },
      "TV1": {
        "help": "Votes to show TV1 Cam",
        "commands": "IRacing.CameraGroupName = 'TV1';",
        "message": "Cockpit camera selected!",
        "vote": "subscriber"
      }
    },
    "duration": 2,
    "resetTime": 10,
    "resetCommands": "IRacing.CameraGroupName = 'TV2';",
    "resetMessage": "Camera reset to TV2"
  }
}

Let’s break down what is happening in this code. At the start we have the three lines labelled:

cam – The poll name
help – The help text describing the purpose of the pole if only the poll name is typed in chat.
actions – Defining what the viewer can control.

Next repeating through the code is each specific action in the below format:

Cockpit, Gyro, Chopper, TV1 – This is the action name the viewer needs to type in chat to trigger the poll. So in this example they would type either cam Cockpit, cam Gyro, cam Chopper or cam TV1.
help – When a viewer only types the poll name, as well as the main help message above being displayed, it will also list each individual help message for each action.
commands – The variable that should be sent to iRacing Live Timing if the poll succeeds.
message – The message that is sent to Twitch chat after the poll succeeds.
vote – Who is the vote open to; all, subscriber or mod.

Then at the end of the code we have:

duration – How long the poll should run for in seconds.
resetTime – Once the variable is sent to iRacing Live Timing, the duration in seconds until the resetCommands are sent.
resetCommands – What variable should be sent to iRacing Live Timing after the resetTime has expired. In this example we are setting the camera back to TV2 after 10 seconds each time the poll is run.

After this block of code for this one poll, you can of course then other blocks of code using the same format to have multiple polls available. Ask in Discord for assistance if you get stuck!

Was this article helpful?

Related Articles

Leave a Reply

Need Support?

Join our Community Discord Server
Join Discord