logo
Menu
Build a UGC Live Streaming App with Amazon IVS: Displaying Viewer Counts on a Channel (Lesson 8.3)

Build a UGC Live Streaming App with Amazon IVS: Displaying Viewer Counts on a Channel (Lesson 8.3)

Welcome to Lesson 8.3 in this series where we're looking at building a web based user-generated content live streaming application with Amazon IVS. This entire series is available in video format on the AWS Developers YouTube channel and all of the code related to the sample application used in this series can be viewed on GitHub. Refer to the links at the end of the post for more information.

Todd Sharp
Amazon Employee
Published Jan 3, 2024

Intro

In this lesson, we'll learn how the StreamCat application retrieves viewer counts for a live stream.

Adding Viewer Counts

In lesson 5.2, we saw how StreamCat adds live stream playback for low-latency streams to the user's channel. In that lesson, we set a variable called isLive to true when playback begins. For viewer counts, if a stream is live, we'll poll the server every 30 seconds to retrieve the latest viewer count.
The updateViewerCount() function makes a call to an endpoint to retrieve the latest viewer count.
This endpoint queries the metrics table for the current stream to retrieve a distinct count of viewer IP addresses as of the most recent minute.

Alternative Approach to Viewer Counts

The @aws-sdk/client-ivs module of the AWS SDK for JavaScript (v3) can also provide viewer count information for a channel, but is limited by service quota limitations. If you'd prefer to utilize this approach, you could use the GetStream (docs) method of the IvsClient.
The GetStreamCommandOutput object contains a stream object which has a viewerCount (docs) property. The docs for this property describe it as:
A count of concurrent views of the stream. Typically, a new view appears in viewerCount within 15 seconds of when video playback starts and a view is removed from viewerCount within 1 minute of when video playback ends. A value of -1 indicates that the request timed out; in this case, retry.

Summary

In this lesson, we saw how StreamCat retrieves viewer counts for a user's live stream. In the next lesson, we'll see how StreamCat supports 'following' another user's channel.

Links

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments