React-native Long-polling or SignalR/websocket?

28 views Asked by At

I need help optimising one aspect from my app. I have placed in a context something like this:

useEffect(() => {
        let interval;
        if (user.certificate) {
            interval = setInterval(() => checkForConsents(), 5000)
        }
        return () => {
            clearInterval(interval)
        }
    }, [user.certificate])


 async function checkForConsents() {
        let dataToSend = await encryptJsonWithAES({
            Patid: user.patid.toString()
        }, user.s_aes, user.s_iv)
        let req = await CertRequesNoEnct(dataToSend, user.token, "", "", "/consent/check-consent-list", user.certificate)
        if (req) {
            let a2 = await decryptAESWithJson(req.replace("\"", ""), user.s_aes, user.s_iv)
            if (a2) {
                let a3 = await JSON.parse(a2)
                if (a3 && a3.length > 0) {
                    idconsent.current = a3[0].id
                    setModalCard(false)
                    setModalConsent(true)
                    return true
                } else {
                    idconsent.current = null
                    setModalConsent(false)
                }
            }
        }
        return false
    }

So a brief explanation is that we create a loop of async calls to the backend where if an event would be found, then it would overlap a certain screen above everything else, however…the phone is getting warm…really hot.

I thought then transitioning to a SignalR solution (since most of the backend is in C#) (although security is going to be a pain the ass) to improve this, but I am not sure if it is the right way.

Has anyone deal with projects where you need to for example verify the consent of the user or 2-way authentication where the app runs continuous checks on the backend?

0

There are 0 answers