Mux EE Module Docs

for ExpressionEngine

Real-Time Views

Real-time viewers can be displayed when using Mux Data. This works with both assets and live streams. The {real_time_views} tag builds the signed link to request the current views from the Mux API directly.

Web Component

<!-- Include Once, use path to your themes folder. -->
<script type="module" src="/themes/user/mux/components/realtime-views.js"></script>

<!-- Include as many times as needed within a video loop -->
      api="{real_time_views}" // Required
      views // Optional.
      viewers // Optional.

Build Your Own

Simply request the url to get the current real-time views. The data updates no quicker than 5 seconds, so pings should be at least 6 or higher.

For more information, visit the Mux Real-Time guide (steps 1-3 are handled by the MuxEE add-on)

<!-- Sample HTML -->
<span data-realtimeviews data-api="{real_time_views}">
        <output data-views>0</output> views,
        <output data-viewers>0</output> viewers.
(function () {

    // This finds all real-time tags and sets update intervals.
    const views = document.querySelectorAll( '[data-realtimeviews]' );

    if (views) {
        views.forEach( view => {

            const api = view.dataset.api; // Get the URL from the HTML element.

            // Make sure the property with a url was set.
            if (!api) {
                console.debug('No API link found for real-time views.');

            async function getRealTimeViews()
                let viewsdatarequest = await fetch(api);
                let viewsdata = await viewsdatarequest.json();

                view.querySelector('[data-views]').innerHTML =[0].views;
                view.querySelector('[data-viewers]').innerHTML =[0].viewers;
            setInterval(getRealTimeViews, 10000); // Update every 10 seconds.