Skip to content

Commit

Permalink
HF 30 - Private groups - WebSocket ping
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Oct 1, 2024
1 parent 3d2a3de commit e1da085
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
15 changes: 14 additions & 1 deletion src/components/pages/Messages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { getRoleInGroup, opGroup } from 'app/utils/groups'
import { getProfileImage, } from 'app/utils/NormalizeProfile';
import { normalizeContacts, normalizeMessages } from 'app/utils/Normalizators';
import { fitToPreview } from 'app/utils/ImageUtils';
import { notificationSubscribe, notificationSubscribeWs,
import { notificationSubscribe, notificationSubscribeWs, notifyWsPing,
notificationShallowUnsubscribe, notificationTake, queueWatch, sendOffchainMessage } from 'app/utils/NotifyApiClient';
import { flash, unflash } from 'app/components/elements/messages/FlashTitle';
import { addShortcut } from 'app/utils/app/ShortcutUtils'
Expand Down Expand Up @@ -329,6 +329,19 @@ class Messages extends React.Component {
}, 5000)
return
}
const ping = async (firstCall = false) => {
if (!firstCall) {
try {
await notifyWsPing()
this.notifyErrorsClear()
} catch (err) {
console.error('Notify ping failed', err)
this.notifyErrorsInc(10)
}
}
setTimeout(ping, 10000)
}
ping(true)
}

componentDidMount() {
Expand Down
17 changes: 8 additions & 9 deletions src/utils/NotifyApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,10 @@ async function connectNotifyWs() {
notifyWs.addEventListener('open', () => {
notifyWs.isOpen = true
clearTimeout(timeout)
setInterval(() => {
console.log('NOTW', notifyWs.readyState)
//notifyWs.send('_heartbeat')
}, 1000)
resolve()
})

notifyWs.addEventListener('error', () => {
alert('NOTW close')
})

notifyWs.addEventListener('сlose', () => {
alert('NOTW close')
if (!notifyWs.isOpen) {
clearTimeout(timeout)
const err = new Error('notifyWs - cannot connect')
Expand Down Expand Up @@ -138,6 +129,14 @@ async function notifyWsSend(api, args, callback = null, eventCallback = null) {
}
}

export async function notifyWsPing() {
await connectNotifyWs()
if (!window.notifyWs || window.notifyWs.readyState !== 1) {
throw new Error('Ping detected what Notify WS not ready')
}
window.notifyWs.send('_heartbeat')
}

export function notifyApiLogin(account, authSession) {
if (!notifyAvailable()) return;
let request = Object.assign({}, request_base, {
Expand Down

0 comments on commit e1da085

Please sign in to comment.