playable
Version:
Video player based on HTML5Video
147 lines • 6.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DELAYED_REPORT_TYPES = exports.REPORT_REASONS = void 0;
var tslib_1 = require("tslib");
var constants_1 = require("../../constants");
var player_api_decorator_1 = (0, tslib_1.__importDefault)(require("../../core/player-api-decorator"));
exports.REPORT_REASONS = {
LONG_INITIAL_VIDEO_PARTS_LOADING: 'long-initial-video-parts-loading',
LONG_METADATA_LOADING: 'long-metadata-loading',
LONG_SEEK_PROCESSING: 'long-seek-processing',
BUFFER_EMPTY_FOR_CURRENT_SEGMENT: 'buffer-empty-for-current-segment',
LONG_PLAY_REQUESTED_PROCESSING: 'long-play-requested-processing',
};
exports.DELAYED_REPORT_TYPES = {
INITIAL_VIDEO_PARTS_LOADING: {
id: '_initialVideoPartsLoading',
timeoutTime: 5000,
},
METADATA_LOADING: {
id: '_metadataLoading',
timeoutTime: 5000,
},
RUNTIME_LOADING: {
id: '_runtimeLoading',
timeoutTime: 5000,
},
};
var AnomalyBloodhound = /** @class */ (function () {
function AnomalyBloodhound(_a) {
var engine = _a.engine, eventEmitter = _a.eventEmitter;
this._engine = engine;
this._eventEmitter = eventEmitter;
this._timeoutMap = Object.create(null);
this._bindEvents();
}
AnomalyBloodhound.prototype._bindEvents = function () {
this._unbindEvents = this._eventEmitter.bindEvents([[constants_1.VideoEvent.STATE_CHANGED, this._processStateChange]], this);
};
AnomalyBloodhound.prototype._processStateChange = function (_a) {
var prevState = _a.prevState, nextState = _a.nextState;
switch (nextState) {
case constants_1.EngineState.LOAD_STARTED:
if (this._engine.isAutoPlayActive || this._engine.isPreloadActive) {
this.startDelayedReport(exports.DELAYED_REPORT_TYPES.METADATA_LOADING, exports.REPORT_REASONS.LONG_METADATA_LOADING);
}
break;
case constants_1.EngineState.METADATA_LOADED:
if (this.isDelayedReportExist(exports.DELAYED_REPORT_TYPES.METADATA_LOADING)) {
this.stopDelayedReport(exports.DELAYED_REPORT_TYPES.METADATA_LOADING);
if (this._engine.getPreload() !== 'metadata') {
this.startDelayedReport(exports.DELAYED_REPORT_TYPES.INITIAL_VIDEO_PARTS_LOADING, exports.REPORT_REASONS.LONG_INITIAL_VIDEO_PARTS_LOADING);
}
}
break;
case constants_1.EngineState.READY_TO_PLAY:
if (this.isDelayedReportExist(exports.DELAYED_REPORT_TYPES.INITIAL_VIDEO_PARTS_LOADING)) {
this.stopDelayedReport(exports.DELAYED_REPORT_TYPES.INITIAL_VIDEO_PARTS_LOADING);
}
if (this.isDelayedReportExist(exports.DELAYED_REPORT_TYPES.RUNTIME_LOADING)) {
this.stopDelayedReport(exports.DELAYED_REPORT_TYPES.RUNTIME_LOADING);
}
break;
case constants_1.EngineState.SEEK_IN_PROGRESS:
if (prevState === constants_1.EngineState.PAUSED) {
this.startDelayedReport(exports.DELAYED_REPORT_TYPES.RUNTIME_LOADING, exports.REPORT_REASONS.LONG_SEEK_PROCESSING);
}
break;
case constants_1.EngineState.WAITING:
switch (prevState) {
case constants_1.EngineState.PLAYING: {
this.reportDebugInfo({
reason: exports.REPORT_REASONS.BUFFER_EMPTY_FOR_CURRENT_SEGMENT,
});
break;
}
case constants_1.EngineState.PLAY_REQUESTED:
if (!this.isDelayedReportExist(exports.DELAYED_REPORT_TYPES.RUNTIME_LOADING)) {
this.startDelayedReport(exports.DELAYED_REPORT_TYPES.RUNTIME_LOADING, exports.REPORT_REASONS.LONG_PLAY_REQUESTED_PROCESSING);
}
break;
/* ignore coverage */
default:
break;
}
break;
case constants_1.EngineState.PLAYING:
if (this.isDelayedReportExist(exports.DELAYED_REPORT_TYPES.RUNTIME_LOADING)) {
this.stopDelayedReport(exports.DELAYED_REPORT_TYPES.RUNTIME_LOADING);
}
break;
default:
break;
}
};
AnomalyBloodhound.prototype.isDelayedReportExist = function (type) {
return Boolean(this._timeoutMap[type.id]);
};
AnomalyBloodhound.prototype.startDelayedReport = function (type, reason) {
var _this = this;
if (this.isDelayedReportExist(type)) {
this.stopDelayedReport(type);
}
var startTS = Date.now();
this._timeoutMap[type.id] = window.setTimeout(function () {
var endTS = Date.now();
delete _this._timeoutMap;
_this.reportDebugInfo({
reason: reason,
startTS: startTS,
endTS: endTS,
});
}, type.timeoutTime);
};
AnomalyBloodhound.prototype.stopDelayedReport = function (type) {
window.clearTimeout(this._timeoutMap[type.id]);
delete this._timeoutMap[type.id];
};
AnomalyBloodhound.prototype.stopAllDelayedReports = function () {
var _this = this;
Object.keys(this._timeoutMap).forEach(function (key) {
window.clearTimeout(_this._timeoutMap[key]);
delete _this._timeoutMap[key];
});
};
AnomalyBloodhound.prototype.setAnomalyCallback = function (callback) {
if (callback) {
this._callback = callback;
}
};
AnomalyBloodhound.prototype.reportDebugInfo = function (_a) {
var reason = _a.reason, startTS = _a.startTS, endTS = _a.endTS;
this._callback &&
this._callback((0, tslib_1.__assign)({ reason: reason, startTS: startTS, endTS: endTS }, this._engine.getDebugInfo()));
};
AnomalyBloodhound.prototype.destroy = function () {
this.stopAllDelayedReports();
this._unbindEvents();
};
AnomalyBloodhound.moduleName = 'anomalyBloodhound';
AnomalyBloodhound.dependencies = ['eventEmitter', 'engine'];
(0, tslib_1.__decorate)([
(0, player_api_decorator_1.default)()
], AnomalyBloodhound.prototype, "setAnomalyCallback", null);
return AnomalyBloodhound;
}());
exports.default = AnomalyBloodhound;
//# sourceMappingURL=anomaly-bloodhound.js.map