Network detection fixed to use default if no server is present (#1137)
This commit is contained in:
parent
f15223abfe
commit
20168d90ca
1 changed files with 9 additions and 4 deletions
|
|
@ -2,12 +2,17 @@ import {NetInfo} from 'react-native';
|
|||
|
||||
import {Client4} from 'mattermost-redux/client';
|
||||
|
||||
export async function checkConnection() {
|
||||
export async function checkConnection(isConnected) {
|
||||
if (Client4.getBaseRoute() === '/api/v4') {
|
||||
// If we don't have a server yet, return the default implementation
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
// Ping the Mattermost server to detect if the we have network connection even if the websocket cannot connect
|
||||
const server = `${Client4.getBaseRoute()}/system/ping?time=${Date.now()}`;
|
||||
|
||||
try {
|
||||
await fetch(server);
|
||||
await fetch(server, {method: 'get'});
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
|
|
@ -15,8 +20,8 @@ export async function checkConnection() {
|
|||
}
|
||||
|
||||
function handleConnectionChange(onChange) {
|
||||
return async () => {
|
||||
const result = await checkConnection();
|
||||
return async (isConnected) => {
|
||||
const result = await checkConnection(isConnected);
|
||||
onChange(result);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue