This demo showcases how Momento elevates media streaming through all the services in its platform. By using Momento Storage, Topics, and Cache, an immersive media experience is created that not only provides a zero buffer rate (ZBR), but also allows for real-time analytics and insights. To view the live demo, you can visit one of the links below.
Momento Storage is used as the media origin. It persists the HLS manifest file along with the segments of the playable media. The browser uses an HLS video streaming library to stream content directly from Momento Storage.
While users are active on the page, a heartbeat is sent to the server component via Momento Topics. The heartbeat contains meta information about the device streaming the data along with data about the player itself. An example heartbeat is below:
{
"playerId": "myPlayerId",
"bitrate": 5000,
"playTime": 21,
"agent": {
"os": "macOS",
"browser": "Google Chrome",
"device": "Desktop"
}
}
These heartbeats are delivered to the server component (an AWS Lambda function) by Momento Topics via a webhook. The server takes the information from the heartbeat and performs three actions:
- Updates a Momento Cache sorted set with the
playerId
and the current time - Overwrites a Momento Cache dictionary item specific to the playerId with the heartbeat data
- Counts all the players from the sorted set that have sent a heartbeat in the past 1.5 seconds and publishes to the viewerCount topic
The media player page subscribes to the viewerCount topic and when the message is recieved, updates the active viewers count seen in the top left corner of the video player.
When a user loads the dashboard, the aggregated data from all the media players is pulled from Momento Cache and used to calculate real-time metrics on the streaming media. Metrics calculated from the heartbeats include:
- Total number of viewers
- Active number of viewers
- Average play time
- Minimum bitrate streamed by any player
- Maximum bitrate streamed by any player
- Average bitrate streamed across all players
- Distribution of viewers by
-
- Device type
-
- Operating system
-
- Browser
All these metrics are calculated on demand and give you a glimpse of the stream at that given point in time.
If you'd like to try this yourself, the entire solution is contained in this repository and is deployable via an AWS SAM template.
- AWS SAM CLI
- AWS CLI
- Node.js 20
- An AWS account and a profile configured on your machine via the AWS CLI
- A Momento API key
To deploy the template to your AWS account, you can run the following commands:
sam build
sam deploy --guided --profile <OPTIONAL PROFILE NAME>
This will guide you through a deployment wizard that will ask you for your Momento API key. Upon successful deployment, the app will be operational and can be found at the VideoBaseUrl
output.