From 20168d90cac6704b689bed40cb0e41d2e0e8cccf Mon Sep 17 00:00:00 2001 From: enahum Date: Mon, 13 Nov 2017 18:36:09 -0300 Subject: [PATCH] Network detection fixed to use default if no server is present (#1137) --- app/utils/network.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/utils/network.js b/app/utils/network.js index 09b852bb0..a84316450 100644 --- a/app/utils/network.js +++ b/app/utils/network.js @@ -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); }; }