Disable start/call button if offline

This commit is contained in:
Evan Hahn 2021-10-19 08:53:11 -05:00 committed by GitHub
parent f914556e4c
commit 75248d8e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import {
} from './CallingLobbyJoinButton';
import { AvatarColorType } from '../types/Colors';
import { LocalizerType } from '../types/Util';
import { useIsOnline } from '../hooks/useIsOnline';
import * as KeyboardLayout from '../services/keyboardLayout';
import { ConversationType } from '../state/ducks/conversations';
import { isConversationTooBigToRing } from '../conversations/isConversationTooBigToRing';
@ -139,6 +140,8 @@ export const CallingLobby = ({
};
}, [toggleVideo, toggleAudio]);
const isOnline = useIsOnline();
const [isCallConnecting, setIsCallConnecting] = React.useState(false);
// eslint-disable-next-line no-nested-ternary
@ -186,7 +189,7 @@ export const CallingLobby = ({
ringButtonType = CallingButtonType.RING_DISABLED;
}
const canJoin = !isCallFull && !isCallConnecting;
const canJoin = !isCallFull && !isCallConnecting && isOnline;
let callingLobbyJoinButtonVariant: CallingLobbyJoinButtonVariant;
if (isCallFull) {

26
ts/hooks/useIsOnline.ts Normal file
View File

@ -0,0 +1,26 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { useEffect, useState } from 'react';
export function useIsOnline(): boolean {
const [isOnline, setIsOnline] = useState(navigator.onLine);
useEffect(() => {
const update = () => {
setIsOnline(navigator.onLine);
};
update();
window.addEventListener('offline', update);
window.addEventListener('online', update);
return () => {
window.removeEventListener('offline', update);
window.removeEventListener('online', update);
};
}, []);
return isOnline;
}