From abdc9ea2314ab819200aa362deafb2fa07a34999 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 10 Jan 2022 08:34:30 +0100 Subject: [PATCH] add reconnect for websocket --- .../new-publication/new-publication.page.ts | 4 ---- .../socket/rocket-chat-client.service.ts | 20 +++++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/app/pages/publications/new-publication/new-publication.page.ts b/src/app/pages/publications/new-publication/new-publication.page.ts index 5d562fdde..f83d7f522 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -113,8 +113,6 @@ export class NewPublicationPage implements OnInit { // this.takePicture(); } - imageUrl; - async takePicture() { const capturedImage = await Camera.getPhoto({ @@ -125,10 +123,8 @@ export class NewPublicationPage implements OnInit { }); const response = await fetch(capturedImage.webPath!); - this.imageUrl = capturedImage.webPath const blob = await response.blob(); - this.convertBlobToBase64Worker.postMessage(blob); this.convertBlobToBase64Worker.onmessage = async (oEvent)=> { this.capturedImage = oEvent.data diff --git a/src/app/services/socket/rocket-chat-client.service.ts b/src/app/services/socket/rocket-chat-client.service.ts index 94f279628..2a588120d 100644 --- a/src/app/services/socket/rocket-chat-client.service.ts +++ b/src/app/services/socket/rocket-chat-client.service.ts @@ -4,13 +4,16 @@ import { v4 as uuidv4 } from 'uuid' class _RocketChatClientService { connected = false - hasPing = false + private hasPing = false + private firstPingFunx: Function constructor() {} private returns() {} - connect(firstPing: Function) { + connect(firstPingFunx: Function) { + this.hasPing = false + this.firstPingFunx = firstPingFunx this.ws.connect('wss://gabinetedigitalchat.dyndns.info/websocket'); @@ -27,7 +30,7 @@ class _RocketChatClientService { this.ws.send({msg:"pong"}) if(this.hasPing == false) { // first ping - firstPing() + firstPingFunx() this.hasPing = true } } @@ -83,6 +86,11 @@ class _RocketChatClientService { deleteMessage() {} createRoom() {} + getRooms() { + + } + + subscribe() { var subscribeRequest = { "msg": "sub", @@ -168,11 +176,11 @@ class _RocketChatClientService { }, onclose:(event: any)=> { + + this.connect(this.firstPingFunx()) + this.connected = false console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`); - setTimeout(()=>{ - // this.connect(this.url) - }, 500) }, onerror: (event: any) => {