Skip to main content

Interactive Live Quickstart

Quickstart

This page takes you from nothing to a question appearing on a viewer’s screen.

You will need an AntCDN API key scoped to an environment, and an encoder such as OBS.

1. Create an interactive live stream

Set interactive to true when you create the stream. This cannot be added later, so set it now even if you are not sure you will use it.

Terminal window
curl -X POST https://api.antcdn.net/v1/live-streams \
-H "X-Api-Key: $ANTCDN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Launch stream",
"interactive": true,
"recording": true
}'

The response includes your streamId, the RTMP ingest URL and your stream key.

Note

Set recording to true as well if you want the questions to replay over the recording afterwards.

2. Start broadcasting

Point your encoder at the RTMP URL and stream key from step 1. See Encoder setup for settings.

Wait until the stream is live. Questions can only be asked while a stream is broadcasting, because a question needs a point in the broadcast to belong to.

3. Ask a question

Terminal window
curl -X POST https://api.antcdn.net/v1/live-streams/$STREAM_ID/questions \
-H "X-Api-Key: $ANTCDN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Which build should we ship first?",
"options": ["The rewrite", "The patch"],
"allowFreeText": false
}'

You get back the question id and the offset in seconds from the start of the broadcast:

{
"questionId": "lsq_71c4a9",
"offsetSeconds": 412
}

The question is now written into your video. Viewers see it when their playback reaches this point.

4. Show it to viewers

The fastest way is the hosted player. Add interactive=1 to the embed URL and the player draws the question overlay for you:

<iframe
src="https://player.antcdn.net/v1/{edgeId}/master.m3u8?interactive=1"
allow="autoplay; fullscreen"
frameborder="0"
></iframe>

edgeId is returned when you create the stream. It is the playback id, and it is different from streamId, which is the id you use on the API. You only need the edge id here. The player works out which room to join.

If you are building your own player, install the SDK instead:

Terminal window
npm install @antcdn/live-signaling
import { connectLiveRoom } from '@antcdn/live-signaling';
const room = connectLiveRoom({ streamId: 'ls_9f2a' });
room.on('question', (question) => showPoll(question));
room.on('tally', (tally) => updateResults(tally));
room.on('closed', (tally) => showFinalResult(tally));

See Player SDK for the full guide, including how to tell the SDK when playback reaches a question.

5. Close the question

Closing stops the voting and returns the final numbers.

Terminal window
curl -X POST \
https://api.antcdn.net/v1/live-streams/$STREAM_ID/questions/$QUESTION_ID/close \
-H "X-Api-Key: $ANTCDN_API_KEY"
{
"questionId": "lsq_71c4a9",
"counts": [1204, 388],
"total": 1592
}

counts lines up with the options array you sent. Index 0 is the first option.

The result is stored, so you can read it back later from the timeline.

Tip

You do not have to close a question by hand before asking the next one. Asking a new question closes the previous one for you.

What next

  • Let viewers write answers in their own words: set allowFreeText to true and read them back with the responses endpoint.
  • Keep the questions working on the recording: see Recordings.