Skip to content

Commit

Permalink
Delete invalid events which are not in the presentation time of the p…
Browse files Browse the repository at this point in the history
…arent period (#3243)
  • Loading branch information
dsilhavy authored and jeffcunat committed May 5, 2020
1 parent b226bec commit b06acf3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/streaming/controllers/EventController.js
Expand Up @@ -249,7 +249,8 @@ function EventController() {

if (calculatedPresentationTimeInSeconds <= currentVideoTime && calculatedPresentationTimeInSeconds + presentationTimeThreshold >= currentVideoTime) {
_startEvent(eventId, event, events);
} else if (currentVideoTime - presentationTimeThreshold > calculatedPresentationTimeInSeconds) {
} else if (_eventHasExpired(currentVideoTime, presentationTimeThreshold, calculatedPresentationTimeInSeconds) || _eventIsInvalid(event)) {
logger.debug(`Deleting event ${eventId} as it is expired or invalid`);
delete events[eventId];
}
}
Expand All @@ -259,6 +260,24 @@ function EventController() {
}
}

function _eventHasExpired(currentVideoTime, presentationTimeThreshold, calculatedPresentationTimeInSeconds) {
try {
return currentVideoTime - presentationTimeThreshold > calculatedPresentationTimeInSeconds;
} catch (e) {
return false;
}
}

function _eventIsInvalid(event) {
try {
const periodEndTime = event.eventStream.period.start + event.eventStream.period.duration;

return event.calculatedPresentationTime / 1000 > periodEndTime;
} catch (e) {
return false;
}
}

function _triggerRemainingEvents(events) {
try {
const eventIds = Object.keys(events);
Expand Down

0 comments on commit b06acf3

Please sign in to comment.