User controls & websocket fix

This commit is contained in:
Thomas
2020-08-05 14:54:21 +02:00
parent ea81b7f598
commit 3ff9be2f96
10 changed files with 59 additions and 35 deletions

View File

@@ -3,4 +3,5 @@
Webapp edition Webapp edition
socket messages types: serverInfos, login, leave, userList, createRoom, connectRoom, offer, answer, candidate socket messages types: serverInfos, login, leave, userList, createRoom, connectRoom, offer, answer, candidate
data types: status, vote
data types: status, vote, settings, userCommand

View File

@@ -1,24 +0,0 @@
# oozik
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

View File

@@ -63,11 +63,14 @@ export default {
rel: 0 rel: 0
} }
return this.isAdmin ? adminVars : userVars return this.isAdmin ? adminVars : userVars
},
lastUserCommand () {
return this.$store.state.room.lastUserCommand
} }
}, },
mounted () { mounted () {
this.player.addEventListener('onStateChange', this.playerStateChange) this.player.addEventListener('onStateChange', this.playerStateChange)
// setInterval(this.updateTimeCode, 1000) setInterval(this.updateTimeCode, 1000)
}, },
watch: { watch: {
roomStatus: function (status) { roomStatus: function (status) {
@@ -79,13 +82,26 @@ export default {
this.player.seekTo(status.player.timeCode, true) this.player.seekTo(status.player.timeCode, true)
if (status.player.playing) this.player.playVideo() if (status.player.playing) this.player.playVideo()
else this.player.pauseVideo() else this.player.pauseVideo()
},
lastUserCommand: function (command) {
switch (command.type) {
case 'play':
this.play()
break
case 'seek':
this.seek(command.argument)
break
case 'skip':
this.skip()
break
}
} }
}, },
methods: { methods: {
async playerStateChange (event) { async playerStateChange (event) {
console.log('[PLAYER] Status change ' + event.data) console.log('[PLAYER] Status change ' + event.data)
console.log(await event.target.getVideoData())
if (this.isAdmin || this.roomSettings.userControl) { if (this.isAdmin) {
this.$store.dispatch('room/setCurrent', { this.$store.dispatch('room/setCurrent', {
playerStatus: event.data, playerStatus: event.data,
timeCode: await this.player.getCurrentTime(), timeCode: await this.player.getCurrentTime(),
@@ -98,8 +114,12 @@ export default {
} }
}, },
play () { play () {
if (this.isAdmin) {
if (this.roomStatus.player.playing) this.player.pauseVideo() if (this.roomStatus.player.playing) this.player.pauseVideo()
else this.player.playVideo() else this.player.playVideo()
} else if (this.roomSettings.userControl) {
this.$store.dispatch('rtc/broadcast', { message: { type: 'play' }, type: 'userCommand' })
}
}, },
async mute () { async mute () {
if (await this.player.isMuted()) this.player.unMute() if (await this.player.isMuted()) this.player.unMute()
@@ -109,10 +129,12 @@ export default {
this.player.setVolume(volume) this.player.setVolume(volume)
}, },
skip () { skip () {
this.$store.commit('room/CURRENT_END') if (this.isAdmin) this.$store.commit('room/CURRENT_END')
else if (this.roomSettings.userControl) this.$store.dispatch('rtc/broadcast', { message: { type: 'skip' }, type: 'userCommand' })
}, },
seek (time) { seek (time) {
this.player.seekTo(time, true) if (this.isAdmin) this.player.seekTo(time, true)
else if (this.roomSettings.userControl) this.$store.dispatch('rtc/broadcast', { message: { type: 'seek', argument: time }, type: 'userCommand' })
}, },
async updateTimeCode () { async updateTimeCode () {
if (this.localSettings.playLink) this.$store.dispatch('room/setTimeCode', await this.player.getCurrentTime()) if (this.localSettings.playLink) this.$store.dispatch('room/setTimeCode', await this.player.getCurrentTime())

View File

@@ -24,7 +24,8 @@ const state = {
localSettings: { localSettings: {
playLink: false, playLink: false,
externalSearch: false externalSearch: false
} },
lastUserCommand: null
} }
const getters = { const getters = {
@@ -40,6 +41,9 @@ const actions = {
setRoomStatus ({ commit }, roomStatus) { setRoomStatus ({ commit }, roomStatus) {
commit('SET_ROOMSTATUS', roomStatus) commit('SET_ROOMSTATUS', roomStatus)
}, },
setUserCommand ({ commit }, command) {
commit('SET_USERCOMMAND', command)
},
setRoomSettings ({ commit, dispatch, state }, roomSettings) { setRoomSettings ({ commit, dispatch, state }, roomSettings) {
commit('SET_ROOMSETTINGS', roomSettings) commit('SET_ROOMSETTINGS', roomSettings)
if (state.admin) dispatch('rtc/broadcast', { message: state.roomSettings, type: 'settings' }, { root: true }) if (state.admin) dispatch('rtc/broadcast', { message: state.roomSettings, type: 'settings' }, { root: true })
@@ -87,6 +91,8 @@ const actions = {
case 2: case 2:
commit('CURRENT_PAUSE', timeCode) commit('CURRENT_PAUSE', timeCode)
break break
default:
return
} }
dispatch('rtc/broadcast', { message: state.roomStatus, type: 'status' }, { root: true }) dispatch('rtc/broadcast', { message: state.roomStatus, type: 'status' }, { root: true })
}, },
@@ -140,6 +146,9 @@ const mutations = {
SET_CURRENTTITLE (state, title) { SET_CURRENTTITLE (state, title) {
state.roomStatus.current.title = title state.roomStatus.current.title = title
}, },
SET_USERCOMMAND (state, command) {
state.lastUserCommand = command
},
ADD_VOTE (state, { title, link, linkID, voterName }) { ADD_VOTE (state, { title, link, linkID, voterName }) {
var play = state.roomStatus.playlist.find(play => play.linkID === linkID) var play = state.roomStatus.playlist.find(play => play.linkID === linkID)
if (play === undefined) { if (play === undefined) {

View File

@@ -195,7 +195,7 @@ function handleDataChannelMessage (event) {
console.log('[RTC] data channel message type ' + data.type) console.log('[RTC] data channel message type ' + data.type)
switch (data.type) { switch (data.type) {
case 'status': case 'status':
if (!store.state.room.admin || store.state.room.roomSettings.userControl) store.dispatch('room/setRoomStatus', data.message) if (!store.state.room.admin) store.dispatch('room/setRoomStatus', data.message)
break break
case 'settings': case 'settings':
if (!store.state.room.admin) store.dispatch('room/setRoomSettings', data.message) if (!store.state.room.admin) store.dispatch('room/setRoomSettings', data.message)
@@ -203,6 +203,9 @@ function handleDataChannelMessage (event) {
case 'vote': case 'vote':
store.dispatch('room/vote', { link: data.message.link, linkID: data.message.linkID, isPositive: data.message.isPositive, voterName: data.message.voterName }) store.dispatch('room/vote', { link: data.message.link, linkID: data.message.linkID, isPositive: data.message.isPositive, voterName: data.message.voterName })
break break
case 'userCommand':
if (store.state.room.roomSettings.userControl) store.dispatch('room/setUserCommand', data.message)
break
} }
} }

View File

@@ -2,6 +2,8 @@
// const connection = new WebSocket('wss://echo.websocket.org') // const connection = new WebSocket('wss://echo.websocket.org')
const connection = new WebSocket('wss://voozik.gltronic.ovh/socket') const connection = new WebSocket('wss://voozik.gltronic.ovh/socket')
// setTimeout(send({ type: 'alive' }), 5000)
export default function createSignalPlugin () { export default function createSignalPlugin () {
return store => { return store => {
connection.onopen = function () { connection.onopen = function () {

View File

@@ -60,13 +60,13 @@ export default {
watch: { watch: {
serverConnected: async function (isConnected) { serverConnected: async function (isConnected) {
if (!this.isLoggedIn && this.serverConnected) { if (!this.isLoggedIn && this.serverConnected) {
setTimeout(send({ type: 'alive' }), 5000)
const name = await localStorage.getItem('name') const name = await localStorage.getItem('name')
if (name) this.login(name) if (name) this.login(name)
else this.loginPrompt() else this.loginPrompt()
} }
}, },
isLoggedIn: function (success) { isLoggedIn: function (success) {
console.log('wwiguhspgus ' + success)
// a cause de null = false // a cause de null = false
if (success === false) { if (success === false) {
this.$buefy.toast.open({ this.$buefy.toast.open({

View File

@@ -0,0 +1,7 @@
package gltronic.voozik.business;
import org.springframework.web.socket.WebSocketSession;
public interface IYTSearch {
public void search (String query, WebSocketSession session);
}

View File

@@ -50,6 +50,10 @@ public class SocketHandler extends TextWebSocketHandler {
case "candidate": case "candidate":
roomManager.followRTC(session, message); roomManager.followRTC(session, message);
break; break;
case "search":
break;
case "alive":
break;
default: default:
roomManager.sendMessage(session, "error", "unknow command"); roomManager.sendMessage(session, "error", "unknow command");
} }

Binary file not shown.