From 0c72c9d68fdaeedac26c64de41c42caf6f0e9836 Mon Sep 17 00:00:00 2001 From: Noor Mohammad Rahimi <64582713+code-lish@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:05:57 +0430 Subject: [PATCH] refactor(ad): refactor ad and add documentation (#148) --- examples/standalone/helper.ts | 6 ++-- packages/docs/src/pages/docs/plugins/ad.mdx | 22 ++++++++++++ packages/docs/src/pages/index.mdx | 2 +- packages/plugins/index.ts | 4 ++- packages/plugins/src/ad.ts | 40 +++++++++++++++++---- 5 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 packages/docs/src/pages/docs/plugins/ad.mdx diff --git a/examples/standalone/helper.ts b/examples/standalone/helper.ts index df1ed880..53c6314e 100644 --- a/examples/standalone/helper.ts +++ b/examples/standalone/helper.ts @@ -1,7 +1,7 @@ import { Player } from '@oplayer/core' import { MenuBar } from '@oplayer/ui/src/types' import { FORMAT_MENU } from './constants' -import { vttThumbnails, ad } from '@oplayer/plugins' +import { vttThumbnails, Ad } from '@oplayer/plugins' import hls from '@oplayer/hls' export const register = (player: Player) => { @@ -35,14 +35,14 @@ export const register = (player: Player) => { ) player.applyPlugin( - ad({ + Ad({ autoplay: false, image: 'http://5b0988e595225.cdn.sohucs.com/images/20190420/da316f8038b242c4b34f6db18b0418d4.gif', // video: VIDEO_LIST[1], duration: 10, skipDuration: 5, target: 'https://oplayer.vercel.app', - plugins: [hls({ qualityControl: false })] + plugins: [hls({ qualityControl: false })], }) ) } diff --git a/packages/docs/src/pages/docs/plugins/ad.mdx b/packages/docs/src/pages/docs/plugins/ad.mdx new file mode 100644 index 00000000..ceb54c5e --- /dev/null +++ b/packages/docs/src/pages/docs/plugins/ad.mdx @@ -0,0 +1,22 @@ +## Ad + +```jsx +import Player from '@oplayer/react' +import ui from '@oplayer/ui' +import { vttThumbnails } from '@oplayer/plugins' + +OPlayer.make('#player').use([ui(), + Ad({ + autoplay: false, + image: 'http://5b0988e595225.cdn.sohucs.com/images/20190420/da316f8038b242c4b34f6db18b0418d4.gif', + video: videoSource, + duration: 200, + skipDuration: 10, + target: 'https://oplayer.vercel.app', + plugins: [hls({ qualityControl: false })], + position:{ + bottom: "10%", + left: "0.3em", + }, + }) +``` diff --git a/packages/docs/src/pages/index.mdx b/packages/docs/src/pages/index.mdx index e4f3ec47..a800c919 100644 --- a/packages/docs/src/pages/index.mdx +++ b/packages/docs/src/pages/index.mdx @@ -126,7 +126,7 @@ import { Playlist, Chromecast, AirPlay } from '@oplayer/plugins' ] }), new Chromecast(), - new AirPlay() + new AirPlay(), ]} /> diff --git a/packages/plugins/index.ts b/packages/plugins/index.ts index 259a6928..99901af2 100644 --- a/packages/plugins/index.ts +++ b/packages/plugins/index.ts @@ -2,5 +2,7 @@ import Chromecast from './src/chromecast' import AirPlay from './src/airplay' import vttThumbnails from './src/vttThumbnails' import Playlist from './src/playlist' +import Ad from "./src/ad" -export { Chromecast, AirPlay, vttThumbnails, Playlist } + +export { Chromecast, AirPlay, vttThumbnails, Playlist, Ad } diff --git a/packages/plugins/src/ad.ts b/packages/plugins/src/ad.ts index afb5ccd3..2d6f1576 100644 --- a/packages/plugins/src/ad.ts +++ b/packages/plugins/src/ad.ts @@ -4,7 +4,11 @@ const topRight = $.css({ position: 'absolute', right: '0.5em', top: '0.5em', - 'z-index': 1 + 'z-index': 1, + display: "flex", + gap: "5px", + "align-items": "center", + "justify-content": "center" }) const area = $.css( @@ -28,7 +32,13 @@ const mute = $.css({ type Options = { video?: string - image?: string + image?: string, + position?:{ + left?: string; + bottom?: string; + top?: string; + right?: string; + }, autoplay?: boolean plugins?: PlayerPlugin[] skipDuration?: number @@ -45,10 +55,12 @@ export default ({ plugins, target, autoplay, - onSkip + onSkip, + position }: Options): PlayerPlugin => ({ name: 'oplayer-plugin-ad', version: __VERSION__, + key:"Ad", apply: (player) => { if (autoplay) { bootstrap() @@ -83,7 +95,18 @@ export default ({ cursor: 'pointer' })}`, {}, - `
+ `
${ skipDuration ? `
${player.locales.get( @@ -98,8 +121,8 @@ export default ({ ${ video ? ` -
- +
+
` @@ -125,7 +148,10 @@ export default ({ .use(plugins || ([] as any)) .create() - $volume!.addEventListener('click', () => { + $volume!.addEventListener('click', (e) => { + e.preventDefault(); + e.stopPropagation(); // Prevent the click event from bubbling to the $container + instance.isMuted ? instance.unmute() : instance.mute() $volume!.classList.toggle(mute) })