Removed socket.io and implemented WebSockets

This commit is contained in:
RemixDev 2021-02-25 11:31:30 +01:00
parent 55125684cb
commit 509f940afd
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
6 changed files with 1206 additions and 1241 deletions

View File

@ -17,7 +17,6 @@
"@vue/composition-api": "^1.0.0-beta.21", "@vue/composition-api": "^1.0.0-beta.21",
"flag-icon-css": "^3.5.0", "flag-icon-css": "^3.5.0",
"lodash-es": "^4.17.15", "lodash-es": "^4.17.15",
"socket.io-client": "^3.1.0",
"svg-country-flags": "^1.2.9", "svg-country-flags": "^1.2.9",
"toastify-js": "^1.9.3", "toastify-js": "^1.9.3",
"vue": "^2.6.12", "vue": "^2.6.12",

File diff suppressed because one or more lines are too long

View File

@ -28,10 +28,6 @@ export default {
find: 'vue', find: 'vue',
replacement: 'vue/dist/vue.esm' replacement: 'vue/dist/vue.esm'
}, },
{
find: 'socket.io-client',
replacement: 'socket.io-client/dist/socket.io.min'
},
{ {
find: '@', find: '@',
replacement: __dirname + '/src' replacement: __dirname + '/src'

View File

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

View File

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

View File

@ -1,8 +1,25 @@
import store from '@/store' 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 => { emit(key, data) {
store.dispatch('setAppInfo', 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 + '/')