fix: removed multiple message events added to CustomWebsocket
This commit is contained in:
parent
c6a2f35fbf
commit
cbf3a5c677
@ -7,5 +7,6 @@
|
||||
"trailingComma": "none",
|
||||
"printWidth": 120,
|
||||
"arrowParens": "avoid",
|
||||
"vueIndentScriptAndStyle": false
|
||||
"vueIndentScriptAndStyle": false,
|
||||
"endOfLine": "lf"
|
||||
}
|
2600
public/js/bundle.js
2600
public/js/bundle.js
File diff suppressed because one or more lines are too long
47
src/app.js
47
src/app.js
@ -32,6 +32,30 @@ function startApp() {
|
||||
i18n,
|
||||
render: h => h(App)
|
||||
}).$mount('#app')
|
||||
|
||||
fetch('connect')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
store.dispatch('setAppInfo', data.update)
|
||||
|
||||
if (data.autologin) {
|
||||
console.log('Autologin')
|
||||
let arl = localStorage.getItem('arl')
|
||||
let accountNum = localStorage.getItem('accountNum')
|
||||
|
||||
if (arl) {
|
||||
arl = arl.trim()
|
||||
let result
|
||||
|
||||
if (accountNum != 0) {
|
||||
result = get('login', { arl: arl, force: true, child: accountNum || 0 })
|
||||
} else {
|
||||
result = get('login', { arl })
|
||||
}
|
||||
result.then(loggedIn)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function initClient() {
|
||||
@ -53,7 +77,7 @@ document.addEventListener('paste', pasteEvent => {
|
||||
if (router.currentRoute.name === 'Link Analyzer') {
|
||||
socket.emit('analyzeLink', pastedText)
|
||||
} else {
|
||||
if (pastedText.indexOf("\n") != -1) pastedText = pastedText.replace(/\n/g, ';');
|
||||
if (pastedText.indexOf('\n') != -1) pastedText = pastedText.replace(/\n/g, ';')
|
||||
sendAddToQueue(pastedText)
|
||||
}
|
||||
} else {
|
||||
@ -122,27 +146,6 @@ function loggedIn(data){
|
||||
}
|
||||
}
|
||||
|
||||
fetch('connect').then(response => response.json()).then(data => {
|
||||
store.dispatch('setAppInfo', data.update )
|
||||
if (data.autologin) {
|
||||
console.log("Autologin")
|
||||
let arl = localStorage.getItem('arl')
|
||||
let accountNum = localStorage.getItem('accountNum')
|
||||
|
||||
if (arl) {
|
||||
arl = arl.trim()
|
||||
let result
|
||||
|
||||
if (accountNum != 0) {
|
||||
result = get('login', {arl: arl, force:true, child:accountNum || 0})
|
||||
} else {
|
||||
result = get('login', {arl})
|
||||
}
|
||||
result.then(loggedIn)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
socket.on('logging_in', function() {
|
||||
toast(i18n.t('toasts.loggingIn'), 'loading', false, 'login-toast')
|
||||
|
@ -1,22 +1,32 @@
|
||||
import store from '@/store'
|
||||
|
||||
let wasEventListenerAdded = false
|
||||
|
||||
class CustomSocket extends WebSocket {
|
||||
constructor(args) {
|
||||
super(args)
|
||||
}
|
||||
|
||||
emit(key, data) {
|
||||
if (this.readyState != WebSocket.OPEN) return false
|
||||
if (this.readyState !== WebSocket.OPEN) return false
|
||||
this.send(JSON.stringify({ key: key, data: data }))
|
||||
}
|
||||
on(key, cb) {
|
||||
if (!wasEventListenerAdded) {
|
||||
wasEventListenerAdded = true
|
||||
|
||||
on(key, callback) {
|
||||
this.addEventListener('message', function(event){
|
||||
let data = JSON.parse(event.data)
|
||||
console.log(data)
|
||||
if (data.key == key) callback(data.data)
|
||||
this.addEventListener('message', event => {
|
||||
const messageData = JSON.parse(event.data)
|
||||
|
||||
if (messageData.key === key) {
|
||||
cb(messageData.data)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
off() {
|
||||
console.log('off!')
|
||||
// this.removeEventListener('message')
|
||||
}
|
||||
}
|
||||
|
||||
export const socket = new CustomSocket('ws://' + location.host + '/')
|
||||
|
Loading…
Reference in New Issue
Block a user