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', initialMethod: platform === 'iOS' || platform === 'Android' ? 'phoneNumber' : 'qrCode',
}); });
} catch (err) { } catch (err) {
onUpdate({ // TODO Investigate which request causes this exception
'@type': 'updateConnectionState', if (err.message !== 'Disconnect') {
connectionState: 'connectionStateBroken', onUpdate({
}); '@type': 'updateConnectionState',
connectionState: 'connectionStateBroken',
});
return; return;
}
} }
if (DEBUG) { if (DEBUG) {

View File

@ -614,6 +614,7 @@ class TelegramClient {
* @param request * @param request
* @returns {Promise} * @returns {Promise}
*/ */
async invoke(request) { async invoke(request) {
if (request.classType !== 'request') { if (request.classType !== 'request') {
throw new Error('You can only invoke MTProtoRequests'); 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()); await client.invoke(new Api.updates.GetState());
return true; return true;
} catch (e) { } catch (e) {
if (e.message === 'Disconnect') throw e;
return false; return false;
} }
} }

View File

@ -88,7 +88,9 @@ class PromisedWebSockets {
this.client.onerror = (error) => { this.client.onerror = (error) => {
reject(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.resolveRead(false);
this.closed = true; this.closed = true;
}; };