Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-13728): Expose the download overlay API (to enable Audio Pla… #48

Merged
merged 9 commits into from May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions demo/index.html
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Kaltura Player Demo Page" />
<title>Download Plugin</title>
<link rel="stylesheet" type="text/css" href="./style.css" />
<script src="https://unpkg.com/@playkit-js/kaltura-player-js@canary/dist/kaltura-ovp-player.js"></script>
<script src="https://unpkg.com/@playkit-js/ui-managers@canary/dist/playkit-ui-managers.js" type="text/javascript"></script>
<script src="./playkit-downloads.js" type="text/javascript"></script>
</head>
<body>
<div id="player-placeholder"></div>
<script type="text/javascript">
const config = {
log: {
level: 'DEBUG'
},
targetId: 'player-placeholder',
provider: {
env: {
serviceUrl: 'https://cdnapisec.kaltura.com/api_v3',
cdnUrl: 'https://cfvod.kaltura.com',
statsServiceUrl: 'https://stats.kaltura.com',
liveStatsServiceUrl: 'https://livestats.kaltura.com',
analyticsServiceUrl: 'https://analytics.kaltura.com',
apiFeatures: {
entryRedirect: '1'
}
},
partnerId: 3076893
},
plugins: {
uiManagers: {},
download: {}
}
};

const player = KalturaPlayer.setup(config);
player.loadMedia({entryId: '1_rhur4p1n'});
</script>
</body>
</html>
9 changes: 9 additions & 0 deletions demo/style.css
@@ -0,0 +1,9 @@
body {
background-color: #212121;
}

#player-placeholder {
margin: 100px auto;
max-width: 640px;
aspect-ratio: 10 / 5.62;
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
"build": "webpack --mode production",
"dev": "webpack-dev-server --mode development",
"docs:generate": "documentation build src/** -f md -o docs/api.md",
"watch": "webpack --progress --colors --watch --mode development",
"watch": "webpack --progress --watch --mode development",
"pushTaggedRelease": "git push --follow-tags --no-verify origin master",
"release": "standard-version",
"eslint": "eslint . --color",
Expand Down
5 changes: 5 additions & 0 deletions src/components/download-overlay/download-overlay.scss
Expand Up @@ -57,5 +57,10 @@
position: absolute;
top: 36px;
right: 36px;

&.small {
top: 10px;
right:10px;
}
}
}
26 changes: 23 additions & 3 deletions src/components/download-overlay/download-overlay.tsx
Expand Up @@ -3,6 +3,12 @@ import {DownloadPluginManager} from '../../download-plugin-manager';
import {createRef} from 'preact';
import {useState, useEffect} from 'preact/hooks';
import {DownloadMetadata} from '../../types';
import {ui} from '@playkit-js/kaltura-player-js';

// @ts-expect-error - TS2339: Property 'bindActions' does not exist on type
const {bindActions} = ui.utils;
// @ts-expect-error - TS2339: Property 'bindActions' does not exist on type
const overlayActions = ui.reducers.overlay.actions;

const {withEventManager} = KalturaPlayer.ui.Event;
const {PLAYER_SIZE} = KalturaPlayer.ui.components;
Expand All @@ -24,6 +30,7 @@ interface DownloadOverlayProps {
closeLabel?: string;
setFocus: () => void;
downloadMetadata: DownloadMetadata;
updateOverlay: (isOpen: boolean) => void;
}

