From 5b9b877562657acb823c50c7b4bcf2d98126672e Mon Sep 17 00:00:00 2001 From: Gustavo Trott Date: Thu, 25 Jan 2024 18:17:16 -0300 Subject: [PATCH] Client test code for new rtt calc --- bbb-graphql-client-test/src/Auth.js | 8 +-- .../src/UserConnectionStatus.js | 67 ++++++++++++++----- .../src/UserConnectionStatusReport.js | 2 +- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/bbb-graphql-client-test/src/Auth.js b/bbb-graphql-client-test/src/Auth.js index e5099f15b1..0c730623fa 100644 --- a/bbb-graphql-client-test/src/Auth.js +++ b/bbb-graphql-client-test/src/Auth.js @@ -139,11 +139,11 @@ export default function Auth() { You are online, welcome {curr.name} ({curr.userId}) - {/**/} - {/*
*/} + +
- {/**/} - {/*
*/} + +
diff --git a/bbb-graphql-client-test/src/UserConnectionStatus.js b/bbb-graphql-client-test/src/UserConnectionStatus.js index a949891764..0d1b43b0a9 100644 --- a/bbb-graphql-client-test/src/UserConnectionStatus.js +++ b/bbb-graphql-client-test/src/UserConnectionStatus.js @@ -1,8 +1,10 @@ import {gql, useMutation, useSubscription} from '@apollo/client'; -import React, {useEffect} from "react"; +import React, {useEffect, useState, useRef } from "react"; import {applyPatch} from "fast-json-patch"; export default function UserConnectionStatus() { + const networkRttInMs = useRef(null); // Ref to store the current timeout + const lastStatusUpdatedAtReceived = useRef(null); // Ref to store the current timeout //example specifying where and time (new Date().toISOString()) //but its not necessary @@ -18,13 +20,20 @@ export default function UserConnectionStatus() { // `); + const timeoutRef = useRef(null); // Ref to store the current timeout + + + //where is not necessary once user can update only its own status //Hasura accepts "now()" as value to timestamp fields const [updateUserClientResponseAtToMeAsNow] = useMutation(gql` - mutation UpdateConnectionAliveAt($userId: String, $userClientResponseAt: timestamp) { + mutation UpdateConnectionClientResponse($networkRttInMs: numeric) { update_user_connectionStatus( where: {userClientResponseAt: {_is_null: true}} - _set: { userClientResponseAt: "now()" } + _set: { + userClientResponseAt: "now()", + networkRttInMs: $networkRttInMs + } ) { affected_rows } @@ -32,7 +41,11 @@ export default function UserConnectionStatus() { `); const handleUpdateUserClientResponseAt = () => { - updateUserClientResponseAtToMeAsNow(); + updateUserClientResponseAtToMeAsNow({ + variables: { + networkRttInMs: networkRttInMs.current + }, + }); }; @@ -48,11 +61,25 @@ export default function UserConnectionStatus() { `); const handleUpdateConnectionAliveAt = () => { - updateConnectionAliveAtToMeAsNow(); + const startTime = performance.now(); - setTimeout(() => { + try { + updateConnectionAliveAtToMeAsNow().then(result => { + const endTime = performance.now(); + networkRttInMs.current = endTime - startTime; + + }); + } catch (error) { + console.error('Error performing mutation:', error); + } + + if (timeoutRef.current) { + clearTimeout(timeoutRef.current); + } + + timeoutRef.current = setTimeout(() => { handleUpdateConnectionAliveAt(); - }, 25000); + }, 5000); }; useEffect(() => { @@ -66,7 +93,8 @@ export default function UserConnectionStatus() { user_connectionStatus { connectionAliveAt userClientResponseAt - rttInMs + applicationRttInMs + networkRttInMs status statusUpdatedAt } @@ -83,7 +111,8 @@ export default function UserConnectionStatus() { {/*Id*/} connectionAliveAt userClientResponseAt - rttInMs + applicationRttInMs + networkRttInMs status statusUpdatedAt @@ -92,12 +121,17 @@ export default function UserConnectionStatus() { {data.user_connectionStatus.map((curr) => { // console.log('user_connectionStatus', curr); - if(curr.userClientResponseAt == null) { - // handleUpdateUserClientResponseAt(); - const delay = 500; - setTimeout(() => { - handleUpdateUserClientResponseAt(); - },delay); + console.log('curr.statusUpdatedAt',curr.statusUpdatedAt); + console.log('lastStatusUpdatedAtReceived.current',lastStatusUpdatedAtReceived.current); + + if(curr.userClientResponseAt == null + && (curr.statusUpdatedAt == null || curr.statusUpdatedAt !== lastStatusUpdatedAtReceived.current)) { + + + + lastStatusUpdatedAtReceived.current = curr.statusUpdatedAt; + // setLastStatusUpdatedAtReceived(curr.statusUpdatedAt); + handleUpdateUserClientResponseAt(); } return ( @@ -106,7 +140,8 @@ export default function UserConnectionStatus() { {curr.userClientResponseAt} - {curr.rttInMs} + {curr.applicationRttInMs} + {curr.networkRttInMs} {curr.status} {curr.statusUpdatedAt} diff --git a/bbb-graphql-client-test/src/UserConnectionStatusReport.js b/bbb-graphql-client-test/src/UserConnectionStatusReport.js index 1b4157904c..b7bfbd0292 100644 --- a/bbb-graphql-client-test/src/UserConnectionStatusReport.js +++ b/bbb-graphql-client-test/src/UserConnectionStatusReport.js @@ -33,7 +33,7 @@ export default function UserConnectionStatusReport() { {data.user_connectionStatusReport.map((curr) => { - console.log('user_connectionStatusReport', curr); + //console.log('user_connectionStatusReport', curr); return ( {curr.user.name}