Imrpove websocket inicial connect

This commit is contained in:
Peter Maquiran
2022-01-07 16:34:02 +01:00
parent ee8550f983
commit e2f69a6788
2 changed files with 16 additions and 85 deletions
@@ -4,14 +4,15 @@ import { v4 as uuidv4 } from 'uuid'
class _RocketChatClientService {
connected = false
hasPing = false
constructor() {}
private returns() {}
connect(url = 'wss://gabinetedigitalchat.dyndns.info/websocket') {
connect(firstPing: Function) {
this.ws.connect(url);
this.ws.connect('wss://gabinetedigitalchat.dyndns.info/websocket');
const connectMessage = {
msg: "connect",
@@ -20,10 +21,15 @@ class _RocketChatClientService {
}
this.ws.send(connectMessage)
this.ws.registerCallback('Onmessage',(message: any) => {
if(message.msg == "ping") {
this.ws.send({msg:"pong"})
if(this.hasPing == false) {
// first ping
firstPing()
this.hasPing = true
}
}
})
@@ -51,7 +57,7 @@ class _RocketChatClientService {
return requestId
}
logout(){ }
logout(){}
send(roomId, message, option) {
const requestId = uuidv4()
@@ -95,7 +101,7 @@ class _RocketChatClientService {
}
// socket ==================================================================
// socket class ==================================================================
private socket!: WebSocket;
private url = ''
private callBacks: {