const mapStateToProps = (state: any) => {
Expand Down Expand Up @@ -61,9 +68,21 @@ const DownloadOverlay = withText({
downloadsLabel: 'download.downloads',
closeLabel: 'overlay.close'
})(
connect(mapStateToProps)(
connect(
mapStateToProps,
bindActions(overlayActions)
)(
withEventManager(
({downloadPluginManager, eventManager, sizeClass, downloadsLabel, closeLabel, setFocus, downloadMetadata}: DownloadOverlayProps) => {
({
downloadPluginManager,
eventManager,
sizeClass,
downloadsLabel,
closeLabel,
setFocus,
downloadMetadata,
updateOverlay
}: DownloadOverlayProps) => {
const [isVisible, setIsVisible] = useState(false);
const closeButtonRef = createRef<HTMLButtonElement>();
const downloadConfig = downloadPluginManager.downloadPlugin.config;
Expand Down Expand Up @@ -117,9 +136,10 @@ const DownloadOverlay = withText({
{shouldRenderAttachments && renderAttachments()}
</div>
<div>
<div data-testid="download-overlay-close-button" className={styles.closeButtonContainer}>
<div data-testid="download-overlay-close-button" className={`${styles.closeButtonContainer} ${sizeClass}`}>
<A11yWrapper
onClick={(e: OnClickEvent, byKeyboard: boolean) => {
updateOverlay(false);
downloadPluginManager.showOverlay = false;
if (byKeyboard) {
setFocus();
Expand Down
45 changes: 27 additions & 18 deletions src/download.tsx
Expand Up @@ -12,8 +12,8 @@ import {DownloadEvent} from './event';

const {ReservedPresetNames} = ui;
const {Text} = ui.preacti18n;

const PRESETS = [ReservedPresetNames.Playback, ReservedPresetNames.Img];
// @ts-expect-error - TS2339: Property 'MiniAudioUI' does not exist on type
const PRESETS = [ReservedPresetNames.Playback, ReservedPresetNames.Img, ReservedPresetNames.MiniAudioUI];

class Download extends KalturaPlayer.core.BasePlugin {
static defaultConfig: DownloadConfig = {
Expand All @@ -33,11 +33,13 @@ class Download extends KalturaPlayer.core.BasePlugin {
private downloadPluginManager: DownloadPluginManager;
private _pluginButtonRef: HTMLButtonElement | null = null;
public triggeredByKeyboard = false;
private store: any;

constructor(name: string, player: KalturaPlayerTypes.Player, config: DownloadConfig) {
super(name, player, config);
this.downloadPluginManager = new DownloadPluginManager(this);
this._addBindings();
this.store = ui.redux.useStore();
}

static isValid(): boolean {
Expand All @@ -63,6 +65,10 @@ class Download extends KalturaPlayer.core.BasePlugin {
});
}

showOverlay(): void {
this.downloadPluginManager.showOverlay = true;
}

private _setPluginButtonRef = (ref: HTMLButtonElement) => {
this._pluginButtonRef = ref;
};
Expand All @@ -82,24 +88,27 @@ class Download extends KalturaPlayer.core.BasePlugin {
if (this.iconId > 0) {
return;
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.iconId = this.upperBarManager.add({
// @ts-expect-error - TS2339: Property 'MiniAudioUI' does not exist on type
if (this.store.getState().shell['activePresetName'] !== ReservedPresetNames.MiniAudioUI) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
ariaLabel: (<Text id="download.download">Download</Text>) as never,
displayName: 'Download',
order: 40,
svgIcon: {
path: DOWNLOAD
},
onClick: this._handleClick as any,
component: () => {
return <DownloadOverlayButton setRef={this._setPluginButtonRef} />;
},
presets: PRESETS
}) as number;
this.iconId = this.upperBarManager.add({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
ariaLabel: (<Text id="download.download">Download</Text>) as never,
displayName: 'Download',
order: 40,
svgIcon: {
path: DOWNLOAD
},
onClick: this._handleClick as any,
component: () => {
return <DownloadOverlayButton setRef={this._setPluginButtonRef} />;
},
// @ts-expect-error - TS2339: Property 'MiniAudioUI' does not exist on type
presets: PRESETS.filter(presetName => presetName !== ReservedPresetNames.MiniAudioUI)
}) as number;
}

this.componentDisposers.push(
this.player.ui.addComponent({
Expand Down
7 changes: 6 additions & 1 deletion webpack.config.js
Expand Up @@ -55,7 +55,12 @@ module.exports = {
]
},
devServer: {
static: `${__dirname}/src`
static: {
directory: path.join(__dirname, 'demo')
},
client: {
progress: true
}
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
Expand Down