fixed css

This commit is contained in:
STEINNI
2025-09-18 17:55:05 +00:00
parent 190d8df334
commit b5f0fb0c5d
13 changed files with 276 additions and 98 deletions
+5 -71
View File
@@ -36,38 +36,7 @@ class MessageBusWorker {
this.token = false
this.stateMachine = 'DISCONNECTED'
this.noReconnect = false
// 'DISCONNECTED'
// -> 'LOGIN' (receive challenge & answer to it)
// -> 'READY' (received logged=true)
this.getToken()
}
/**
*
*/
getToken() {
if(!this.config.devotpToken){
fetch(this.config.tokenUrl+'?'+crypto.randomUUID(),{
credentials: 'include'
})
.then(response => response.json(), (err => {console.log('ERROR IN FETCH:',err)}))
.then(data => {
if(data.success && data.payload && data.payload.token) {
this.token = data.payload.token
if(this.config.debug && ''=='sensitive-even-for-debug') console.log(`Received Token : ${this.token}`)
this.connect();
} else {
console.warn('Could not get messagebus token !')
//TODO retry once in a while / integrate in the whole connect process
// to be part of retrials...
}
})
} else {
console.warn('!!! Using dev token for bus !!!')
this.token = this.config.devotpToken
this.connect();
}
this.connect();
}
/**
@@ -103,23 +72,11 @@ class MessageBusWorker {
* @param {*} e
*/
WSonOpen(e){
this.stateMachine = 'LOGIN'
this.stateMachine = 'READY'
clearTimeout( this.ConnectTimeout);
console.log('Websocket connection established');
this.curReconnectTime = 0;
}
/**
*
* @param {*} challenge
*/
async login(challenge) {
let data = new TextEncoder().encode(this.token+challenge)
let bytesBuf = await crypto.subtle.digest("SHA-512", data)
let arrayBuf = Array.from(new Uint8Array(bytesBuf))
let response = arrayBuf.map((b) => b.toString(16).padStart(2, "0")).join("")
if(this.config.debug && ''=='sensitive-even-for-debug') console.log(`Answering to challenge, with userinfo:`, response, this.userInfo)
this.clientActionDispatch({'action':'LOGIN', 'userInfo': this.userInfo , 'otp': response});
postMessage({'event': 'connected' });
}
/**
@@ -141,29 +98,6 @@ class MessageBusWorker {
return;
}
//if(this.config.debug) console.log(`Received MSG (in state:${this.stateMachine}) :`, data, this.stateMachine)
// LOGIN messages
if(this.stateMachine == 'LOGIN'){
if(data.action!='LOGIN') { // Non LOGIN messages in a LOGIN state are garbage
console.warn('WSS: Non-login message in a LOGIN state',data.action)
return
}
if(data.challenge) { // step1: challenge to reply
if(this.config.debug && ''=='sensitive-even-for-debug') console.log(`Got challenge ${data.challenge}...`)
this.login(data.challenge)
return
} else if(data.logged===true){ // step2 logged !
if(this.config.debug) console.log(`Logged !`)
this.stateMachine = 'READY'
postMessage({'event': 'connected' });
return
} else if(data.logged===false){ // step2 bad login !
this.noReconnect = true
console.warn('WSS-Login: challenge-response refused. (session lost?)')
return
}
}
if((data.action=='PING') && this.keepAlive){ // Keep Alive is managed here
this.clientActionDispatch({'action':'PONG'});
return
@@ -196,8 +130,8 @@ class MessageBusWorker {
}
var rjit = (Math.random()*reconnectJitterPercent)-(reconnectJitterPercent/2);
this.curReconnectTime += (this.curReconnectTime*(rjit/100));
// Reconnect in curReconnectTime (=>getToken THEN connect)
setTimeout(this.getToken.bind(this), Math.floor(1000*this.curReconnectTime));
// Reconnect in curReconnectTime
setTimeout(this.connect.bind(this), Math.floor(1000*this.curReconnectTime));
}
}