Removed socket.io and implemented WebSockets

This commit is contained in:
RemixDev
2021-02-25 11:31:30 +01:00
parent 55125684cb
commit 509f940afd
6 changed files with 1206 additions and 1241 deletions

View File

@@ -69,7 +69,8 @@ export default {
// ConfirmModal
},
mounted() {
socket.on('connect', () => {
socket.addEventListener('open', (event) => {
console.log("Connected to WebSocket")
this.isSocketConnected = true
})
}

View File

@@ -7,8 +7,5 @@
"@components/*": ["./components/*"]
}
},
"typeAcquisition": {
"include": ["socket.io-client"]
},
"exclude": ["assets/**/*", "styles/**/*"]
}

View File

@@ -1,8 +1,25 @@
import store from '@/store'
import io from 'socket.io-client'
export const socket = io.connect('/')
class CustomSocket extends WebSocket {
constructor(args) {
super(args)
console.log(args)
}
socket.on('init_update', data => {
store.dispatch('setAppInfo', data)
})
emit(key, data) {
console.log("emit:", key, data)
console.log(this.readyState)
if (this.readyState != WebSocket.OPEN) return false
this.send(JSON.stringify({key:key, data:data}))
}
on(key, callback) {
this.addEventListener('message', function(event){
console.log(event.data)
let data = JSON.parse(event.data)
if (data.key == key) callback(data.data)
})
}
}
export const socket = new CustomSocket('ws://' + location.host + '/')