pleroma-fe/src/components/flash/flash.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-04-12 00:00:23 +03:00
import { library } from '@fortawesome/fontawesome-svg-core'
2021-04-13 00:08:17 +03:00
import {
2026-01-06 16:22:52 +02:00
faExclamationTriangle,
2026-01-06 16:23:17 +02:00
faStop,
2021-04-13 00:08:17 +03:00
} from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:23:17 +02:00
import RuffleService from '../../services/ruffle_service/ruffle_service.js'
2021-04-12 00:00:23 +03:00
2026-01-06 16:22:52 +02:00
library.add(faStop, faExclamationTriangle)
const Flash = {
2022-07-31 12:35:48 +03:00
props: ['src'],
2026-01-06 16:22:52 +02:00
data() {
2021-04-12 00:00:23 +03:00
return {
player: false, // can be true, "hidden", false. hidden = element exists
loaded: false,
2026-01-06 16:22:52 +02:00
ruffleInstance: null,
2021-04-12 00:00:23 +03:00
}
},
methods: {
2026-01-06 16:22:52 +02:00
openPlayer() {
2021-04-13 00:08:17 +03:00
if (this.player) return // prevent double-loading, or re-loading on failure
2021-04-12 00:00:23 +03:00
this.player = 'hidden'
RuffleService.getRuffle().then((ruffle) => {
const player = ruffle.newest().createPlayer()
2021-04-12 00:00:23 +03:00
player.config = {
2026-01-06 16:22:52 +02:00
letterbox: 'on',
2021-04-12 00:00:23 +03:00
}
const container = this.$refs.container
container.appendChild(player)
2021-04-12 00:00:23 +03:00
player.style.width = '100%'
player.style.height = '100%'
2026-01-06 16:22:52 +02:00
player
.load(this.src)
.then(() => {
this.player = true
})
.catch((e) => {
console.error('Error loading ruffle', e)
this.player = 'error'
})
2021-04-12 00:00:23 +03:00
this.ruffleInstance = player
this.$emit('playerOpened')
})
2021-04-12 00:00:23 +03:00
},
2026-01-06 16:22:52 +02:00
closePlayer() {
this.ruffleInstance && this.ruffleInstance.remove()
2021-04-12 00:00:23 +03:00
this.player = false
this.$emit('playerClosed')
2026-01-06 16:22:52 +02:00
},
},
}
export default Flash