Skip to content

Commit

Permalink
fix(FEC-13717): [Download Plugin]: Add Events (used by kava analytics) (
Browse files Browse the repository at this point in the history
#43)

### Description of the Changes

Adjusting Events (used by kava analytics)

#### Solves FEC-13717

#### Related PR: 
kaltura/playkit-js-kava#156

---------

Co-authored-by: JonathanTGold <jonathan.gold@[email protected]>
  • Loading branch information
JonathanTGold and JonathanTGold authored Mar 11, 2024
1 parent 8777c95 commit dbaa0f9
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/components/attachments-list/attachments-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {DownloadItem} from '../download-item';
import * as styles from './attachments-list.scss';
import {ComponentChildren} from 'preact';
import {getIconByFileExt} from '@playkit-js/common/dist/icon/icon-utils';
import { assetType } from '../../consts/asset-type';

const {withText} = KalturaPlayer.ui.preacti18n;

Expand All @@ -21,7 +22,7 @@ export const AttachmentsList = withText({
};

const _renderDownloadItem = (key: string, fileName: string, downloadUrl: string, icon: ComponentChildren) => {
return <DownloadItem downloadPluginManager={downloadPluginManager} key={key} fileName={fileName} downloadUrl={downloadUrl} iconFileType={icon} />;
return <DownloadItem downloadPluginManager={downloadPluginManager} key={key} fileName={fileName} downloadUrl={downloadUrl} assetType={assetType.Attachments} iconFileType={icon} />;
};

const _renderAttachments = (attachments: Array<KalturaAttachmentAsset>) => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/captions-list/captions-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {DownloadItem} from '../download-item';
import * as styles from './captions-list.scss';
import {ExpandableContainer} from '../expandable-container';
import {Icon as CommonIcon} from '@playkit-js/common/dist/icon';
import { assetType } from '../../consts/asset-type';

const {withText} = KalturaPlayer.ui.preacti18n;

Expand Down Expand Up @@ -44,6 +45,7 @@ export const CaptionsList = withText({
fileName={fileName}
description={languageLabel}
downloadUrl={downloadUrl}
assetType={assetType.Captions}
iconFileType={<CommonIcon name={'closedCaptions'} />}
/>
);
Expand Down
6 changes: 5 additions & 1 deletion src/components/download-item/download-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface DownloadItemProps {
downloadFailedLabel?: string;
downloadButtonLabel?: string;
fileName: string;
assetType: string;
description?: string;
downloadUrl: string;
iconFileType: ComponentChildren;
Expand All @@ -42,6 +43,7 @@ export const DownloadItem = withText({
downloadPluginManager,
downloadButtonLabel,
fileName,
assetType,
description,
downloadUrl,
iconFileType,
Expand All @@ -62,7 +64,9 @@ export const DownloadItem = withText({
if (downloadUrl) {
downloadPluginManager.downloadFile(downloadUrl, fileName);
downloadPluginManager.notifyDownloadStarted(downloadLabel!, downloadStartedLabel!);
player.dispatchEvent(new KalturaPlayer.core.FakeEvent(DownloadEvent.DOWNLOAD_ITEM_CLICKED));

const fileType = fileName.match(/\.(.*?)$/)![1];
player.dispatchEvent(new KalturaPlayer.core.FakeEvent(DownloadEvent.DOWNLOAD_ITEM_CLICKED, {fileType, description, assetType}));
} else {
downloadPluginManager.notifyDownloadFailed(downloadLabel!, downloadFailedLabel!);
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/download-overlay/download-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as styles from './download-overlay.scss';
import {SourcesList} from '../sources-list';
import {CaptionsList} from '../captions-list';
import {AttachmentsList} from '../attachments-list';
import {DownloadInternalEvent} from '../../event';
import {DownloadEvent} from '../../event';

interface DownloadOverlayProps {
downloadPluginManager: DownloadPluginManager;
Expand Down Expand Up @@ -68,11 +68,11 @@ const DownloadOverlay = withText({
const closeButtonRef = createRef<HTMLButtonElement>();
const downloadConfig = downloadPluginManager.downloadPlugin.config;
useEffect(() => {
eventManager?.listen(downloadPluginManager, DownloadInternalEvent.SHOW_OVERLAY, () => {
eventManager?.listen(downloadPluginManager, DownloadEvent.SHOW_OVERLAY, () => {
setIsVisible(true);
});

eventManager?.listen(downloadPluginManager, DownloadInternalEvent.HIDE_OVERLAY, () => {
eventManager?.listen(downloadPluginManager, DownloadEvent.HIDE_OVERLAY, () => {
setIsVisible(false);
});
}, []);
Expand Down
2 changes: 2 additions & 0 deletions src/components/sources-list/sources-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {DownloadConfig} from '../../types';
import {ExpandableContainer} from '../expandable-container';
import {ComponentChildren} from 'preact';
import {Icon as CommonIcon} from '@playkit-js/common/dist/icon';
import { assetType } from '../../consts/asset-type';
const {Icon, IconType} = KalturaPlayer.ui.components;

const {withText} = KalturaPlayer.ui.preacti18n;
Expand Down Expand Up @@ -104,6 +105,7 @@ export const SourcesList = withText({
description={description}
downloadUrl={downloadUrl}
iconFileType={icon}
assetType={assetType.Media}
isDefault={isDefault}
/>
);
Expand Down
5 changes: 5 additions & 0 deletions src/consts/asset-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum assetType {
Media = 'Media',
Captions = 'Captions',
Attachments = 'Attachments'
}
6 changes: 3 additions & 3 deletions src/download-plugin-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Download} from './download';
import {DOWNLOAD, ERROR} from './icons';
import {DownloadService} from './services';
import {DownloadMetadata} from './types';
import {DownloadInternalEvent} from './event';
import {DownloadEvent} from './event';

class DownloadPluginManager extends KalturaPlayer.core.FakeEventTarget {
private _showOverlay = false;
Expand Down Expand Up @@ -67,13 +67,13 @@ class DownloadPluginManager extends KalturaPlayer.core.FakeEventTarget {
this.downloadPlugin.player.pause();
this.playOnClose = true;
}
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(DownloadInternalEvent.SHOW_OVERLAY, {byKeyboard: this.downloadPlugin.triggeredByKeyboard}));
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(DownloadEvent.SHOW_OVERLAY, {byKeyboard: this.downloadPlugin.triggeredByKeyboard}));
} else {
if (this.playOnClose) {
this.downloadPlugin.player.play();
this.playOnClose = false;
}
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(DownloadInternalEvent.HIDE_OVERLAY));
this.dispatchEvent(new KalturaPlayer.core.FakeEvent(DownloadEvent.HIDE_OVERLAY));
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {DownloadPluginManager} from './download-plugin-manager';

import {OnClickEvent} from '@playkit-js/common';
import {ui} from '@playkit-js/kaltura-player-js';
import { DownloadEvent } from "./event";

const {ReservedPresetNames} = ui;
const {Text} = ui.preacti18n;
Expand Down Expand Up @@ -36,6 +37,7 @@ class Download extends KalturaPlayer.core.BasePlugin {
constructor(name: string, player: KalturaPlayerTypes.Player, config: DownloadConfig) {
super(name, player, config);
this.downloadPluginManager = new DownloadPluginManager(this);
this._addBindings();
}

static isValid(): boolean {
Expand Down Expand Up @@ -138,6 +140,11 @@ class Download extends KalturaPlayer.core.BasePlugin {
}
}

_addBindings() {
this.eventManager.listen(this.downloadPluginManager, DownloadEvent.SHOW_OVERLAY, (e) => this.dispatchEvent(DownloadEvent.SHOW_OVERLAY, e.payload));
this.eventManager?.listen(this.downloadPluginManager, DownloadEvent.HIDE_OVERLAY, (e) => this.dispatchEvent(DownloadEvent.HIDE_OVERLAY, e.payload));
}

reset() {
this.upperBarManager?.remove(this.iconId);
this.iconId = -1;
Expand Down
2 changes: 2 additions & 0 deletions src/event/download-event.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
export namespace DownloadEvent {
const DOWNLOAD_ITEM_CLICKED: string;
const SHOW_OVERLAY: string;
const HIDE_OVERLAY: string;
}
4 changes: 3 additions & 1 deletion src/event/download-event.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const DownloadEvent = {
DOWNLOAD_ITEM_CLICKED: 'download_item_clicked'
DOWNLOAD_ITEM_CLICKED: 'download_item_clicked',
SHOW_OVERLAY: 'download_show_overlay',
HIDE_OVERLAY: 'download_hide_overlay'
};

export {DownloadEvent};
4 changes: 0 additions & 4 deletions src/event/download-internal-event.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/event/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {DownloadInternalEvent} from './download-internal-event';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {DownloadEvent} from './download-event';
export {DownloadInternalEvent, DownloadEvent};
export {DownloadEvent};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export {Download as Plugin};
export {VERSION, NAME};

export const pluginName = 'download';
export {DownloadEvent} from './event';

KalturaPlayer.core.registerPlugin(pluginName, Download);

0 comments on commit dbaa0f9

Please sign in to comment.