diff --git a/client/src/components/Player.vue b/client/src/components/Player.vue index d284673..7a3eabc 100644 --- a/client/src/components/Player.vue +++ b/client/src/components/Player.vue @@ -7,13 +7,22 @@ @playing="roomStatus.player.playing"> -

- - - - -

+ + + +
+ + + +

{{convertTimeCode(roomStatus.player.timeCode)}} / {{convertTimeCode(roomStatus.player.timeLength)}}

@@ -51,6 +60,7 @@ export default { }, mounted () { this.player.addEventListener('onStateChange', this.playerStateChange) + setInterval(this.updateTimeCode, 1000) }, watch: { roomStatus: function (status) { @@ -72,6 +82,7 @@ export default { this.$store.dispatch('room/setCurrent', { playerStatus: event.data, timeCode: await this.player.getCurrentTime(), + timeLength: await this.player.getDuration(), title: await event.target.getVideoData().title }) } @@ -80,15 +91,26 @@ export default { if (this.roomStatus.player.playing) this.player.pauseVideo() else this.player.playVideo() }, - mute () { - if (this.player.isMuted()) this.player.unMute() + async mute () { + if (await this.player.isMuted()) this.player.unMute() else this.player.mute() }, volume (volume) { this.player.setVolume(volume) }, skip () { - + this.$store.commit('room/CURRENT_END') + }, + seek (time) { + this.player.seekTo(time, true) + }, + async updateTimeCode () { + if (this.settings.playLink) this.$store.dispatch('room/setTimeCode', await this.player.getCurrentTime()) + }, + convertTimeCode (timeCode) { + const minutes = Math.round(timeCode / 60) + const seconds = Math.round(timeCode % 60) + return minutes + ':' + seconds } } } @@ -99,4 +121,14 @@ export default { text-align: center; max-width: 500px; } + +.playerButton { + margin-left: 10px; +} + +.playerVolume { + margin-left: 30px; + margin-right: 30px; + max-width: 150px; +} diff --git a/client/src/store/roomModule.js b/client/src/store/roomModule.js index f1a12cb..1067ff5 100644 --- a/client/src/store/roomModule.js +++ b/client/src/store/roomModule.js @@ -35,6 +35,9 @@ const actions = { setAdmin ({ commit }) { commit('SET_ADMIN') }, + setTimeCode ({ commit }, timeCode) { + commit('SET_TIMECODE', timeCode) + }, vote ({ commit, dispatch, state }, { link, linkID, isPositive, voterName }) { console.log('vote on ' + link + ' | ' + linkID + ' (' + isPositive + ') by ' + voterName) if (isPositive) { @@ -51,7 +54,7 @@ const actions = { } dispatch('rtc/broadcast', { message: state.roomStatus, type: 'status' }, { root: true }) }, - setCurrent ({ commit, dispatch }, { playerStatus, timeCode, title }) { + setCurrent ({ commit, dispatch }, { playerStatus, timeCode, timeLength, title }) { switch (playerStatus) { case 0: commit('CURRENT_END') @@ -59,12 +62,33 @@ const actions = { case 1: commit('CURRENT_PLAY', timeCode) commit('SET_CURRENTTITLE', title) + commit('SET_TIMELENGTH', timeLength) break case 2: commit('CURRENT_PAUSE', timeCode) break } dispatch('rtc/broadcast', { message: state.roomStatus, type: 'status' }, { root: true }) + }, + leave ({ commit, dispatch }) { + dispatch('rtc/leave', null, { root: true }) + commit('SET_ROOMSTATUS', { + roomName: '', + roomCode: '', + player: { + timeCode: 0, + timeLength: 0, + playing: true + }, + current: { + link: '', + linkID: '', + title: '', + votes: 0, + voters: [] + }, + playlist: [] + }) } } @@ -81,6 +105,12 @@ const mutations = { SET_ADMIN (state) { state.admin = true }, + SET_TIMECODE (state, timeCode) { + state.roomStatus.player.timeCode = timeCode + }, + SET_TIMELENGTH (state, timeLength) { + state.roomStatus.player.timeLength = timeLength + }, SET_CURRENTTITLE (state, title) { state.roomStatus.current.title = title }, diff --git a/client/src/store/rtcModule.js b/client/src/store/rtcModule.js index 6a1fc21..2ae8354 100644 --- a/client/src/store/rtcModule.js +++ b/client/src/store/rtcModule.js @@ -124,9 +124,10 @@ const mutations = { }, LEAVE (state) { state.peers.forEach((peer) => { + peer.dataChannel.close() peer.connection.close() }) - state.peers = {} + state.peers = [] }, BROADCAST (state, { message, type }) { const data = JSON.stringify({ diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index 5d841d8..9546eb5 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -1,22 +1,28 @@ @@ -40,10 +46,18 @@ export default { }, serverConnected () { return this.$store.state.app.signalServerConnected + }, + isLoggedIn () { + return this.$store.state.app.loginSuccess + }, + userName () { + return this.$store.state.rtc.name } }, - mounted () { - this.loginPrompt() + watch: { + serverConnected: function (isConnected) { + if (!this.isLoggedIn && this.serverConnected) this.loginPrompt() + } }, methods: { loginPrompt () { diff --git a/client/src/views/Room.vue b/client/src/views/Room.vue index 1fdd2b5..e9ac08c 100644 --- a/client/src/views/Room.vue +++ b/client/src/views/Room.vue @@ -9,7 +9,7 @@ - + @@ -21,12 +21,16 @@ -
+ Play link -
-
+ + Show player -
+ +
+ + Leave +
@@ -76,6 +80,12 @@ export default { this.settings.playLink = true this.settings.showPlayer = true } + }, + methods: { + leave () { + this.$store.dispatch('room/leave') + this.$router.push({ name: 'Home' }) + } } }