Browse Source

Release networker on drain

master
Eduard Kuzmenko 4 years ago
parent
commit
93cb272fde
  1. 8
      src/lib/mtproto/apiManager.ts
  2. 6
      src/lib/mtproto/networker.ts
  3. 7
      src/lib/mtproto/networkerFactory.ts
  4. 2
      src/lib/mtproto/transports/websocket.ts

8
src/lib/mtproto/apiManager.ts

@ -273,13 +273,15 @@ export class ApiManager { @@ -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();
};
}

6
src/lib/mtproto/networker.ts

@ -17,7 +17,7 @@ import Schema from './schema'; @@ -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 { @@ -370,8 +370,8 @@ export default class MTPNetworker {
}
public destroy() {
assumeType<TcpObfuscated>(this.transport);
this.transport.destroy();
//assumeType<TcpObfuscated>(this.transport);
(this.transport as TcpObfuscated).destroy();
}
// private sendPingDelayDisconnect = () => {

7
src/lib/mtproto/networkerFactory.ts

@ -23,6 +23,13 @@ export class NetworkerFactory { @@ -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;
}

2
src/lib/mtproto/transports/websocket.ts

@ -56,7 +56,7 @@ export default class Socket extends EventListenerBase<{ @@ -56,7 +56,7 @@ export default class Socket extends EventListenerBase<{
return;
}
this.log.error('close execution');
this.log('close execution');
try {
this.ws.close();

Loading…
Cancel
Save