Добавил хоткей для навигации между стримами

This commit is contained in:
saber-nyan 2019-05-15 11:07:41 +03:00
parent 829595264d
commit 918c7ca85a
No known key found for this signature in database
GPG Key ID: 7B069E9C295E6B4A

View File

@ -28,6 +28,33 @@ export default {
data: function () {
return {
streams: [],
navigationKeysCallback: (e) => {
if (e.key === 'ArrowUp') {
e.preventDefault();
const index = this.$data.streams.findIndex(e => e.id === this.$props.streamId);
const newStream = this.$data.streams[index - 1];
if (!newStream) return;
const newId = newStream.id;
this.$router.push({name: 'home', params: {servicePort: this.$props.servicePort, streamId: newId}});
} else if (e.key === 'ArrowDown') {
e.preventDefault();
const index = this.$data.streams.findIndex(e => e.id === this.$props.streamId);
const newStream = this.$data.streams[index + 1];
if (!newStream) return;
const newId = newStream.id;
this.$router.push({name: 'home', params: {servicePort: this.$props.servicePort, streamId: newId}});
} else if (e.key === 'Home') {
const newStream = this.$data.streams[0];
if (!newStream) return;
const newId = newStream.id;
this.$router.push({name: 'home', params: {servicePort: this.$props.servicePort, streamId: newId}});
} else if (e.key === 'End') {
const newStream = this.$data.streams[this.$data.streams.length - 1];
if (!newStream) return;
const newId = newStream.id;
this.$router.push({name: 'home', params: {servicePort: this.$props.servicePort, streamId: newId}});
}
},
}
},
watch: {
@ -85,6 +112,12 @@ export default {
},
},
components: {Stream, InfiniteLoading,},
mounted() {
document.addEventListener('keyup', this.$data.navigationKeysCallback);
},
beforeDestroy() {
document.removeEventListener('keyup', this.$data.navigationKeysCallback);
},
}
</script>
<style>