diff --git a/src/lib/mtproto/apiManager.ts b/src/lib/mtproto/apiManager.ts index 0514b2d4..e2b272f1 100644 --- a/src/lib/mtproto/apiManager.ts +++ b/src/lib/mtproto/apiManager.ts @@ -273,13 +273,15 @@ export class ApiManager { } } - if(networker.isFileNetworker) { + if(transportType === 'websocket' && networker.isFileNetworker) { networker.onDrain = () => { - this.log('networker drain', networker); - + this.log('networker drain', networker.dcId); + networker.onDrain = undefined; const idx = networkers.indexOf(networker); networkers.splice(idx, 1); + networkerFactory.removeNetworker(networker); + networker.destroy(); }; } diff --git a/src/lib/mtproto/networker.ts b/src/lib/mtproto/networker.ts index 152818d4..e8e8425e 100644 --- a/src/lib/mtproto/networker.ts +++ b/src/lib/mtproto/networker.ts @@ -17,7 +17,7 @@ import Schema from './schema'; import timeManager from './timeManager'; import networkerFactory from './networkerFactory'; import { logger, LogTypes } from '../logger'; -import { assumeType, InvokeApiOptions } from '../../types'; +import { InvokeApiOptions } from '../../types'; import { longToBytes } from '../crypto/crypto_utils'; import MTTransport from './transports/transport'; import { convertToUint8Array, bufferConcat, bytesCmp, bytesToHex } from '../../helpers/bytes'; @@ -370,8 +370,8 @@ export default class MTPNetworker { } public destroy() { - assumeType(this.transport); - this.transport.destroy(); + //assumeType(this.transport); + (this.transport as TcpObfuscated).destroy(); } // private sendPingDelayDisconnect = () => { diff --git a/src/lib/mtproto/networkerFactory.ts b/src/lib/mtproto/networkerFactory.ts index 8c8a0c31..6ae005e8 100644 --- a/src/lib/mtproto/networkerFactory.ts +++ b/src/lib/mtproto/networkerFactory.ts @@ -23,6 +23,13 @@ export class NetworkerFactory { public akStopped = false; public userAgent = navigator.userAgent; + public removeNetworker(networker: MTPNetworker) { + const idx = this.networkers.indexOf(networker); + if(idx !== -1) { + this.networkers.splice(idx, 1); + } + } + public setUpdatesProcessor(callback: (obj: any) => void) { this.updatesProcessor = callback; } diff --git a/src/lib/mtproto/transports/websocket.ts b/src/lib/mtproto/transports/websocket.ts index aa7e2490..592e476b 100644 --- a/src/lib/mtproto/transports/websocket.ts +++ b/src/lib/mtproto/transports/websocket.ts @@ -56,7 +56,7 @@ export default class Socket extends EventListenerBase<{ return; } - this.log.error('close execution'); + this.log('close execution'); try { this.ws.close();