GramJs: Temporary workaround for logouts on launch, add WS logging (#1290)

This commit is contained in:
Alexander Zinchuk 2021-07-20 15:47:59 +03:00
parent 4e4299bf39
commit 9794b62ec8
4 changed files with 13 additions and 6 deletions

View File

@ -79,12 +79,15 @@ export async function init(_onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs)
initialMethod: platform === 'iOS' || platform === 'Android' ? 'phoneNumber' : 'qrCode',
});
} catch (err) {
onUpdate({
'@type': 'updateConnectionState',
connectionState: 'connectionStateBroken',
});
// TODO Investigate which request causes this exception
if (err.message !== 'Disconnect') {
onUpdate({
'@type': 'updateConnectionState',
connectionState: 'connectionStateBroken',
});
return;
return;
}
}
if (DEBUG) {

View File

@ -614,6 +614,7 @@ class TelegramClient {
* @param request
* @returns {Promise}
*/
async invoke(request) {
if (request.classType !== 'request') {
throw new Error('You can only invoke MTProtoRequests');

View File

@ -56,6 +56,7 @@ export async function checkAuthorization(client: TelegramClient) {
await client.invoke(new Api.updates.GetState());
return true;
} catch (e) {
if (e.message === 'Disconnect') throw e;
return false;
}
}

View File

@ -88,7 +88,9 @@ class PromisedWebSockets {
this.client.onerror = (error) => {
reject(error);
};
this.client.onclose = () => {
this.client.onclose = (event) => {
// eslint-disable-next-line no-console
console.error(`Socket closed with code: ${event.code}`);
this.resolveRead(false);
this.closed = true;
};