LiveStreamingModule

The LiveStreamingModule class enables to retrieve information from a live stream from within the effect, such as reactions and comments.

Example

//==============================================================================
// The following example demonstrates how to dynamically update an effect based
// on the reactions and comments of a viewer during a livestream.
//
// Project setup:
// - Insert two text objects
//==============================================================================

// Load in the required modules
const LiveStreaming = require('LiveStreaming');
const Scene = require('Scene');

// Enable async/await in JS [part 1]
(async function() {
  // Locate the text objects in the Scene
  const [angryCountText, matchCounterText] = await Promise.all([
    Scene.root.findFirst('text0'),
    Scene.root.findFirst('text1')
  ]);

  // Store references to the reactions and comments properties
  const reactions = LiveStreaming.reactions;
  const comments = LiveStreaming.comments;

  //==============================================================================
  // Displaying a number based on the number of a certain reaction from viewers
  //==============================================================================

  // Store a reference to the number of angry reactions
  const angryCount = reactions.angry;

  // Bind the number of angry reactions to the text object
  angryCountText.text = angryCount.toString();

  //==============================================================================
  // Displaying a string based on the number of comments from viewers
  //==============================================================================

  // Define what strings we want to start a counter for
  const matchStrings = ['cat','dog'];

  // Define if those strings should be case sensitive or not
  const isCaseSensitive = false;

  // Create a variable to store the highest count
  var leadingCount = 0;

  // Subscribe to the startMatchCounter EventSource
  comments.startMatchCounter(matchStrings,isCaseSensitive).subscribe(
  (result) => {
    // Loop through the keys in the result (e.g. 'cat' or 'dog')
    for (var key in result) {
      // Update the text and leadingCount if the count of the result is
      // is greater than the current leadingCount
      if (result[key] > leadingCount) {
        matchCounterText.text = key;
        leadingCount = result[key];
      }
    }
  });
// Enable async/await in JS [part 2]
})();

Properties

PropertyDescription
comments
(get) comments: LiveStreamingComments
(set) (Not Available)


Provides access to a LiveStreamingComments object that encapsulates data about the live stream's comments.
concurrentViewerCount
(get) concurrentViewerCount: ScalarSignal
(set) (Not Available)


Provides access to a ScalarSignal that encapsulates the number of concurrent viewers of the live stream.
reactions
(get) reactions: LiveStreamingReactions
(set) (Not Available)


Provides access to a LiveStreamingReactions object that encapsulates data about the live stream's reactions.
state
(get) state: Signal<LiveStreamingModule.State>
(set) (Not Available)


Specifies a LiveStreaming.State enum value indicating the broadcast state.

Methods

This module exposes no methods.

Classes

ClassDescription
LiveStreamingCommentsThe LiveStreamingComments class provides access to the Facebook Live comments stream.
LiveStreamingReactionsThe LiveStreamingReactions class provides access to the Facebook Live reactions stream. For low volumes of reactions this will correspond to the stream of reaction bubbles that float by the broadcast, for higher volumes of reactions this will an approximate count of how many times the reaction button was tapped, with some rate limiting per-user. This number will not correspond to the number of reactions displayed elsewhere because that number only counts each user's reaction once.

Enums

EnumDescription
StateThe LiveStreamingModule.State enum describes the state of a live stream.