dictrigyn-video-player
Version:
Contains Video player library components powered by angular. These components are designed to be used in sunbird consumption platforms *(mobile app, web portal, offline desktop app)* to drive reusability, maintainability hence reducing the redundant devel
1,246 lines (1,241 loc) • 85.3 kB
JavaScript
import { Injectable, ɵɵdefineInjectable, ɵɵinject, EventEmitter, Optional, Component, ChangeDetectorRef, Renderer2, Input, Output, ViewChild, HostListener, ViewEncapsulation, NgModule } from '@angular/core';
import { isEmpty, isArray, forEach, some, last, get, filter } from 'lodash-es';
import { CsTelemetryModule } from '@project-sunbird/client-services/telemetry';
import { errorCode, errorMessage, ErrorService, SunbirdPlayerSdkModule } from '@dicdikshaorg/player-sdk-v9';
import { __awaiter } from 'tslib';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { QuestionCursor, QumlLibraryModule } from '@project-sunbird/sunbird-quml-player-v9';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import 'videojs-contrib-quality-levels';
import videojshttpsourceselector from 'videojs-http-source-selector';
/**
* @fileoverview added by tsickle
* Generated from: lib/services/util.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class UtilService {
/**
* @param {?=} length
* @return {?}
*/
uniqueId(length = 32) {
/** @type {?} */
let result = '';
/** @type {?} */
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
/** @type {?} */
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
/**
* @param {?} duration
* @return {?}
*/
getTimeSpentText(duration) {
/** @type {?} */
const minutes = Math.floor(duration / 60000);
/** @type {?} */
const seconds = Number(((duration % 60000) / 1000).toFixed(0));
return (minutes + ':' + (seconds < 10 ? '0' : '') + seconds);
}
}
UtilService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */ UtilService.ɵprov = ɵɵdefineInjectable({ factory: function UtilService_Factory() { return new UtilService(); }, token: UtilService, providedIn: "root" });
/**
* @fileoverview added by tsickle
* Generated from: lib/sunbird-video-player.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class SunbirdVideoPlayerService {
/**
* @param {?} utilService
*/
constructor(utilService) {
this.utilService = utilService;
this.contentSessionId = this.utilService.uniqueId();
}
/**
* @param {?} __0
* @return {?}
*/
initialize({ context, config, metadata }) {
this.context = context;
this.config = config;
this.playSessionId = this.utilService.uniqueId();
if (!CsTelemetryModule.instance.isInitialised) {
CsTelemetryModule.instance.init({});
CsTelemetryModule.instance.telemetryService.initTelemetry({
config: {
pdata: context.pdata,
env: 'contentplayer',
channel: context.channel,
did: context.did,
authtoken: context.authToken || '',
uid: context.uid || '',
sid: context.sid,
batchsize: 20,
mode: context.mode,
host: context.host || '',
endpoint: context.endpoint || '/data/v3/telemetry',
tags: context.tags,
cdata: [{ id: this.contentSessionId, type: 'ContentSession' },
{ id: this.playSessionId, type: 'PlaySession' },
{ id: '2.0', type: 'PlayerVersion' }]
},
userOrgDetails: {}
});
}
this.telemetryObject = {
id: metadata.identifier,
type: 'Content',
ver: metadata.pkgVersion + '',
rollup: context.objectRollup || {}
};
}
/**
* @param {?} duration
* @return {?}
*/
start(duration) {
CsTelemetryModule.instance.telemetryService.raiseStartTelemetry({
options: this.getEventOptions(),
edata: { type: 'content', mode: 'play', pageid: '', duration: Number((duration / 1e3).toFixed(2)) }
});
}
/**
* @param {?} duration
* @param {?} totallength
* @param {?} currentlength
* @param {?} endpageseen
* @param {?} totalseekedlength
* @param {?} visitedlength
* @param {?} score
* @return {?}
*/
end(duration, totallength, currentlength, endpageseen, totalseekedlength, visitedlength, score) {
/** @type {?} */
const durationSec = Number((duration / 1e3).toFixed(2));
CsTelemetryModule.instance.telemetryService.raiseEndTelemetry({
edata: {
type: 'content',
mode: 'play',
pageid: 'sunbird-player-Endpage',
summary: [
{
progress: Number(((currentlength / totallength) * 100).toFixed(0))
},
{
totallength
},
{
visitedlength
},
{
visitedcontentend: (totallength === currentlength)
},
{
totalseekedlength
},
{
endpageseen
},
{
score
}
],
duration: durationSec
},
options: this.getEventOptions()
});
}
/**
* @param {?} id
* @param {?} currentPage
* @param {?=} extraValues
* @return {?}
*/
interact(id, currentPage, extraValues) {
CsTelemetryModule.instance.telemetryService.raiseInteractTelemetry({
options: this.getEventOptions(),
edata: { type: 'TOUCH', subtype: '', id, pageid: currentPage + '', extra: extraValues }
});
}
/**
* @param {?} data
* @return {?}
*/
heartBeat(data) {
CsTelemetryModule.instance.playerTelemetryService.onHeartBeatEvent(data, {});
}
/**
* @param {?} currentPage
* @param {?=} cdata
* @return {?}
*/
impression(currentPage, cdata = {}) {
/** @type {?} */
const impressionEvent = {
options: this.getEventOptions(),
edata: { type: 'workflow', subtype: '', pageid: currentPage + '', uri: '' }
};
if (!isEmpty(cdata)) {
impressionEvent.options.context.cdata.push(cdata);
}
CsTelemetryModule.instance.telemetryService.raiseImpressionTelemetry(impressionEvent);
}
/**
* @param {?} errorCode
* @param {?} errorType
* @param {?=} stacktrace
* @return {?}
*/
error(errorCode, errorType, stacktrace) {
CsTelemetryModule.instance.telemetryService.raiseErrorTelemetry({
options: this.getEventOptions(),
edata: {
err: errorCode,
errtype: errorType,
stacktrace: (stacktrace && stacktrace.toString()) || ''
}
});
}
/**
* @private
* @return {?}
*/
getEventOptions() {
return ({
object: this.telemetryObject,
context: {
channel: this.context.channel,
pdata: this.context.pdata,
env: 'contentplayer',
sid: this.context.sid,
uid: this.context.uid,
cdata: [{ id: this.contentSessionId, type: 'ContentSession' },
{ id: this.playSessionId, type: 'PlaySession' },
{ id: '2.0', type: 'PlayerVersion' }],
rollup: this.context.contextRollup || {}
}
});
}
}
SunbirdVideoPlayerService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
SunbirdVideoPlayerService.ctorParameters = () => [
{ type: UtilService }
];
/** @nocollapse */ SunbirdVideoPlayerService.ɵprov = ɵɵdefineInjectable({ factory: function SunbirdVideoPlayerService_Factory() { return new SunbirdVideoPlayerService(ɵɵinject(UtilService)); }, token: SunbirdVideoPlayerService, providedIn: "root" });
if (false) {
/**
* @type {?}
* @private
*/
SunbirdVideoPlayerService.prototype.contentSessionId;
/**
* @type {?}
* @private
*/
SunbirdVideoPlayerService.prototype.playSessionId;
/**
* @type {?}
* @private
*/
SunbirdVideoPlayerService.prototype.telemetryObject;
/**
* @type {?}
* @private
*/
SunbirdVideoPlayerService.prototype.context;
/** @type {?} */
SunbirdVideoPlayerService.prototype.config;
/**
* @type {?}
* @private
*/
SunbirdVideoPlayerService.prototype.utilService;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/services/viewer.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class ViewerService {
/**
* @param {?} videoPlayerService
* @param {?} utilService
* @param {?} http
* @param {?} questionCursor
*/
constructor(videoPlayerService, utilService, http, questionCursor) {
this.videoPlayerService = videoPlayerService;
this.utilService = utilService;
this.http = http;
this.questionCursor = questionCursor;
this.endPageSeen = false;
this.timeSpent = '0:0';
this.version = '1.0';
this.playerEvent = new EventEmitter();
this.sidebarMenuEvent = new EventEmitter();
this.isAvailableLocally = false;
this.interceptionResponses = {};
this.showScore = false;
this.scoreObtained = 0;
this.contentMap = {};
this.isEndEventRaised = false;
this.PlayerLoadStartedAt = new Date().getTime();
}
/**
* @param {?} __0
* @return {?}
*/
initialize({ context, config, metadata }) {
this.contentName = metadata.name;
this.isAvailableLocally = metadata.isAvailableLocally;
this.streamingUrl = metadata.streamingUrl;
this.artifactUrl = metadata.artifactUrl;
this.mimeType = metadata.streamingUrl ? 'application/x-mpegURL' : metadata.mimeType;
this.artifactMimeType = metadata.mimeType;
this.isAvailableLocally = metadata.isAvailableLocally;
this.traceId = config.traceId;
this.interceptionPoints = metadata.interceptionPoints;
if (context.userData) {
const { userData: { firstName, lastName } } = context;
this.userName = firstName === lastName ? firstName : `${firstName} ${lastName}`;
}
this.metaData = {
actions: [],
volume: [],
playBackSpeeds: [],
totalDuration: 0,
muted: undefined,
currentDuration: undefined,
transcripts: []
};
this.transcripts = metadata.transcripts ? metadata.transcripts : [];
this.showDownloadPopup = false;
this.endPageSeen = false;
if (this.isAvailableLocally) {
/** @type {?} */
const basePath = (metadata.streamingUrl) ? (metadata.streamingUrl) : (metadata.basePath || metadata.baseDir);
this.streamingUrl = `${basePath}/${metadata.artifactUrl}`;
this.mimeType = metadata.mimeType;
}
}
/**
* @param {?} selectedTranscripts
* @return {?}
*/
handleTranscriptsData(selectedTranscripts) {
this.metaData.transcripts = selectedTranscripts;
if (!isArray(this.transcripts)) {
this.raiseExceptionLog('INVALID_TRANSCRIPT_DATATYPE', 'TRANSCRIPT', new Error('Transcript data should be array'), this.traceId);
return [];
}
else {
forEach(this.transcripts, (/**
* @param {?} value
* @return {?}
*/
(value) => {
if (!(some(this.transcripts, { language: value.language, artifactUrl: value.artifactUrl,
languageCode: value.languageCode, identifier: value.identifier }))) {
this.raiseExceptionLog('TRANSCRIPT_DATA_MISSING', 'TRANSCRIPT', new Error('Transcript object dose not have required fields'), this.traceId);
return [];
}
else if (!isEmpty(selectedTranscripts) &&
(last(selectedTranscripts) !== 'off' && last(selectedTranscripts) === value.languageCode)) {
value.default = true;
}
}));
}
return this.transcripts;
}
/**
* @return {?}
*/
getPlayerOptions() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.streamingUrl) {
return [{ src: this.artifactUrl, type: this.artifactMimeType }];
}
else {
/** @type {?} */
const data = yield this.http.head(this.streamingUrl, { responseType: 'blob' }).toPromise().catch((/**
* @param {?} error
* @return {?}
*/
error => {
// tslint:disable-next-line:max-line-length
this.raiseExceptionLog(errorCode.streamingUrlSupport, errorMessage.streamingUrlSupport, new Error(`Streaming Url Not Supported ${this.streamingUrl}`), this.traceId);
}));
if (data) {
return [{ src: this.streamingUrl, type: this.mimeType }];
}
else {
return [{ src: this.artifactUrl, type: this.artifactMimeType }];
}
}
});
}
/**
* @return {?}
*/
getMarkers() {
var _a, _b;
if ((_b = (_a = this) === null || _a === void 0 ? void 0 : _a.interceptionPoints) === null || _b === void 0 ? void 0 : _b.items) {
try {
/** @type {?} */
const interceptionPoints = this.interceptionPoints;
this.showScore = true;
return interceptionPoints.items.map((/**
* @param {?} __0
* @return {?}
*/
({ interceptionPoint, identifier, type }) => {
return { time: interceptionPoint, type, identifier, duration: 3 };
}));
}
catch (error) {
console.log(error);
this.raiseExceptionLog('CPV2_CONT_INTERCEPTION_PARSE', 'error parsing the inteception points string', error, '');
this.showScore = false;
}
}
return null;
}
/**
* @param {?} identifier
* @return {?}
*/
getQuestionSet(identifier) {
/** @type {?} */
const content = this.contentMap[identifier];
if (!content) {
if (!this.questionCursor) {
return null;
}
else {
return this.questionCursor.getQuestionSet(identifier)
.pipe(map((/**
* @param {?} response
* @return {?}
*/
(response) => {
this.contentMap[identifier] = response.questionSet;
return this.contentMap[identifier];
})));
}
}
else {
return of(content);
}
}
/**
* @return {?}
*/
preFetchContent() {
/** @type {?} */
const nextMarker = this.getNextMarker();
if (nextMarker) {
/** @type {?} */
const identifier = nextMarker.identifier;
this.getQuestionSet(nextMarker.identifier);
}
}
/**
* @return {?}
*/
getNextMarker() {
/** @type {?} */
const currentTime = this.playerInstance.currentTime();
/** @type {?} */
const markersList = this.getMarkers();
if (!markersList) {
return null;
}
return markersList.find((/**
* @param {?} marker
* @return {?}
*/
marker => {
/** @type {?} */
const markerTime = marker.time;
return markerTime > currentTime;
}));
}
/**
* @param {?} event
* @return {?}
*/
raiseStartEvent(event) {
/** @type {?} */
const duration = new Date().getTime() - this.PlayerLoadStartedAt;
/** @type {?} */
const startEvent = {
eid: 'START',
ver: this.version,
edata: {
type: 'START',
mode: 'play',
duration
},
metaData: this.metaData
};
this.playerEvent.emit(startEvent);
this.videoPlayerService.start(duration);
this.PlayerLoadStartedAt = new Date().getTime();
}
/**
* @return {?}
*/
calculateScore() {
this.scoreObtained = Object.values(this.interceptionResponses).reduce((
// tslint:disable-next-line:no-string-literal
/**
* @param {?} acc
* @param {?} response
* @return {?}
*/
(acc, response) => acc + response['score']), 0);
}
/**
* @return {?}
*/
raiseEndEvent() {
if (!this.isEndEventRaised) {
this.calculateScore();
/** @type {?} */
const duration = new Date().getTime() - this.PlayerLoadStartedAt;
/** @type {?} */
const endEvent = {
eid: 'END',
ver: this.version,
edata: {
type: 'END',
currentTime: this.currentlength,
totalTime: this.totalLength,
duration
},
metaData: this.metaData
};
this.playerEvent.emit(endEvent);
this.timeSpent = this.utilService.getTimeSpentText(this.visitedLength);
this.videoPlayerService.end(duration, this.totalLength, this.currentlength, this.endPageSeen, this.totalSeekedLength, this.visitedLength / 1000, this.scoreObtained);
this.isEndEventRaised = true;
}
}
/**
* @param {?} type
* @param {?=} extraValues
* @return {?}
*/
raiseHeartBeatEvent(type, extraValues) {
if (type === 'REPLAY') {
this.interceptionResponses = {};
this.showScore = false;
this.scoreObtained = 0;
}
/** @type {?} */
const hearBeatEvent = {
eid: 'HEARTBEAT',
ver: this.version,
edata: {
type,
currentPage: 'videostage',
extra: extraValues
},
metaData: this.metaData
};
this.playerEvent.emit(hearBeatEvent);
this.videoPlayerService.heartBeat(hearBeatEvent);
/** @type {?} */
const interactItems = ['PLAY', 'PAUSE', 'EXIT', 'VOLUME_CHANGE', 'DRAG',
'RATE_CHANGE', 'CLOSE_DOWNLOAD', 'DOWNLOAD', 'NAVIGATE_TO_PAGE',
'NEXT', 'OPEN_MENU', 'PREVIOUS', 'CLOSE_MENU', 'DOWNLOAD_MENU', 'DOWNLOAD_POPUP_CLOSE', 'DOWNLOAD_POPUP_CANCEL',
'SHARE', 'REPLAY', 'FORWARD', 'BACKWARD', 'FULLSCREEN', 'NEXT_CONTENT_PLAY', 'TRANSCRIPT_LANGUAGE_OFF',
'TRANSCRIPT_LANGUAGE_SELECTED', 'VIDEO_MARKER_SELECTED'
];
if (interactItems.includes(type)) {
this.videoPlayerService.interact(type.toLowerCase(), 'videostage', extraValues);
}
}
/**
* @param {?} pageId
* @param {?=} cdata
* @return {?}
*/
raiseImpressionEvent(pageId, cdata = {}) {
this.videoPlayerService.impression(pageId, cdata);
}
// tslint:disable-next-line:no-shadowed-variable
/**
* @param {?} errorCode
* @param {?} errorType
* @param {?} stacktrace
* @param {?} traceId
* @return {?}
*/
raiseExceptionLog(errorCode, errorType, stacktrace, traceId) {
/** @type {?} */
const exceptionLogEvent = {
eid: 'ERROR',
edata: {
err: errorCode,
errtype: errorType,
requestid: traceId || '',
stacktrace: (stacktrace && stacktrace.toString()) || '',
}
};
this.playerEvent.emit(exceptionLogEvent);
this.videoPlayerService.error(errorCode, errorType, stacktrace);
}
}
ViewerService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
ViewerService.ctorParameters = () => [
{ type: SunbirdVideoPlayerService },
{ type: UtilService },
{ type: HttpClient },
{ type: QuestionCursor, decorators: [{ type: Optional }] }
];
/** @nocollapse */ ViewerService.ɵprov = ɵɵdefineInjectable({ factory: function ViewerService_Factory() { return new ViewerService(ɵɵinject(SunbirdVideoPlayerService), ɵɵinject(UtilService), ɵɵinject(HttpClient), ɵɵinject(QuestionCursor, 8)); }, token: ViewerService, providedIn: "root" });
if (false) {
/** @type {?} */
ViewerService.prototype.endPageSeen;
/** @type {?} */
ViewerService.prototype.timeSpent;
/**
* @type {?}
* @private
*/
ViewerService.prototype.version;
/** @type {?} */
ViewerService.prototype.playerEvent;
/** @type {?} */
ViewerService.prototype.contentName;
/** @type {?} */
ViewerService.prototype.showDownloadPopup;
/** @type {?} */
ViewerService.prototype.streamingUrl;
/** @type {?} */
ViewerService.prototype.mimeType;
/** @type {?} */
ViewerService.prototype.artifactMimeType;
/** @type {?} */
ViewerService.prototype.userName;
/** @type {?} */
ViewerService.prototype.metaData;
/** @type {?} */
ViewerService.prototype.PlayerLoadStartedAt;
/** @type {?} */
ViewerService.prototype.totalLength;
/** @type {?} */
ViewerService.prototype.currentlength;
/** @type {?} */
ViewerService.prototype.totalSeekedLength;
/** @type {?} */
ViewerService.prototype.artifactUrl;
/** @type {?} */
ViewerService.prototype.visitedLength;
/** @type {?} */
ViewerService.prototype.sidebarMenuEvent;
/** @type {?} */
ViewerService.prototype.traceId;
/** @type {?} */
ViewerService.prototype.isAvailableLocally;
/** @type {?} */
ViewerService.prototype.interceptionPoints;
/** @type {?} */
ViewerService.prototype.interceptionResponses;
/** @type {?} */
ViewerService.prototype.showScore;
/** @type {?} */
ViewerService.prototype.scoreObtained;
/** @type {?} */
ViewerService.prototype.maxScore;
/** @type {?} */
ViewerService.prototype.playerInstance;
/** @type {?} */
ViewerService.prototype.contentMap;
/** @type {?} */
ViewerService.prototype.isEndEventRaised;
/** @type {?} */
ViewerService.prototype.transcripts;
/**
* @type {?}
* @private
*/
ViewerService.prototype.videoPlayerService;
/**
* @type {?}
* @private
*/
ViewerService.prototype.utilService;
/**
* @type {?}
* @private
*/
ViewerService.prototype.http;
/** @type {?} */
ViewerService.prototype.questionCursor;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/sunbird-video-player.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class SunbirdVideoPlayerComponent {
/**
* @param {?} videoPlayerService
* @param {?} viewerService
* @param {?} cdr
* @param {?} renderer2
* @param {?} errorService
*/
constructor(videoPlayerService, viewerService, cdr, renderer2, errorService) {
this.videoPlayerService = videoPlayerService;
this.viewerService = viewerService;
this.cdr = cdr;
this.renderer2 = renderer2;
this.errorService = errorService;
this.telemetryEvent = new EventEmitter();
this.viewState = 'player';
this.showControls = true;
this.sideMenuConfig = {
showShare: true,
showDownload: true,
showReplay: true,
showExit: true
};
this.isPaused = false;
this.showQumlPlayer = false;
this.QumlPlayerConfig = {};
this.isFullScreen = false;
this.raiseInternetDisconnectionError = (/**
* @return {?}
*/
() => {
/** @type {?} */
const code = errorCode.internetConnectivity;
/** @type {?} */
const message = errorMessage.internetConnectivity;
/** @type {?} */
const stacktrace = `${code}: ${message}`;
this.viewerService.raiseExceptionLog(code, message, stacktrace, this.traceId);
});
this.playerEvent = this.viewerService.playerEvent;
this.viewerService.playerEvent.subscribe((/**
* @param {?} event
* @return {?}
*/
event => {
if (event.type === 'pause') {
this.isPaused = true;
this.showControls = true;
}
if (event.type === 'play') {
this.isPaused = false;
}
if (event.type === 'loadstart') {
this.viewerService.raiseStartEvent(event);
}
if (event.type === 'ended') {
this.viewerService.endPageSeen = true;
this.viewerService.raiseEndEvent();
this.viewState = 'end';
}
if (event.type === 'error') {
// tslint:disable-next-line:one-variable-per-declaration
/** @type {?} */
let code = errorCode.contentLoadFails;
/** @type {?} */
let message = errorMessage.contentLoadFails;
if (this.viewerService.isAvailableLocally) {
code = errorCode.contentLoadFails;
message = errorMessage.contentLoadFails;
}
if (code === errorCode.contentLoadFails) {
this.showContentError = true;
}
this.viewerService.raiseExceptionLog(code, message, event, this.traceId);
}
// tslint:disable-next-line:max-line-length
/** @type {?} */
const events = [{ type: 'volumechange', telemetryEvent: 'VOLUME_CHANGE' }, { type: 'seeking', telemetryEvent: 'DRAG' }, { type: 'fullscreen', telemetryEvent: 'FULLSCREEN' },
{ type: 'ratechange', telemetryEvent: 'RATE_CHANGE' }];
events.forEach((/**
* @param {?} data
* @return {?}
*/
data => {
if (event.type === data.type) {
this.viewerService.raiseHeartBeatEvent(data.telemetryEvent);
}
}));
}));
}
/**
* @param {?} event
* @return {?}
*/
onTelemetryEvent(event) {
this.telemetryEvent.emit(event.detail);
}
/**
* @return {?}
*/
ngOnInit() {
if (typeof this.playerConfig === 'string') {
try {
this.playerConfig = JSON.parse(this.playerConfig);
}
catch (error) {
console.error('Invalid playerConfig: ', error);
}
}
setInterval((/**
* @return {?}
*/
() => {
if (!this.isPaused) {
this.showControls = false;
}
}), 5000);
/* tslint:disable:no-string-literal */
this.nextContent = this.playerConfig.config.nextContent;
this.traceId = this.playerConfig.config['traceId'];
this.sideMenuConfig = Object.assign(Object.assign({}, this.sideMenuConfig), this.playerConfig.config.sideMenu);
this.videoPlayerService.initialize(this.playerConfig);
this.viewerService.initialize(this.playerConfig);
window.addEventListener('offline', this.raiseInternetDisconnectionError, true);
this.QumlPlayerConfig.config = this.playerConfig.config;
this.QumlPlayerConfig.config.sideMenu.enable = false;
this.QumlPlayerConfig.context = this.playerConfig.context;
this.setTelemetryObjectRollup(this.playerConfig.metadata.identifier);
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (changes.action) {
if (!this.showQumlPlayer) {
this.playerAction = this.action;
}
}
}
/**
* @return {?}
*/
ngAfterViewInit() {
/** @type {?} */
const videoPlayerElement = this.videoPlayerRef.nativeElement;
this.unlistenMouseMove = this.renderer2.listen(videoPlayerElement, 'mousemove', (/**
* @return {?}
*/
() => {
this.showControls = true;
}));
this.unlistenTouchStart = this.renderer2.listen(videoPlayerElement, 'touchstart', (/**
* @return {?}
*/
() => {
this.showControls = true;
}));
/** @type {?} */
const contentCompabilityLevel = this.playerConfig.metadata['compatibilityLevel'];
if (contentCompabilityLevel) {
/** @type {?} */
const checkContentCompatible = this.errorService.checkContentCompatibility(contentCompabilityLevel);
if (!checkContentCompatible['isCompitable']) {
// tslint:disable-next-line:max-line-length
this.viewerService.raiseExceptionLog(errorCode.contentCompatibility, errorMessage.contentCompatibility, checkContentCompatible['error']['message'], this.traceId);
}
}
}
/**
* @param {?} event
* @return {?}
*/
sideBarEvents(event) {
this.playerEvent.emit(event);
if (event.type === 'DOWNLOAD') {
this.downloadVideo();
}
/** @type {?} */
const events = ['SHARE', 'DOWNLOAD_MENU', 'EXIT', 'CLOSE_MENU', 'OPEN_MENU', 'DOWNLOAD_POPUP_CANCEL', 'DOWNLOAD_POPUP_CLOSE'];
events.forEach((/**
* @param {?} data
* @return {?}
*/
data => {
if (event.type === data) {
this.viewerService.raiseHeartBeatEvent(data);
}
if (event.type === 'EXIT') {
this.viewerService.sidebarMenuEvent.emit('CLOSE_MENU');
}
}));
}
/**
* @param {?} id
* @return {?}
*/
setTelemetryObjectRollup(id) {
if (this.QumlPlayerConfig.context) {
/** @type {?} */
const hasObjectRollup = this.QumlPlayerConfig && this.QumlPlayerConfig.context && this.QumlPlayerConfig.context.objectRollup;
if (!hasObjectRollup) {
this.QumlPlayerConfig.context.objectRollup = {};
}
/** @type {?} */
const levels = Object.keys(this.QumlPlayerConfig.context.objectRollup);
this.QumlPlayerConfig.context.objectRollup[`l${levels.length + 1}`] = id;
}
}
/**
* @param {?} event
* @return {?}
*/
playContent(event) {
this.viewerService.raiseHeartBeatEvent(event.type);
}
/**
* @param {?} event
* @return {?}
*/
replayContent(event) {
this.playerEvent.emit(event);
this.viewState = 'player';
this.viewerService.isEndEventRaised = false;
this.viewerService.raiseHeartBeatEvent('REPLAY');
}
/**
* @param {?} event
* @return {?}
*/
exitContent(event) {
this.playerEvent.emit(event);
this.viewerService.raiseHeartBeatEvent('EXIT');
}
/**
* @return {?}
*/
downloadVideo() {
/** @type {?} */
const a = document.createElement('a');
a.href = this.viewerService.artifactUrl;
a.download = this.viewerService.contentName;
a.target = '_blank';
document.body.appendChild(a);
a.click();
a.remove();
this.viewerService.raiseHeartBeatEvent('DOWNLOAD');
}
/**
* @param {?} event
* @return {?}
*/
qumlPlayerEvents(event) {
if (event.eid === 'QUML_SUMMARY') {
this.showQumlPlayer = false;
/** @type {?} */
const score = parseInt(event.edata.extra.find((/**
* @param {?} p
* @return {?}
*/
p => p.id === 'score'))['value'], 10);
this.viewerService.interceptionResponses[this.currentInterceptionTime] = {
score,
isSkipped: false
};
/** @type {?} */
const interceptPointElement = document.querySelector(`[data-marker-time="${this.currentInterceptionTime}"]`);
if (interceptPointElement) {
interceptPointElement['style'].background = 'green';
}
this.videoInstance.play();
this.videoInstance.controls(true);
this.viewerService.raiseImpressionEvent('video');
// if currently video is not in full screen and was previously full screen then set it back to full screen again
if (!document.fullscreenElement && this.isFullScreen) {
if (document.getElementsByClassName('video-js')[0]) {
document.getElementsByClassName('video-js')[0].requestFullscreen()
.catch((/**
* @param {?} err
* @return {?}
*/
(err) => console.error(err)));
}
}
}
}
/**
* @param {?} __0
* @return {?}
*/
questionSetData({ response, time, identifier }) {
this.QumlPlayerConfig.metadata = response;
this.QumlPlayerConfig.metadata['showStartPage'] = 'No';
this.QumlPlayerConfig.metadata['showEndPage'] = 'No';
this.currentInterceptionTime = time;
this.currentInterceptionUIId = identifier;
if (document.fullscreenElement) {
this.isFullScreen = true;
document.exitFullscreen()
.catch((/**
* @param {?} err
* @return {?}
*/
(err) => console.error(err)));
}
else {
this.isFullScreen = false;
}
this.showQumlPlayer = true;
this.viewerService.raiseImpressionEvent('interactive-question-set', { id: identifier, type: 'QuestionSet' });
this.viewerService.raiseHeartBeatEvent('VIDEO_MARKER_SELECTED', {
identifier,
// Question set id,
type: 'QuestionSet',
// Type of interaction
interceptedAt: time // Time when the interception happened
});
}
/**
* @param {?} event
* @return {?}
*/
playerInstance(event) {
this.videoInstance = event;
}
/**
* @return {?}
*/
ngOnDestroy() {
this.viewerService.raiseEndEvent();
this.unlistenTouchStart();
this.unlistenMouseMove();
this.viewerService.isEndEventRaised = false;
window.removeEventListener('offline', this.raiseInternetDisconnectionError, true);
}
}
SunbirdVideoPlayerComponent.decorators = [
{ type: Component, args: [{
selector: 'sunbird-video-player',
template: "<div class=\"sunbird-video-player-container\" #videoPlayer [ngClass]=\"showQumlPlayer ? 'videoPlayerHide': 'videoPlayerShow'\">\r\n <sb-player-side-menu-icon class=\"sb-player-side-menu-icon notVisible\" tabindex=\"0\" (sidebarMenuEvent)=\"sideBarEvents($event)\"\r\n\r\n *ngIf=\"viewState ==='player'\" [ngClass]=\"{'isVisible': showControls}\"></sb-player-side-menu-icon>\r\n <video-player *ngIf=\"viewState === 'player'\" (questionSetData)=\"questionSetData($event)\" (playerInstance)=\"playerInstance($event)\" [config]=\"playerConfig.config\" [action]=\"playerAction\">\r\n </video-player>\r\n <sb-player-sidebar *ngIf=\"viewState ==='player'\"\r\n [title]=\"viewerService.contentName\"\r\n (sidebarEvent)=\"sideBarEvents($event)\" [config]=\"sideMenuConfig\"></sb-player-sidebar>\r\n <sb-player-end-page \r\n [contentName]=\"viewerService.contentName\" \r\n [outcomeLabel]=\"viewerService.showScore ? 'Score: ': ''\" \r\n [outcome]=\"viewerService.showScore ? viewerService.scoreObtained + ((viewerService.maxScore && viewerService.maxScore > 0) ? '/' + viewerService.maxScore : '') : ''\"\r\n [nextContent]=\"nextContent\" [userName]=\"viewerService.userName\" \r\n [showExit]=\"sideMenuConfig.showExit\"\r\n [timeSpentLabel]=\"viewerService.timeSpent\" tabindex=\"0\" (playNextContent)=\"playContent($event)\" \r\n (exitContent)=\"exitContent($event)\" (replayContent)=\"replayContent($event)\"\r\n *ngIf=\"viewState === 'end'\"></sb-player-end-page>\r\n <sb-player-contenterror *ngIf=\"showContentError\"></sb-player-contenterror>\r\n</div>\r\n\r\n<div class=\"sunbird-video-player-container\" *ngIf=\"showQumlPlayer\" #qumlPlayer>\r\n <quml-main-player [playerConfig]=\"QumlPlayerConfig\" (playerEvent)=\"qumlPlayerEvents($event)\"></quml-main-player>\r\n</div>",
styles: [".sunbird-video-player-container{width:100%;height:100%;overflow:hidden;position:relative}.videoPlayerHide{display:none}.videoPlayerShow{display:block}pdf-menu{position:absolute;top:0;left:0;z-index:99}.BtmNotVisible,.notVisible{transition:1s ease-in-out;position:absolute;width:100%}.notVisible{top:-10rem}.notVisible.isVisible{top:0}.BtmNotVisible{bottom:-10rem}.BtmNotVisible.isVisible{bottom:0}::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon input[type=checkbox]:checked~#overlay-button span{background:0 0!important}::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon input[type=checkbox]:checked~#overlay-button span:after,::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon input[type=checkbox]:checked~#overlay-button span:before,::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon input[type=checkbox]:checked~#overlay-button:hover span:after,::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon input[type=checkbox]:checked~#overlay-button:hover span:before{background-color:rgba(255,255,255,.7)!important}::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon label{background:rgba(51,51,51,.5)}::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon label span,::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon label span:after,::ng-deep .sunbird-video-player-container .sb-player-side-menu-icon label span:before{background-color:rgba(255,255,255,.7)!important}::ng-deep .sunbird-pdf-player{overflow:hidden}::ng-deep .pdfViewer .page{background:0 0!important;-o-border-image:none!important;border-image:none!important;border:0!important}::ng-deep #toolbarContainer{background:0 0!important;height:auto!important}::ng-deep #viewerContainer{position:relative!important;height:calc(100% - 3rem)}::ng-deep .body,::ng-deep .html,::ng-deep .pdf-viewer button,::ng-deep .pdf-viewer input,::ng-deep .pdf-viewer select{font-size:inherit!important}::ng-deep .findbar,::ng-deep .secondaryToolbar,::ng-deep html[dir=ltr] #toolbarContainer,::ng-deep html[dir=rtl] #toolbarContainer{box-shadow:none!important}::ng-deep .zoom{min-height:inherit!important}::ng-deep html[dir=rtl] .sb-pdf-reading-status{left:auto;right:1rem}.sb-pdf-reading-status{color:var(--gray-800);font-size:.75rem;position:absolute;left:1rem;bottom:1rem;display:flex;align-items:center;background:var(--white);border-radius:.5rem;padding:.25em .5rem;z-index:5;line-height:normal}.sb-pdf-reading-status span{background:var(--gray-800);width:.25rem;height:.25rem;display:block;margin:0 .5rem;border-radius:50%}.sbt-pdf-footer{background:var(--white);position:absolute;bottom:0;width:100%;height:3rem;display:flex;align-items:center;justify-content:flex-end;padding:.75rem .5rem}@media all and (orientation:landscape){::ng-deep .visible-only-potrait{display:none}}@media all and (orientation:portrait){::ng-deep #viewerContainer{height:calc(100% - 6rem)!important}::ng-deep .visible-only-landscape{display:none}::ng-deep .visible-only-potrait{display:block}::ng-deep .file-download__popup{height:15.125rem}::ng-deep .pdf-endpage{display:block!important;position:relative}::ng-deep .pdf-endpage__left-panel{margin-top:6rem}::ng-deep .pdf-endpage__right-panel .title-section{position:absolute;top:0;left:0;right:0}}@media all and (max-width:640px){.visible-only-landscape{display:none}.visible-only-potrait{display:block}}@media all and (min-width:640px){.visible-only-landscape{display:block}.visible-only-potrait{display:none}}"]
}] }
];
/** @nocollapse */
SunbirdVideoPlayerComponent.ctorParameters = () => [
{ type: SunbirdVideoPlayerService },
{ type: ViewerService },
{ type: ChangeDetectorRef },
{ type: Renderer2 },
{ type: ErrorService }
];
SunbirdVideoPlayerComponent.propDecorators = {
playerConfig: [{ type: Input }],
action: [{ type: Input }],
playerEvent: [{ type: Output }],
telemetryEvent: [{ type: Output }],
videoPlayerRef: [{ type: ViewChild, args: ['videoPlayer', { static: true },] }],
onTelemetryEvent: [{ type: HostListener, args: ['document:TelemetryEvent', ['$event'],] }],
ngOnDestroy: [{ type: HostListener, args: ['window:beforeunload',] }]
};
if (false) {
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.playerConfig;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.action;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.playerEvent;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.telemetryEvent;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.videoPlayerRef;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.viewState;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.traceId;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.nextContent;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.showContentError;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.showControls;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.sideMenuConfig;
/**
* @type {?}
* @private
*/
SunbirdVideoPlayerComponent.prototype.unlistenTouchStart;
/**
* @type {?}
* @private
*/
SunbirdVideoPlayerComponent.prototype.unlistenMouseMove;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.isPaused;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.showQumlPlayer;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.QumlPlayerConfig;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.videoInstance;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.currentInterceptionTime;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.currentInterceptionUIId;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.isFullScreen;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.playerAction;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.raiseInternetDisconnectionError;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.videoPlayerService;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.viewerService;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.cdr;
/**
* @type {?}
* @private
*/
SunbirdVideoPlayerComponent.prototype.renderer2;
/** @type {?} */
SunbirdVideoPlayerComponent.prototype.errorService;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/components/video-player/video-player.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class VideoPlayerComponent {
/**
* @param {?} viewerService
* @param {?} renderer2
* @param {?} questionCursor
* @param {?} http
*/
constructor(viewerService, renderer2, questionCursor, http) {
this.viewerService = viewerService;
this.renderer2 = renderer2;
this.questionCursor = questionCursor;
this.http = http;
this.questionSetData = new EventEmitter();
this.playerInstance = new EventEmitter();
this.transcripts = [];
this.showBackwardButton = false;
this.showForwardButton = false;
this.showPlayButton = true;
this.showPauseButton = false;
this.showControls = true;
this.currentPlayerState = 'none';
this.totalSeekedLength = 0;
this.previousTime = 0;
this.currentTime = 0;
this.seekStart = null;
this.time = 10;
this.totalSpentTime = 0;
this.isAutoplayPrevented = false;
this.setMetaDataConfig = false;
this.totalDuration = 0;
}
/**
* @return {?}
*/
ngOnInit() {
this.transcripts = this.viewerService.handleTranscriptsData(get(this.config, 'transcripts') || []);
}
/**
* @return {?}
*/
ngAfterViewInit() {
this.viewerService.getPlayerOptions().then((/**
* @param {?} options
* @return {?}
*/
(options) => __awaiter(this, void 0, void 0, function* () {
this.player = yield videojs(this.target.nativeElement, {
fluid: true,
responsive: true,
sources: options,
autoplay: false,
muted: get(this.config, 'muted'),
playbackRates: [0.5, 1, 1.5, 2],
controlBar: {
children: ['playToggle', 'volumePanel', 'durationDisplay',
'progressControl', 'remainingTimeDisplay', 'CaptionsButton',
'playbackRateMenuButton', 'fullscreenToggle']
},
plugins: {
httpSourceSelector: {
default: 'low'
}
},
html5: {
hls: {
overrideNative: true
},
nativeAudioTracks: false,
nativeVideoTracks: false,
}
});
this.player.videojshttpsourceselector = videojshttpsourceselector;
this.player.videojshttpsourceselector();
/** @type {?} */
const markers = this.viewerService.getMarkers();
if (markers && markers.length > 0) {
/** @type {?} */
const identifiers = markers.map((/**
* @param {?} item
* @return {?}
*/
item => {
return item.identifier;
}));
if (this.viewerService.questionCursor) {
this.viewerService.questionCursor.getAllQuestionSet(identifiers).subscribe((/**
* @param {?} response
* @return {?}
*/
(response) => {
if (!isEmpty(response)) {
this.viewerService.maxScore = response.reduce((/**
* @param {?} a
* @param {?} b
* @return {?}
*/
(a, b) => a + b), 0);
}
}));
}
}
if (markers) {
this.player.markers({
markers,
markerStyle: {
h