Heartbeat de présence configurable dans la salle de conférence

This commit is contained in:
wpetit 2020-10-13 09:38:09 +02:00
parent 0b93b0875e
commit 50ec72fcf4
2 changed files with 4 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import React, { FunctionComponent, useEffect } from 'react'; import React, { FunctionComponent, useEffect } from 'react';
import { Config } from '../../config';
import { useUserProfile } from '../../gql/queries/profile'; import { useUserProfile } from '../../gql/queries/profile';
import { useConference } from '../../hooks/useConference'; import { useConference } from '../../hooks/useConference';
import { Page } from '../Page'; import { Page } from '../Page';
@ -13,8 +14,6 @@ const StatusThumbsUp = 'thumbs-up';
const StatusThumbsDown = 'thumbs-down'; const StatusThumbsDown = 'thumbs-down';
const StatusNoVote = 'no-vote'; const StatusNoVote = 'no-vote';
const HeartbeatInterval = 5000;
export const ConferencePage:FunctionComponent<ConferencePageProps> = () => { export const ConferencePage:FunctionComponent<ConferencePageProps> = () => {
const { user } = useUserProfile(); const { user } = useUserProfile();
const { uuid, data, setNickname, setEmail, ping, setStatus, forget } = useConference(); const { uuid, data, setNickname, setEmail, ping, setStatus, forget } = useConference();
@ -29,7 +28,7 @@ export const ConferencePage:FunctionComponent<ConferencePageProps> = () => {
useEffect(() => { useEffect(() => {
ping(); ping();
const intervalId = setInterval(() => ping(), HeartbeatInterval); const intervalId = setInterval(() => ping(), Config.conferenceHeartbeatInterval + (Math.random() * Config.conferenceHeartbeatInterval/2));
return () => clearInterval(intervalId); return () => clearInterval(intervalId);
}, []); }, []);
@ -89,7 +88,7 @@ export const ConferencePage:FunctionComponent<ConferencePageProps> = () => {
if (p === uuid) return null; if (p === uuid) return null;
if (now.getTime() > lastHeartBeat.getTime() + HeartbeatInterval) { if (now.getTime() > lastHeartBeat.getTime() + Config.conferenceHeartbeatInterval*2) {
forget(p); forget(p);
return null; return null;
} }

View File

@ -3,6 +3,7 @@ export const Config = {
logoutURL: get<string>("logoutURL", "http://localhost:8081/logout"), logoutURL: get<string>("logoutURL", "http://localhost:8081/logout"),
graphQLEndpoint: get<string>("graphQLEndpoint", "http://localhost:8081/api/v1/graphql"), graphQLEndpoint: get<string>("graphQLEndpoint", "http://localhost:8081/api/v1/graphql"),
subscriptionEndpoint: get<string>("subscriptionEndpoint", "ws://localhost:8081/api/v1/graphql"), subscriptionEndpoint: get<string>("subscriptionEndpoint", "ws://localhost:8081/api/v1/graphql"),
conferenceHeartbeatInterval: get<number>("conferenceHeartbeatInterval", 10000),
}; };
function get<T>(key: string, defaultValue: T):T { function get<T>(key: string, defaultValue: T):T {