diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index aa2d76f..71dac6f 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -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); + }, }