Working datachannel, youtube support & server fix

This commit is contained in:
Thomas
2020-07-29 19:03:11 +02:00
parent 927fa2d1a2
commit e8247a1ba3
9 changed files with 295 additions and 16 deletions

View File

@@ -39,8 +39,8 @@ const actions = {
leave ({ commit }) {
commit('LEAVE')
},
broadcast ({ commit }, message) {
commit('BROADCAST', message)
broadcast ({ commit }, { message, type }) {
commit('BROADCAST', { message: message, type: type })
}
}
@@ -79,6 +79,7 @@ const mutations = {
var peer = state.peers.find(peer => peer.name === target)
peer.dataChannel = peer.connection.createDataChannel('dataChannel')
peer.dataChannel.onmessage = handleDataChannelMessage
peer.dataChannel.onopen = handleDataChannelStateChangeEvent
peer.dataChannel.onclose = handleDataChannelStateChangeEvent
@@ -127,9 +128,14 @@ const mutations = {
})
state.peers = {}
},
BROADCAST (state, message) {
BROADCAST (state, { message, type }) {
const data = JSON.stringify({
type: type,
message: message
})
console.log('[RTC] broadcast message ' + data)
state.peers.forEach(peer => {
peer.dataChannel.send(message)
peer.dataChannel.send(data)
})
}
}
@@ -167,17 +173,19 @@ function handleDataChannelCallback (event) {
peer.dataChannel.onopen = handleDataChannelStateChangeEvent
peer.dataChannel.onclose = handleDataChannelStateChangeEvent
store.dispatch('rtc/broadcast', store.state.room.roomStatus)
store.dispatch('rtc/broadcast', { message: store.state.room.roomStatus, type: 'status' })
}
function handleDataChannelMessage (event) {
console.log('[RTC] data channel message ' + event.data)
var data = event.data
var data = JSON.parse(event.data)
console.log('[RTC] data channel message type ' + data.type)
switch (data.type) {
case 'status':
store.dispatch('room/setRoomStatus', data.message)
break
case 'vote':
store.dispatch('room/vote', { link: data.message.link, isPositive: data.message.isPositive, voterName: data.message.voterName })
break
}
}