Eventi in coda quando la risposta delle sessioni è lenta queueing-events-when-sessions-response-is-slow

L’API Media Collection è RESTful: ad esempio effettui una richiesta HTTP e attendi la risposta. Questo è un punto importante solo se esegui una Richiesta sessioni per ottenere un ID sessione all’inizio della riproduzione video. È importante perché l’ID sessione è necessario per tutte le chiamate di tracciamento successive.

È possibile che il lettore possa attivare eventi prima che venga restituita la Richiesta sessioni (con il parametro ID sessione) dal backend. In questo caso, l’app deve mettere in coda tutti gli eventi di tracciamento che arrivano tra la Richiesta sessioni e la relativa risposta. Quando la Risposta sessioni arriva, devi prima elaborare tutti gli eventi in coda, quindi puoi iniziare l’elaborazione degli eventi live con le chiamate Eventi.

NOTE
La Richiesta eventi non restituisce i dati al client oltre un codice di risposta HTTP.

Controlla il Lettore di riferimento nella tua distribuzione per sapere come elaborare gli eventi prima di ricevere un ID sessione. Ad esempio:

var eventData = {};            // JSON payload
eventData.playerTime = getPlayerTime(); // Required
eventData.eventType = "play";           // Required
eventData.params = {};                  // Optional for events

VideoPlayer.prototype._collectEvent =
  function(eventData) {

    // If we don't have a Session ID yet,
    // queue the event and return...
    if (!sessionStarted) {
        console.log("[Player] Queueing event ");
        _pendingEvents.push(eventData);
        return;
    }

    // If we DO have a Session ID, process the
    // tracking event...
    apiClient.request({
        "baseUrl": "{endpoint}",
        "path": "api/v1/{sid}/events", // events request
        "method": "POST",
        "data": eventData
    }).then((response) => {
        […]
    }
}

VideoPlayer.prototype.collectEvent =
  function (eventType, eventParams) {

    if (typeof eventParams === 'undefined') {
        eventParams = {};
    }

    this._collectEvent({
        eventType: eventType,            // Required
        playerTime: getPlayerTime(),     // Required
        params: eventParams              // Optional
    });
};

VideoPlayer.prototype.getPlayerTime = function() {
    return {
        playhead: this.getPlayhead(),    // playhead value in seconds
        ts: this.getCurrentTimestamp()   // timestamp value in milliseconds
    };
};

Elabora tutti gli eventi in coda. Il lettore di riferimento elabora gli eventi in coda come segue:

    […]
    this._processPendingEvents();    // Once you have a Session ID,
    […]                              // process any queued events

VideoPlayer.prototype._processPendingEvents =
  function() {
    this._pendingEvents.forEach((eventData) => {
        this._collectEvent(eventData);
    });

    this._pendingEvents = [];
}

Continua a elaborare gli eventi di tracciamento man mano che si verificano.

recommendation-more-help
c8eee520-cef5-4f8c-a38a-d4952cfae4eb