summaryrefslogtreecommitdiff
path: root/src/web/app/common/views/components/stream-indicator.vue
blob: 00bd58c1f9d6042e345d980b49e482d73f98a117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<template>
<div class="mk-stream-indicator" v-if="stream">
	<p v-if=" stream.state == 'initializing' ">
		%fa:spinner .pulse%
		<span>%i18n:common.tags.mk-stream-indicator.connecting%<mk-ellipsis/></span>
	</p>
	<p v-if=" stream.state == 'reconnecting' ">
		%fa:spinner .pulse%
		<span>%i18n:common.tags.mk-stream-indicator.reconnecting%<mk-ellipsis/></span>
	</p>
	<p v-if=" stream.state == 'connected' ">
		%fa:check%
		<span>%i18n:common.tags.mk-stream-indicator.connected%</span>
	</p>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import * as anime from 'animejs';

export default Vue.extend({
	data() {
		return {
			stream: null
		};
	},
	created() {
		this.stream = this.$root.$data.os.stream.borrow();

		this.$root.$data.os.stream.on('connected', this.onConnected);
		this.$root.$data.os.stream.on('disconnected', this.onDisconnected);

		this.$nextTick(() => {
			if (this.stream.state == 'connected') {
				this.$el.style.opacity = '0';
			}
		});
	},
	beforeDestroy() {
		this.$root.$data.os.stream.off('connected', this.onConnected);
		this.$root.$data.os.stream.off('disconnected', this.onDisconnected);
	},
	methods: {
		onConnected() {
			this.stream = this.$root.$data.os.stream.borrow();

			setTimeout(() => {
				anime({
					targets: this.$el,
					opacity: 0,
					easing: 'linear',
					duration: 200
				});
			}, 1000);
		},
		onDisconnected() {
			this.stream = null;

			anime({
				targets: this.$el,
				opacity: 1,
				easing: 'linear',
				duration: 100
			});
		}
	}
});
</script>

<style lang="stylus" scoped>
.mk-stream-indicator
	pointer-events none
	position fixed
	z-index 16384
	bottom 8px
	right 8px
	margin 0
	padding 6px 12px
	font-size 0.9em
	color #fff
	background rgba(0, 0, 0, 0.8)
	border-radius 4px

	> p
		display block
		margin 0

		> [data-fa]
			margin-right 0.25em

</style>