mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
adding Request Queue
This commit is contained in:
@@ -7,11 +7,27 @@ class _RocketChatClientService {
|
||||
private hasPing = false
|
||||
private firstPingFunx: Function
|
||||
isLogin = false;
|
||||
request = []
|
||||
requestQueue = []
|
||||
|
||||
constructor() {}
|
||||
|
||||
private returns() {}
|
||||
|
||||
private attemptRequestQueue(arg, option) {
|
||||
|
||||
const conditionToSend = this.ws.connected == true && this.isLogin == true
|
||||
|
||||
if(conditionToSend) {
|
||||
this.requestQueue.push({
|
||||
arg: arg,
|
||||
status: {
|
||||
isLogin: this.isLogin,
|
||||
isConnected: this.ws.connected
|
||||
}
|
||||
})
|
||||
}
|
||||
return conditionToSend
|
||||
}
|
||||
|
||||
connect(firstPingFunx: Function) {
|
||||
this.hasPing = false
|
||||
@@ -45,6 +61,7 @@ class _RocketChatClientService {
|
||||
login(user) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
this.isLogin = false
|
||||
|
||||
const loginRequest = {
|
||||
msg: "method",
|
||||
@@ -66,6 +83,7 @@ class _RocketChatClientService {
|
||||
if(message.result) {
|
||||
if(message.result.token) {
|
||||
this.isLogin = true
|
||||
this.ws.wsMsgQueue()
|
||||
resolve(message)
|
||||
} else {
|
||||
this.isLogin = false
|
||||
@@ -84,6 +102,10 @@ class _RocketChatClientService {
|
||||
logout(){}
|
||||
|
||||
send(roomId, message) {
|
||||
|
||||
const conditions = this.attemptRequestQueue({...roomId, message}, {methodName:'send'})
|
||||
if(conditions == false) { return new Promise((resolve, reject) => { reject('no error')}); }
|
||||
|
||||
const requestId = uuidv4()
|
||||
|
||||
var request = {
|
||||
@@ -134,6 +156,10 @@ class _RocketChatClientService {
|
||||
|
||||
|
||||
subscribe(roomId : string) {
|
||||
|
||||
const conditions = this.attemptRequestQueue({roomId},{methodName: 'subscribe'})
|
||||
if(conditions == false) { return new Promise((resolve, reject) => { reject('no error')}); }
|
||||
|
||||
const requestId = uuidv4()
|
||||
var subscribeRequest = {
|
||||
"msg": "sub",
|
||||
@@ -196,12 +222,16 @@ class _RocketChatClientService {
|
||||
onopen:()=> {
|
||||
this.ws.connected = true
|
||||
console.log('================== welcome to socket server =====================')
|
||||
|
||||
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()) => {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user