Skip to content

Commit

Permalink
Revert "Revert "feat(FEV-1168): Add "quiz" type of cue-points to Kalt…
Browse files Browse the repository at this point in the history
…ura-cue-points plugin (#18)""

This reverts commit 10bf5dd.
  • Loading branch information
RoyBregman committed Jan 24, 2022
1 parent b2f7cce commit a99527d
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 5 deletions.
57 changes: 57 additions & 0 deletions src/providers/vod/quiz-question-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import ILoader = KalturaPlayerTypes.ILoader;
import {KalturaCuePointListResponse, KalturaQuizQuestionCuePoint, KalturaCuePoint} from './response-types';

const {RequestBuilder} = KalturaPlayer.providers;
interface KalturaQuizQuestionCuePointsResponse {
quizQuestionCuePoints: Array<KalturaQuizQuestionCuePoint>;
}
export class QuizQuestionLoader implements ILoader {
_entryId: string = '';
_requests: any[] = [];
_response: KalturaQuizQuestionCuePointsResponse = {quizQuestionCuePoints: []};

static get id(): string {
return 'quiz-question';
}

constructor(params: {entryId: string}) {
this._entryId = params.entryId;
const headers: Map<string, string> = new Map();
const request = new RequestBuilder(headers);

request.service = 'cuepoint_cuepoint';
request.action = 'list';
request.params = {
filter: {
objectType: 'KalturaQuestionCuePointFilter',
entryIdEqual: this._entryId,
cuePointTypeEqual: KalturaCuePoint.KalturaCuePointType.QUIZ_QUESTION,
orderBy: '+startTime'
}
};
this.requests.push(request);
}

set requests(requests: any[]) {
this._requests = requests;
}

get requests(): any[] {
return this._requests;
}

set response(response: any) {
const cuePointList = new KalturaCuePointListResponse<KalturaQuizQuestionCuePoint>(response[0]?.data, KalturaQuizQuestionCuePoint);
if (cuePointList.totalCount) {
this._response.quizQuestionCuePoints = cuePointList.cuePoints;
}
}

get response(): any {
return this._response;
}

isValid(): boolean {
return !!this._entryId;
}
}
2 changes: 2 additions & 0 deletions src/providers/vod/response-types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './kaltura-cue-point';
export * from './kaltura-code-cue-point';
export * from './kaltura-thumb-cue-point';
export * from './kaltura-cue-point-list-response';
export * from './kaltura-quiz-question-cue-point';
1 change: 0 additions & 1 deletion src/providers/vod/response-types/kaltura-cue-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export class KalturaCuePoint {
ANNOTATION: 'annotation.Annotation',
CODE: 'codeCuePoint.Code',
EVENT: 'eventCuePoint.Event',
QUIZ_ANSWER: 'quiz.QUIZ_ANSWER',
QUIZ_QUESTION: 'quiz.QUIZ_QUESTION',
THUMB: 'thumbCuePoint.Thumb'
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {KalturaCuePoint} from './kaltura-cue-point';

export enum KalturaQuestionType {
fillInBlank = 5,
goTo = 7,
hotSpot = 6,
multipleAnswerQuestion = 4,
multipleChoiceAnswer = 1,
openQuestion = 8,
reflectionPoint = 3,
trueFalse = 2
}

export interface OptionalAnswer {
isCorrect: boolean;
key: string;
objectType: string;
text?: string;
weight: number;
}

export class KalturaQuizQuestionCuePoint extends KalturaCuePoint {
excludeFromScore: boolean;
objectType: string;
optionalAnswers: Array<OptionalAnswer>;
question: string;
questionType: KalturaQuestionType;
userId: string;

constructor(codeCuePoint: any) {
super(codeCuePoint);
this.excludeFromScore = codeCuePoint.excludeFromScore;
this.objectType = codeCuePoint.objectType;
this.optionalAnswers = codeCuePoint.optionalAnswers;
this.question = codeCuePoint.question;
this.questionType = codeCuePoint.questionType;
this.userId = codeCuePoint.userId;
}
}
40 changes: 36 additions & 4 deletions src/providers/vod/vod-provider.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Provider, ProviderRequest} from '../provider';
import {ThumbLoader} from './thumb-loader';
import {KalturaThumbCuePoint} from './response-types';
import {KalturaQuizQuestionCuePoint, KalturaThumbCuePoint, KalturaCodeCuePoint} from './response-types';
import {KalturaCuePointType, KalturaThumbCuePointSubType, CuepointTypeMap} from '../../types';
import Player = KalturaPlayerTypes.Player;
import Logger = KalturaPlayerTypes.Logger;
import EventManager = KalturaPlayerTypes.EventManager;
import {makeAssetUrl} from '../utils';
import {ViewChangeLoader} from './view-change-loader';
import {KalturaCodeCuePoint} from './response-types/kaltura-code-cue-point';
import {QuizQuestionLoader} from './quiz-question-loader';

export class VodProvider extends Provider {
constructor(player: Player, eventManager: EventManager, logger: Logger, types: CuepointTypeMap) {
Expand Down Expand Up @@ -35,16 +35,27 @@ export class VodProvider extends Provider {
requests.push({loader: ViewChangeLoader, params: {entryId: this._player.sources.id}});
}

if (this._types.has(KalturaCuePointType.QUIZ)) {
requests.push({loader: QuizQuestionLoader, params: {entryId: this._player.sources.id}});
}

if (requests.length) {
this._player.provider
.doRequest(requests)
.then((data: Map<string, any>) => {
if (data && data.has(ThumbLoader.id)) {
if (!data) {
this._logger.warn("Provider cue points doRequest doesn't have data");
return;
}
if (data.has(ThumbLoader.id)) {
this._handleThumbResponse(data);
}
if (data && data.has(ViewChangeLoader.id)) {
if (data.has(ViewChangeLoader.id)) {
this._handleViewChangeResponse(data);
}
if (data.has(QuizQuestionLoader.id)) {
this._handleQuizQustionResponse(data);
}
})
.catch((e: any) => {
this._logger.warn('Provider cue points doRequest was rejected');
Expand Down Expand Up @@ -133,4 +144,25 @@ export class VodProvider extends Provider {
this._addCuePointToPlayer(cuePoints);
}
}

private _handleQuizQustionResponse(data: Map<string, any>) {
const createCuePointList = (quizQuestionCuePoints: Array<KalturaQuizQuestionCuePoint>) => {
return quizQuestionCuePoints.map((quizQuestionCuePoint: KalturaQuizQuestionCuePoint) => {
return {
...quizQuestionCuePoint,
startTime: quizQuestionCuePoint.startTime / 1000,
endTime: Number.MAX_SAFE_INTEGER
};
});
};
const quizQuestionCuePointsLoader: QuizQuestionLoader = data.get(QuizQuestionLoader.id);
const quizQuestionCuePoints: Array<KalturaQuizQuestionCuePoint> = quizQuestionCuePointsLoader?.response.quizQuestionCuePoints || [];
this._logger.debug(`_fetchVodData quiz question response successful with ${quizQuestionCuePoints.length} cue points`);
if (quizQuestionCuePoints.length) {
let cuePoints = createCuePointList(quizQuestionCuePoints);
cuePoints = this._sortCuePoints(cuePoints);
cuePoints = this._fixCuePointsEndTime(cuePoints);
this._addCuePointToPlayer(cuePoints);
}
}
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum KalturaThumbCuePointSubType {
}
export enum KalturaCuePointType {
// AOA = 'aoa',
QUIZ = 'quiz',
SLIDE = 'slide',
VIEW_CHANGE = 'viewchange'
// HOTSPOT = 'hotspot',
Expand Down

0 comments on commit a99527d

Please sign in to comment.