CLEAR

LiveStreamingComments


The LiveStreamingComments class provides access to the Facebook Live comments stream.

Properties

PropertyDescription

stream

(get) stream: EventSource (set) (Not Available)

Specifies an EventSource that emits an update every time the Live stream receives a new comment. You may subscribe() to the EventSource and provide it with a callback that takes a single argument; when the callback is called, this argument will have the properties body (containing the text of the comment), and timestampInVideoMs (containing the video timestamp in milliseconds at which the comment was submitted). The stream will only return comments that are displayed on the broadcaster's screen, which in the case of high comment volume will not include every comments. To process potentially large volumes of comments, use the Counter and Vote methods below.

Methods

MethodDescription

startHashtagCounter

startHashtagCounter(): EventSource

Returns an EventSource that emits an update every time there is a change in the count of comments on the Live stream that contain hashtags. Hashtags are counted in case insensitive mode. You may subscribe() to the EventSource and provide a callback that receives a single argument, which will be an associative array of hashtagged strings to comment counts. The hashtags will be provided in a canonical format, which will generally be CamelCase (for example #FacebookLive or #GrilledCheese). Internally, only the first 500 hashtags will be tracked and only the top 20 will be surfaced to the subscription. A maximum of 10 counter/vote subscriptions may be active at a time. If one is created beyond that limit then the oldest one will not receive any more updates. The subscription will receive a maximum of one update per second.

startHashtagVote

startHashtagVote(): EventSource

This method is identical to startHashtagCounter() except that for each user only the first hashtag appeared in his/her comments will be counted.

startMatchCounter

startMatchCounter(matchStrings, isCaseSensitive): EventSource

Returns an EventSource that emits an update every time there is a change in the count of comments on the Live stream that match one or more target strings. The matchStrings argument is an array of strings to search for in comments. The isCaseSensitive determines whether the string matching respects letter case. You may subscribe() to the EventSource and provide a callback that receives a single argument, which will be an associative array of matched strings to comment counts. Up to 20 match strings may be requested in one counter. A maximum of 10 counter/vote subscriptions may be active at a time. If one is created beyond that limit then the oldest one will not receive any more updates. The subscription will receive a maximum of one update per second.

startMatchVote

startMatchVote(matchStrings, isCaseSensitive): EventSource

This method is identical to startMatchCounter() except that for each user only the first matched string appearing in the comment will be counted.

Example

// The following example demonstrates how to monitor comments that match target strings
// For example, to implement comment-based voting
// You can set up an event source with string-matching rules and subscribe to it

const matchStrings = ['pizza', 'cheese', 'meatball'];
const isCaseSensitive = false;

LiveStreamingComments.startMatchVote(
  matchStrings,
  isCaseSensitive
).subscribe(function(result) {
  // Incoming result will be an associative array
  // of matched strings and comment counts, e.g.:
  // { 'pizza': 23, 'cheese': 17, 'meatball': 0 }
  for (var str in result) {
    // ... update the scene with data from the match map ...
  }
});