Wait for VPN connection only when appconfig flag is set (#2627)
This commit is contained in:
parent
fbd5c34c5e
commit
cc3ce0e509
4 changed files with 48 additions and 6 deletions
|
|
@ -9,6 +9,7 @@ import {Client4} from 'mattermost-redux/client';
|
|||
import {ClientError} from 'mattermost-redux/client/client4';
|
||||
|
||||
import mattermostBucket from 'app/mattermost_bucket';
|
||||
import mattermostManaged from 'app/mattermost_managed';
|
||||
import LocalConfig from 'assets/config';
|
||||
|
||||
import {t} from 'app/utils/i18n';
|
||||
|
|
@ -18,6 +19,12 @@ import {t} from 'app/utils/i18n';
|
|||
const HEADER_X_CLUSTER_ID = 'X-Cluster-Id';
|
||||
const HEADER_TOKEN = 'Token';
|
||||
|
||||
let managedConfig;
|
||||
|
||||
mattermostManaged.addEventListener('fetch_managed_config', (config) => {
|
||||
managedConfig = config;
|
||||
});
|
||||
|
||||
const handleRedirectProtocol = (url, response) => {
|
||||
const serverUrl = Client4.getUrl();
|
||||
const parsed = urlParse(url);
|
||||
|
|
@ -39,12 +46,20 @@ Client4.doFetchWithResponse = async (url, options) => {
|
|||
|
||||
const customHeaders = LocalConfig.CustomRequestHeaders;
|
||||
let waitsForConnectivity = false;
|
||||
if (url.includes('/api/v4/system/ping')) {
|
||||
let timeoutIntervalForResource = 30;
|
||||
|
||||
if (managedConfig?.useVPN === 'true') {
|
||||
waitsForConnectivity = true;
|
||||
}
|
||||
|
||||
if (managedConfig?.timeoutVPN) {
|
||||
timeoutIntervalForResource = parseInt(managedConfig.timeoutVPN, 10);
|
||||
}
|
||||
|
||||
let requestOptions = {
|
||||
...Client4.getOptions(options),
|
||||
waitsForConnectivity,
|
||||
timeoutIntervalForResource,
|
||||
};
|
||||
|
||||
if (customHeaders && Object.keys(customHeaders).length > 0) {
|
||||
|
|
@ -129,6 +144,13 @@ Client4.doFetchWithResponse = async (url, options) => {
|
|||
|
||||
const initFetchConfig = async () => {
|
||||
let fetchConfig = {};
|
||||
|
||||
try {
|
||||
managedConfig = await mattermostManaged.getConfig();
|
||||
} catch {
|
||||
// no managed config
|
||||
}
|
||||
|
||||
if (Platform.OS === 'ios') {
|
||||
const certificate = await mattermostBucket.getPreference('cert');
|
||||
fetchConfig = {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@ import RNFetchBlob from 'rn-fetch-blob';
|
|||
import {Client4} from 'mattermost-redux/client';
|
||||
|
||||
import mattermostBucket from 'app/mattermost_bucket';
|
||||
import mattermostManaged from 'app/mattermost_managed';
|
||||
|
||||
let certificate = '';
|
||||
let previousState;
|
||||
export async function checkConnection(isConnected) {
|
||||
if (!isConnected || !Client4.getBaseRoute().startsWith('http')) {
|
||||
if (!Client4.getBaseRoute().startsWith('http')) {
|
||||
// If we don't have a connection or have a server yet, return the default implementation
|
||||
return {hasInternet: isConnected, serverReachable: false};
|
||||
}
|
||||
|
|
@ -20,9 +21,28 @@ export async function checkConnection(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()}`;
|
||||
|
||||
let managedConfig;
|
||||
let waitsForConnectivity = false;
|
||||
let timeoutIntervalForResource = 30;
|
||||
|
||||
try {
|
||||
managedConfig = await mattermostManaged.getConfig();
|
||||
} catch {
|
||||
// no managed config
|
||||
}
|
||||
|
||||
if (managedConfig?.useVPN === 'true') {
|
||||
waitsForConnectivity = true;
|
||||
}
|
||||
|
||||
if (managedConfig?.timeoutVPN) {
|
||||
timeoutIntervalForResource = parseInt(managedConfig.timeoutVPN, 10);
|
||||
}
|
||||
|
||||
const config = {
|
||||
auto: true,
|
||||
waitsForConnectivity: true,
|
||||
waitsForConnectivity,
|
||||
timeoutIntervalForResource,
|
||||
};
|
||||
|
||||
if (Platform.OS === 'ios' && certificate === '') {
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -13188,8 +13188,8 @@
|
|||
}
|
||||
},
|
||||
"rn-fetch-blob": {
|
||||
"version": "github:enahum/react-native-fetch-blob#e81b40d87e9e2ca39870d61a6e4c02b9a695aaad",
|
||||
"from": "github:enahum/react-native-fetch-blob#e81b40d87e9e2ca39870d61a6e4c02b9a695aaad",
|
||||
"version": "github:enahum/react-native-fetch-blob#5b19784992ef2a1fa00c3a4c71fb005d7789b05c",
|
||||
"from": "github:enahum/react-native-fetch-blob#5b19784992ef2a1fa00c3a4c71fb005d7789b05c",
|
||||
"requires": {
|
||||
"base-64": "0.1.0",
|
||||
"glob": "7.0.6"
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
"redux-persist-transform-filter": "0.0.18",
|
||||
"redux-thunk": "2.3.0",
|
||||
"reselect": "4.0.0",
|
||||
"rn-fetch-blob": "github:enahum/react-native-fetch-blob#e81b40d87e9e2ca39870d61a6e4c02b9a695aaad",
|
||||
"rn-fetch-blob": "github:enahum/react-native-fetch-blob#5b19784992ef2a1fa00c3a4c71fb005d7789b05c",
|
||||
"rn-placeholder": "github:enahum/rn-placeholder#bfee66eb54f1f06d1425a0ad511a5e16559bf82c",
|
||||
"semver": "5.6.0",
|
||||
"shallow-equals": "1.0.0",
|
||||
|
|
|
|||
Loading…
Reference in a new issue