mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
save
This commit is contained in:
@@ -8,7 +8,7 @@ import { environment } from 'src/environments/environment';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { Message } from 'src/app/models/message.model';
|
||||
import { Observable, Subject } from "rxjs/Rx";
|
||||
import { WebsocketService } from './socket/websocket.service';
|
||||
import { WebsocketService } from './websocket.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -8,7 +8,7 @@ class _RocketChatClientService {
|
||||
private firstPingFunx: Function
|
||||
isLogin = false;
|
||||
request = []
|
||||
|
||||
|
||||
constructor() {}
|
||||
|
||||
private returns() {}
|
||||
@@ -26,7 +26,7 @@ class _RocketChatClientService {
|
||||
}
|
||||
|
||||
this.ws.send(connectMessage)
|
||||
|
||||
|
||||
this.ws.registerCallback({type:'Onmessage',funx:(message: any) => {
|
||||
|
||||
if(message.msg == "ping") {
|
||||
@@ -141,7 +141,7 @@ class _RocketChatClientService {
|
||||
}
|
||||
|
||||
this.ws.send(subscribeRequest);
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', requestId, runOnces: true, funx:(message)=>{
|
||||
if(message.result.id == requestId) { // same request send
|
||||
@@ -155,7 +155,7 @@ class _RocketChatClientService {
|
||||
private disconnect = () => {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// socket class ==================================================================
|
||||
private socket!: WebSocket;
|
||||
private wsUrl = ''
|
||||
@@ -165,7 +165,7 @@ class _RocketChatClientService {
|
||||
private ws = {
|
||||
connected: false,
|
||||
registerCallback:(params: wsCallbacksParams) =>{
|
||||
|
||||
|
||||
if(!params.requestId) {
|
||||
params.requestId = uuidv4()
|
||||
}
|
||||
@@ -191,15 +191,15 @@ 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);
|
||||
})
|
||||
|
||||
|
||||
},
|
||||
send: (message: object, requestId = uuidv4()) => {
|
||||
|
||||
|
||||
if (this.ws.connected == false) { // save data to send when back online
|
||||
console.log('save msgQueue')
|
||||
this.wsMsgQueue.push({message, requestId})
|
||||
@@ -210,24 +210,24 @@ class _RocketChatClientService {
|
||||
}
|
||||
return requestId
|
||||
},
|
||||
|
||||
|
||||
onmessage:(event: any)=> {
|
||||
const data = JSON.parse(event.data)
|
||||
console.log('event.data', data)
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if(value.type== 'Onmessage') {
|
||||
value.funx(data)
|
||||
if(value.runOnces) {
|
||||
delete this.wsCallbacks[value.requestId || key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
onclose:(event: any)=> {
|
||||
|
||||
this.connect(this.firstPingFunx())
|
||||
@@ -235,7 +235,7 @@ class _RocketChatClientService {
|
||||
this.ws.connected = false
|
||||
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
|
||||
},
|
||||
|
||||
|
||||
onerror: (event: any) => {
|
||||
console.log(`[error] ${event.message}`);
|
||||
}
|
||||
@@ -245,4 +245,4 @@ class _RocketChatClientService {
|
||||
}
|
||||
|
||||
|
||||
export const RocketChatClientService = new _RocketChatClientService()
|
||||
export const RocketChatClientService = new _RocketChatClientService()
|
||||
|
||||
Reference in New Issue
Block a user