mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-22 21:31:20 -08:00
fix(react): [EX-01] verify installed consumers and clean up callback failures
This commit is contained in:
1 parent
3e39fc745f
commit
e0d785662d
25 files changed
+3539
-98
No files matched your search
@@ -1,16 +1,11 @@
|
||||
import type { Option } from 'artplayer'
|
||||
import type { HTMLAttributes } from 'react'
|
||||
import Artplayer from 'artplayer'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import Artplayer, { type Option } from 'artplayer'
|
||||
import { playerOptions } from './player-options'
|
||||
|
||||
// Test i18n
|
||||
import fr from 'artplayer/i18n/fr'
|
||||
import id from 'artplayer/i18n/id'
|
||||
|
||||
// Test plugins
|
||||
import artplayerPluginDanmuku from 'artplayer-plugin-danmuku'
|
||||
import artplayerPluginDocumentPip from 'artplayer-plugin-document-pip'
|
||||
|
||||
interface PlayerProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
option: Partial<Option>,
|
||||
export interface PlayerProps extends HTMLAttributes<HTMLDivElement> {
|
||||
option: Partial<Option>
|
||||
getInstance?: (art: Artplayer) => void
|
||||
}
|
||||
|
||||
@@ -18,24 +13,25 @@ export default function Player({ option, getInstance, ...rest }: PlayerProps) {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!containerRef.current) return
|
||||
if (!containerRef.current)
|
||||
return
|
||||
|
||||
const art = new Artplayer({
|
||||
...option,
|
||||
container: containerRef.current,
|
||||
url: option.url as string,
|
||||
i18n: { id, fr },
|
||||
lang: 'fr',
|
||||
plugins: [
|
||||
artplayerPluginDocumentPip({}),
|
||||
artplayerPluginDanmuku({
|
||||
danmuku: 'https://artplayer.org/assets/sample/danmuku.xml',
|
||||
}),
|
||||
],
|
||||
})
|
||||
const art = new Artplayer(playerOptions(option, containerRef.current))
|
||||
|
||||
if (typeof getInstance === 'function') {
|
||||
getInstance(art)
|
||||
try {
|
||||
if (typeof getInstance === 'function') {
|
||||
getInstance(art)
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
try {
|
||||
art.destroy(false)
|
||||
}
|
||||
finally {
|
||||
// Keep the consumer's error even if teardown also fails.
|
||||
// eslint-disable-next-line no-unsafe-finally
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
|
||||
Reference in new issue
Block a user