feat: update version to 1.1.0 and enhance VAST plugin with new event handling and configuration options

This commit is contained in:
Harvey Zhao committed 2026-01-04 23:31:30 +08:00
1 parent 4a980971f7
commit 486231f04b
3 files changed
+31 -12

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "artplayer-plugin-vast",
"version": "1.0.2",
"version": "1.1.0",
"description": "VAST plugin for ArtPlayer",
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
"license": "MIT",
@@ -35,6 +35,6 @@
"legacy": "./dist/artplayer-plugin-vast.legacy.js",
"browserslist": "last 1 Chrome version",
"dependencies": {
"@glomex/vast-ima-player": "^1.21.0"
"@glomex/vast-ima-player": "^1.21.2"
}
}
+21 -5
View File
@@ -45,16 +45,21 @@ export default function artplayerPluginVast(callback) {
imaPlayer = new Player(ima, $video, $container, adsRenderingSettings, playerOptions)
imaPlayer.addEventListener('AdStarted', () => {
imaPlayer.addEventListener('AdContentPauseRequested', () => {
isAdPlaying = true
$container.style.display = 'block'
})
imaPlayer.addEventListener('AdComplete', () => {
imaPlayer.addEventListener('AdContentResumeRequested', () => {
isAdPlaying = false
$container.style.display = 'none'
})
imaPlayer.addEventListener('AdStarted', () => {
isAdPlaying = true
$container.style.display = 'block'
})
imaPlayer.addEventListener('AdError', (event) => {
console.error('VAST Ad Error:', event.detail)
isAdPlaying = false
@@ -73,23 +78,29 @@ export default function artplayerPluginVast(callback) {
imaPlayer = null
}
function playUrl(url) {
function playUrl(url, config = {}) {
if (isAdPlaying)
return
if (!imaPlayer)
initPlayer()
const request = new ima.AdsRequest()
request.adTagUrl = url
for (const key in config) {
request[key] = config[key]
}
imaPlayer.playAds(request)
}
function playRes(res) {
function playRes(res, config = {}) {
if (isAdPlaying)
return
if (!imaPlayer)
initPlayer()
const request = new ima.AdsRequest()
request.adsResponse = res
for (const key in config) {
request[key] = config[key]
}
imaPlayer.playAds(request)
}
@@ -98,8 +109,13 @@ export default function artplayerPluginVast(callback) {
art,
playUrl,
playRes,
init: initPlayer,
ima,
imaPlayer,
adsRenderingSettings,
playerOptions,
get imaPlayer() {
return imaPlayer
},
get container() {
return $container
},
@@ -1,4 +1,4 @@
import type { Player } from '@glomex/vast-ima-player'
import type { Player, PlayerOptions } from '@glomex/vast-ima-player'
import type Artplayer from 'artplayer'
declare global {
@@ -7,15 +7,18 @@ declare global {
}
}
type PlayUrlFn = (url: string) => void
type PlayResFn = (res: string) => void
type PlayUrlFn = (url: string, config?: any) => void
type PlayResFn = (res: string, config?: any) => void
interface VastPluginContext {
art: Artplayer
ima: any // Replace 'any' with a more specific type if available, or declare google.ima type above
imaPlayer: Player
ima: any
imaPlayer: Player | null
playUrl: PlayUrlFn
playRes: PlayResFn
init: () => Player
adsRenderingSettings: any
playerOptions: PlayerOptions
container: HTMLDivElement | null
}