Accumulation

Accumulation is the simplest form of aggregation. Using this method, the server simply timestamps and concatenates all JSON blobs sent to it.

No combining or processing is done on the data you send and no automatic broadcasting of the data is provided. Your extension (or other authenticated source) must ask for the data using an accessor method. Viewers may not request the data themselves, but the broadcaster live app can get, transform and send the info out to viewers as needed.

Accumulation data expires automatically 1 day after the last entry is added. After that point, all accumulation values will be removed and sending data with the same ‘name’ will act as a new accumulation.

Sending Data

To send a data blob:

const opts = new Muxy.DebuggingOptions();
opts.role('viewer');
Muxy.debug(opts);

const sdk = new Muxy.SDK();
sdk.accumulate('awesomeness_level', {
  awesomeness_level: {
    great: 10,
    good: 2.5,
    poor: 'dank'
  }
});

You may include any data in these blobs (e.g. timestamp or user id info) as long as it is a valid JSON object.

Accessing Data

The broadcaster can request the accumulated data at any point, specifying a max age timestamp:

const oneMinuteAgo = new Date().getTime() - 1000 * 60; // Timestamp in seconds of the oldest entry.

const opts = new Muxy.DebuggingOptions();
opts.role('broadcaster');
Muxy.debug(opts);

const sdk = new Muxy.SDK();
sdk.getAccumulation('awesomeness_level', oneMinuteAgo).then(resp => {
  console.log(resp.latest); // An epoch timestamp of the most recent accumulate entry.
  console.log(resp.data); // A list of all accumulate values since oneMinuteAgo.
});

Response:

{
   "data":[
      {
         "observed": 1503939418480,    // The timestamp of when this accumulate entry was sent.
         "channel_id": "23161357",     // The id of the channel the entry was sent from.
         "opaque_user_id": "A1954218", // The opaque id of the viewer that sent the event.
         "user_id": "",                // The user id of the viewer (if shared).
         "data": {                     // The JSON object that was sent in the request.
            "awesomeness_level": {
               "good": 2.5,
               "great": 10,
               "poor": "dank"
            }
         }
      }
   ],
   "latest": 1503939418480             // The timestamp of the last entry from the server.
}