forked from rc/aircox
fix logs merge with diff algorithm
This commit is contained in:
@ -1,11 +1,15 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
import OnAir from './onAir.vue';
|
||||
import Player from './player.vue';
|
||||
import Tab from './tab.vue';
|
||||
import Tabs from './tabs.vue';
|
||||
|
||||
Vue.component('a-on-air', OnAir);
|
||||
Vue.component('a-player', Player);
|
||||
Vue.component('a-tab', Tab);
|
||||
Vue.component('a-tabs', Tabs);
|
||||
|
||||
export {Tab, Tabs};
|
||||
export {Player, Tab, Tabs};
|
||||
|
||||
|
||||
|
63
assets/vue/onAir.vue
Normal file
63
assets/vue/onAir.vue
Normal file
@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<div class="media">
|
||||
<!-- TODO HERE -->
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
props: {
|
||||
url: String,
|
||||
timeout: Number,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
// promise is set to null on destroy: this is used as check
|
||||
// for timeout to know wether to repeat itself or not.
|
||||
promise: null,
|
||||
// on air infos
|
||||
on_air: null
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
methods: {
|
||||
fetch() {
|
||||
const promise = fetch(url).then(response =>
|
||||
reponse.ok ? response.json
|
||||
: Promise.reject(response)
|
||||
).then(data => {
|
||||
this.on_air = data.results;
|
||||
return this.on_air
|
||||
})
|
||||
|
||||
this.promise = promise;
|
||||
return promise;
|
||||
},
|
||||
|
||||
refresh() {
|
||||
const promise = this.fetch();
|
||||
promise.then(data => {
|
||||
if(promise != this.promise)
|
||||
return;
|
||||
|
||||
window.setTimeout(() => this.update(), this.timeout*1000)
|
||||
})
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.update()
|
||||
},
|
||||
|
||||
destroyed() {
|
||||
this.promise = null;
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
|
82
assets/vue/player.vue
Normal file
82
assets/vue/player.vue
Normal file
@ -0,0 +1,82 @@
|
||||
<template>
|
||||
<div class="media">
|
||||
<div class="media-left">
|
||||
<div class="button is-size-4" @click="toggle()">
|
||||
<span class="fas fa-pause" v-if="playing"></span>
|
||||
<span class="fas fa-play" v-else></span>
|
||||
</div>
|
||||
<audio ref="audio" @playing="onChange" @ended="onChange" @pause="onChange">
|
||||
<slot name="sources"></slot>
|
||||
</audio>
|
||||
</div>
|
||||
<div class="media-content">
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
export const State = {
|
||||
paused: 0,
|
||||
playing: 1,
|
||||
loading: 2,
|
||||
}
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
state: State.paused,
|
||||
}
|
||||
},
|
||||
|
||||
props: {
|
||||
onAir: String,
|
||||
src: String,
|
||||
},
|
||||
|
||||
computed: {
|
||||
paused() { return this.state == State.paused; },
|
||||
playing() { return this.state == State.playing; },
|
||||
loading() { return this.state == State.loading; },
|
||||
},
|
||||
|
||||
methods: {
|
||||
load(src) {
|
||||
const audio = this.$refs.audio;
|
||||
audio.src = src;
|
||||
audio.load()
|
||||
},
|
||||
|
||||
play(src) {
|
||||
if(src)
|
||||
this.load(src);
|
||||
this.$refs.audio.play().catch(e => console.error(e))
|
||||
},
|
||||
|
||||
pause() {
|
||||
this.$refs.audio.pause()
|
||||
},
|
||||
|
||||
toggle() {
|
||||
if(this.paused)
|
||||
this.play()
|
||||
else
|
||||
this.pause()
|
||||
},
|
||||
|
||||
onChange(event) {
|
||||
const audio = this.$refs.audio;
|
||||
this.state = audio.paused ? State.paused : State.playing;
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.load(this.src);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user