mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
improve login to rocket chat via websocket
This commit is contained in:
@@ -19,23 +19,34 @@ export class RocketChatClientService {
|
||||
|
||||
private returns() {}
|
||||
|
||||
private attemptRequestQueue(arg, option) {
|
||||
private attemptRequestQueue(arg, options) {
|
||||
|
||||
const conditionToSend = this.ws.connected == true && this.isLogin == true
|
||||
const conditionToSend = this.ws.connected == false || this.isLogin == false
|
||||
|
||||
if(conditionToSend) {
|
||||
if(!conditionToSend) {
|
||||
console.log('requestQueue')
|
||||
this.requestQueue.push({
|
||||
arg: arg,
|
||||
methodName: options.methodName,
|
||||
status: {
|
||||
isLogin: this.isLogin,
|
||||
isConnected: this.ws.connected
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return conditionToSend
|
||||
}
|
||||
|
||||
private runRequestQueue(){}
|
||||
private runRequestQueue(){
|
||||
this.requestQueue.forEach((request,index, object)=>{
|
||||
console.log('runRequestQueue '+index)
|
||||
const method = request.methodName
|
||||
const arg = request.arg
|
||||
this[method](...arg)
|
||||
object.splice(index, 1);
|
||||
})
|
||||
}
|
||||
|
||||
connect(firstPingFunx: Function) {
|
||||
this.hasPing = false
|
||||
@@ -91,8 +102,8 @@ export class RocketChatClientService {
|
||||
if(message.result) {
|
||||
if(message.result.token) {
|
||||
this.isLogin = true
|
||||
this.runRequestQueue()
|
||||
this.ws.wsMsgQueue()
|
||||
this.runRequestQueue()
|
||||
resolve(message)
|
||||
} else {
|
||||
this.isLogin = false
|
||||
@@ -342,17 +353,14 @@ export class RocketChatClientService {
|
||||
onopen:()=> {
|
||||
this.ws.connected = true
|
||||
console.log('================== welcome to socket server =====================')
|
||||
this.ws.wsMsgQueue()
|
||||
},
|
||||
wsMsgQueue:()=> {
|
||||
this.wsMsgQueue.forEach((item, index, object) => {
|
||||
this.ws.send(item.message, item.requestId);
|
||||
object.splice(index, 1);
|
||||
})
|
||||
},
|
||||
wsMsgQueue:()=> {
|
||||
// this.wsMsgQueue.forEach((item, index, object) => {
|
||||
// this.ws.send(item.message, item.requestId);
|
||||
// object.splice(index, 1);
|
||||
// })
|
||||
},
|
||||
send: (message: object, requestId = uuidv4()) => {
|
||||
|
||||
if (this.ws.connected == false) { // save data to send when back online
|
||||
|
||||
Reference in New Issue
Block a user