Skip to content

Commit

Permalink
Merge pull request #517 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue PS-2754 feat : Enable tracking consumption for V1 player - youtube, html, h5p
  • Loading branch information
itsvick authored Dec 12, 2024
2 parents 03e209e + 637cd2e commit f5a78bf
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 8 deletions.
4 changes: 4 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ const nextConfig = {
source: routes.API.GENERAL.CONTENT_PLUGINS,
destination: `${PORTAL_BASE_URL}${routes.API.GENERAL.CONTENT_PLUGINS}`, // Proxy to portal
},
{
source: '/sunbird-plugins/renderer/:path*',
destination: `${process.env.WORKSPACE_BASE_URL}/sunbird-plugins/renderer/:path*`,
},
];
},
webpack: (config, { isServer }) => {
Expand Down
97 changes: 91 additions & 6 deletions src/components/ContentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,19 @@ const ContentCard: React.FC<ContentCardProps> = ({
let status = '';
response.data?.some((item: any) =>
item.contents?.some((content: any) => {
if (content.contentId === identifier) {
status = content.status || '';
// status = parseInt(content.percentage, 10);
return true;
if (
content.contentId === identifier &&
(content.contentMime === ContentType.HTML ||
content.contentMime === ContentType.H5P) &&
content.status === contentStatus.IN_PROGRESS
) {
status = contentStatus.COMPLETED;
} else {
if (content.contentId === identifier) {
status = content.status || '';
// status = parseInt(content.percentage, 10);
return true;
}
}
})
);
Expand All @@ -102,6 +111,10 @@ const ContentCard: React.FC<ContentCardProps> = ({
setProgress(0);
setStatusMsg(t('CENTER_SESSION.NOTSTARTED'));
break;
case '':
setProgress(0);
setStatusMsg(t('CENTER_SESSION.NOTSTARTED'));
break;
default:
setProgress(0);
setStatusMsg('');
Expand Down Expand Up @@ -129,7 +142,79 @@ const ContentCard: React.FC<ContentCardProps> = ({
relevantKeys.forEach((key) => {
const telemetryEvent = localStorage.getItem(key);
if (telemetryEvent) {
detailsObject.push(JSON.parse(telemetryEvent));
const parsedTelemetryEvent = JSON.parse(telemetryEvent);
let progressFromSummary = null;
let progressFromExtra = null;
const mimeType = parsedTelemetryEvent?.mimeType;

// Check `summary` for progress
if (parsedTelemetryEvent?.edata?.summary?.length > 0) {
progressFromSummary =
parsedTelemetryEvent.edata.summary[0]?.progress;
}

// Check `extra` for progress
if (parsedTelemetryEvent?.edata?.extra?.length > 0) {
const progressEntry = parsedTelemetryEvent.edata.extra.find(
(entry: any) => entry.id === 'progress'
);
if (progressEntry) {
progressFromExtra = parseInt(progressEntry.value, 10);
}
}

// Skip event if `eid === 'END'` and progress is not 100 in either `summary` or `extra`
if (
parsedTelemetryEvent?.eid === 'END' &&
((progressFromSummary !== 100 && progressFromSummary !== null) ||
(progressFromExtra !== 100 && progressFromExtra !== null))
) {
return;
}

// Push parsed telemetry event
detailsObject.push(parsedTelemetryEvent);
}
});

// After processing all keys, check if an END event exists in detailsObject for html or h5p
const requiredMimeTypes = [ContentType.H5P, ContentType.HTML];
requiredMimeTypes.forEach((type) => {
const hasEndEvent = detailsObject.some(
(event) => event?.eid === 'END' && mimeType === type
);

if (!hasEndEvent) {
// Push the default END event for missing types
detailsObject.push({
eid: 'END',
edata: {
duration: 0,
mode: 'play',
pageid: 'sunbird-player-Endpage',
summary: [
{
progress: 100,
},
{
totallength: '',
},
{
visitedlength: '',
},
{
visitedcontentend: '',
},
{
totalseekedlength: '',
},
{
endpageseen: false,
},
],
type: 'content',
},
});
}
});
}
Expand All @@ -142,7 +227,6 @@ const ContentCard: React.FC<ContentCardProps> = ({
const ContentTypeReverseMap = Object.fromEntries(
Object.entries(ContentType).map(([key, value]) => [value, key])
);
console.log(ContentTypeReverseMap);

const reqBody: ContentCreate = {
userId: userId,
Expand All @@ -154,6 +238,7 @@ const ContentCard: React.FC<ContentCardProps> = ({
lastAccessOn: lastAccessOn,
detailsObject: detailsObject,
};
console.log('reqBody', reqBody);
if (detailsObject.length > 0) {
const response = await createContentTracking(reqBody);
if (response) {
Expand Down
6 changes: 5 additions & 1 deletion src/pages/course-planner/center/[cohortId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ const CoursePlannerDetail = () => {
}, [fetchCourseDetails]);

const handleBackEvent = () => {
window.history.back();
if (typeof window !== 'undefined' && window.localStorage) {
const classId = localStorage.getItem('classId');
router.push(`/course-planner?center=${classId}`);
}
// window.history.back();
logEvent({
action: 'back-button-clicked-attendance-overview',
category: 'Attendance Overview Page',
Expand Down
6 changes: 5 additions & 1 deletion src/pages/topic-detail-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ const TopicDetailView = () => {

const handleBackEvent = () => {
// window.history.back();
router.back();
if (typeof window !== 'undefined' && window.localStorage) {
const classId = localStorage.getItem('classId');
router.push(`course-planner/center/${classId}`);
}
// router.back();
logEvent({
action: 'back-button-clicked-attendance-overview',
category: 'Attendance Overview Page',
Expand Down

0 comments on commit f5a78bf

Please sign in to comment.