mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
improve
This commit is contained in:
@@ -15,13 +15,6 @@ export class WsChatService {
|
||||
loginResponse = {}
|
||||
|
||||
constructor() {
|
||||
|
||||
|
||||
window.addEventListener('online', ()=>{
|
||||
this.connect()
|
||||
this.login()
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
connect() {
|
||||
@@ -612,13 +605,16 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
private wsCallbacks: {[key: string]: wsCallbacksParams} = {}
|
||||
private wsReconnect = 0
|
||||
|
||||
private n = 0
|
||||
|
||||
private ws = {
|
||||
connected: false,
|
||||
registerCallback:(params: wsCallbacksParams) => {
|
||||
|
||||
let id = params.requestId || params.key || uuidv4()
|
||||
this.wsCallbacks[id] = params
|
||||
|
||||
this.n++
|
||||
console.log('n', this.n)
|
||||
return id
|
||||
},
|
||||
connect:()=> {
|
||||
@@ -629,7 +625,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
this.socket.onclose = this.ws.onclose;
|
||||
this.socket.onerror = this.ws.onerror;
|
||||
},
|
||||
onopen:()=> {
|
||||
onopen: async ()=> {
|
||||
this.ws.connected = true
|
||||
|
||||
console.log('================== welcome to socket server =====================')
|
||||
@@ -639,9 +635,10 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
if(this.wsReconnect >= 1) {
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if(value.type== 'reConnect') {
|
||||
const dontRepeat = value.funx()
|
||||
const dontRepeat = await value.funx()
|
||||
|
||||
if(dontRepeat) {
|
||||
this.n--
|
||||
delete this.wsCallbacks[key]
|
||||
}
|
||||
|
||||
@@ -681,15 +678,16 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
return requestId
|
||||
},
|
||||
|
||||
onmessage:(event: any)=> {
|
||||
onmessage: async (event: any)=> {
|
||||
const data = JSON.parse(event.data)
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if(value.type== 'Onmessage') {
|
||||
const dontRepeat = value.funx(data)
|
||||
const dontRepeat = await value.funx(data)
|
||||
|
||||
if(dontRepeat) {
|
||||
delete this.wsCallbacks[key]
|
||||
this.n--
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user