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

54 lines
1.4 KiB
JavaScript
Raw Normal View History

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