forked from Ivasoft/mattermost-mobile
Set 5s as default timeout for ping (#6271)
This commit is contained in:
@@ -35,7 +35,8 @@ async function getDeviceIdForPing(serverUrl: string, checkDeviceId: boolean) {
|
||||
return getDeviceToken(appDatabase);
|
||||
}
|
||||
|
||||
export const doPing = async (serverUrl: string, verifyPushProxy: boolean) => {
|
||||
// Default timeout interval for ping is 5 seconds
|
||||
export const doPing = async (serverUrl: string, verifyPushProxy: boolean, timeoutInterval = 5) => {
|
||||
let client: Client;
|
||||
try {
|
||||
client = await NetworkManager.createClient(serverUrl);
|
||||
@@ -57,7 +58,7 @@ export const doPing = async (serverUrl: string, verifyPushProxy: boolean) => {
|
||||
|
||||
let response: ClientResponse;
|
||||
try {
|
||||
response = await client.ping(deviceId);
|
||||
response = await client.ping(deviceId, timeoutInterval);
|
||||
|
||||
if (response.code === 401) {
|
||||
// Don't invalidate the client since we want to eventually
|
||||
|
||||
@@ -244,6 +244,10 @@ export default class ClientBase {
|
||||
retryLimit: 0,
|
||||
};
|
||||
}
|
||||
if (options.timeoutInterval) {
|
||||
requestOptions.timeoutInterval = options.timeoutInterval;
|
||||
}
|
||||
|
||||
let response: ClientResponse;
|
||||
try {
|
||||
response = await request!(url, requestOptions);
|
||||
|
||||
@@ -7,7 +7,7 @@ import ClientError from './error';
|
||||
|
||||
export interface ClientGeneralMix {
|
||||
getOpenGraphMetadata: (url: string) => Promise<any>;
|
||||
ping: (deviceId?: string) => Promise<any>;
|
||||
ping: (deviceId?: string, timeoutInterval?: number) => Promise<any>;
|
||||
logClientError: (message: string, level?: string) => Promise<any>;
|
||||
getClientConfigOld: () => Promise<ClientConfig>;
|
||||
getClientLicenseOld: () => Promise<ClientLicense>;
|
||||
@@ -25,14 +25,14 @@ const ClientGeneral = (superclass: any) => class extends superclass {
|
||||
);
|
||||
};
|
||||
|
||||
ping = async (deviceId?: string) => {
|
||||
ping = async (deviceId?: string, timeoutInterval?: number) => {
|
||||
let url = `${this.urlVersion}/system/ping?time=${Date.now()}`;
|
||||
if (deviceId) {
|
||||
url = `${url}&device_id=${deviceId}`;
|
||||
}
|
||||
return this.doFetch(
|
||||
url,
|
||||
{method: 'get'},
|
||||
{method: 'get', timeoutInterval},
|
||||
false,
|
||||
);
|
||||
};
|
||||
|
||||
1
types/api/client.d.ts
vendored
1
types/api/client.d.ts
vendored
@@ -7,6 +7,7 @@ type ClientOptions = {
|
||||
body?: any;
|
||||
method?: string;
|
||||
noRetry?: boolean;
|
||||
timeoutInterval?: number;
|
||||
};
|
||||
|
||||
interface ClientErrorProps extends Error {
|
||||
|
||||
Reference in New Issue
Block a user