add reconnect for websocket

This commit is contained in:
Peter Maquiran
2022-01-10 08:34:30 +01:00
parent e2f69a6788
commit abdc9ea231
2 changed files with 14 additions and 10 deletions
@@ -113,8 +113,6 @@ export class NewPublicationPage implements OnInit {
// this.takePicture(); // this.takePicture();
} }
imageUrl;
async takePicture() { async takePicture() {
const capturedImage = await Camera.getPhoto({ const capturedImage = await Camera.getPhoto({
@@ -125,10 +123,8 @@ export class NewPublicationPage implements OnInit {
}); });
const response = await fetch(capturedImage.webPath!); const response = await fetch(capturedImage.webPath!);
this.imageUrl = capturedImage.webPath
const blob = await response.blob(); const blob = await response.blob();
this.convertBlobToBase64Worker.postMessage(blob); this.convertBlobToBase64Worker.postMessage(blob);
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> { this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
this.capturedImage = oEvent.data this.capturedImage = oEvent.data
@@ -4,13 +4,16 @@ import { v4 as uuidv4 } from 'uuid'
class _RocketChatClientService { class _RocketChatClientService {
connected = false connected = false
hasPing = false private hasPing = false
private firstPingFunx: Function
constructor() {} constructor() {}
private returns() {} private returns() {}
connect(firstPing: Function) { connect(firstPingFunx: Function) {
this.hasPing = false
this.firstPingFunx = firstPingFunx
this.ws.connect('wss://gabinetedigitalchat.dyndns.info/websocket'); this.ws.connect('wss://gabinetedigitalchat.dyndns.info/websocket');
@@ -27,7 +30,7 @@ class _RocketChatClientService {
this.ws.send({msg:"pong"}) this.ws.send({msg:"pong"})
if(this.hasPing == false) { if(this.hasPing == false) {
// first ping // first ping
firstPing() firstPingFunx()
this.hasPing = true this.hasPing = true
} }
} }
@@ -83,6 +86,11 @@ class _RocketChatClientService {
deleteMessage() {} deleteMessage() {}
createRoom() {} createRoom() {}
getRooms() {
}
subscribe() { subscribe() {
var subscribeRequest = { var subscribeRequest = {
"msg": "sub", "msg": "sub",
@@ -168,11 +176,11 @@ class _RocketChatClientService {
}, },
onclose:(event: any)=> { onclose:(event: any)=> {
this.connect(this.firstPingFunx())
this.connected = false this.connected = false
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`); console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
setTimeout(()=>{
// this.connect(this.url)
}, 500)
}, },
onerror: (event: any) => { onerror: (event: any) => {