-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMPROVEMENT] Change server while connecting/updating (#1981)
* [IMPROVEMENT] Change server while connecting * [FIX] Not login/reconnect to previous server * [FIX] Abort all fetch while connecting * [FIX] Abort sdk fetch * [FIX] Patch-package * Add comments Co-authored-by: Diego Mello <[email protected]>
- Loading branch information
1 parent
ee5b759
commit c578f1b
Showing
7 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
diff --git a/node_modules/@rocket.chat/sdk/lib/api/api.ts b/node_modules/@rocket.chat/sdk/lib/api/api.ts | ||
index 17c2c2b..cb094e8 100644 | ||
--- a/node_modules/@rocket.chat/sdk/lib/api/api.ts | ||
+++ b/node_modules/@rocket.chat/sdk/lib/api/api.ts | ||
@@ -117,24 +117,31 @@ class Client implements IClient { | ||
JSON.stringify(data) | ||
} | ||
|
||
+ getSignal (options?: any): AbortSignal { | ||
+ return options && options.signal; | ||
+ } | ||
+ | ||
get (url: string, data: any, options?: any): Promise<any> { | ||
return fetch(`${this.host}/api/v1/${encodeURI(url)}?${this.getParams(data)}`, { | ||
method: 'GET', | ||
- headers: this.getHeaders(options) | ||
+ headers: this.getHeaders(options), | ||
+ signal: this.getSignal(options) | ||
}).then(this.handle) | ||
} | ||
post (url: string, data: any, options?: any): Promise<any> { | ||
return fetch(`${this.host}/api/v1/${encodeURI(url)}`, { | ||
method: 'POST', | ||
body: this.getBody(data), | ||
- headers: this.getHeaders(options) | ||
+ headers: this.getHeaders(options), | ||
+ signal: this.getSignal(options) | ||
}).then(this.handle) | ||
} | ||
put (url: string, data: any, options?: any): Promise<any> { | ||
return fetch(`${this.host}/api/v1/${encodeURI(url)}`, { | ||
method: 'PUT', | ||
body: this.getBody(data), | ||
- headers: this.getHeaders(options) | ||
+ headers: this.getHeaders(options), | ||
+ signal: this.getSignal(options) | ||
}).then(this.handle) | ||
} | ||
|
||
@@ -142,7 +149,8 @@ class Client implements IClient { | ||
return fetch(`${this.host}/api/v1/${encodeURI(url)}`, { | ||
method: 'DELETE', | ||
body: this.getBody(data), | ||
- headers: this.getHeaders(options) | ||
+ headers: this.getHeaders(options), | ||
+ signal: this.getSignal(options) | ||
}).then(this.handle) | ||
} | ||
private async handle (r: any) { | ||
@@ -176,11 +184,13 @@ export default class Api extends EventEmitter { | ||
authToken: string, | ||
result: ILoginResultAPI | ||
} | null = null | ||
+ controller: AbortController | ||
|
||
constructor ({ client, host, logger = Logger }: any) { | ||
super() | ||
this.client = client || new Client({ host } as any) | ||
this.logger = Logger | ||
+ this.controller = new AbortController(); | ||
} | ||
|
||
get username () { | ||
@@ -212,6 +222,10 @@ export default class Api extends EventEmitter { | ||
if (auth && !this.loggedIn()) { | ||
throw new Error('') | ||
} | ||
+ | ||
+ const { signal } = this.controller; | ||
+ options = { ...options, signal }; | ||
+ | ||
let result | ||
switch (method) { | ||
case 'GET': result = await this.client.get(endpoint, data, options); break | ||
@@ -242,6 +256,8 @@ export default class Api extends EventEmitter { | ||
/** Do a DELETE request to an API endpoint. */ | ||
del: IAPIRequest = (endpoint, data, auth, ignore, options = {}) => this.request('DELETE', endpoint, data, auth, ignore, options) | ||
|
||
+ abort = (): void => this.controller.abort() | ||
+ | ||
/** Check result data for success, allowing override to ignore some errors */ | ||
success (result: any, ignore?: RegExp) { | ||
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10072,7 +10072,7 @@ react-native-scrollable-tab-view@^1.0.0: | |
prop-types "^15.6.0" | ||
react-timer-mixin "^0.13.3" | ||
|
||
react-native-slowlog@^1.0.2: | ||
[email protected]: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/react-native-slowlog/-/react-native-slowlog-1.0.2.tgz#5520979e3ef9d5273495d431ff3be34f02e35c89" | ||
integrity sha1-VSCXnj751Sc0ldQx/zvjTwLjXIk= | ||
|