Browse Source

Transport detection: close pending websockets

master
Eduard Kuzmenko 3 years ago
parent
commit
41c8024956
  1. 12
      src/lib/mtproto/transports/controller.ts

12
src/lib/mtproto/transports/controller.ts

@ -57,7 +57,17 @@ export class MTTransportController extends EventListenerBase<{ @@ -57,7 +57,17 @@ export class MTTransportController extends EventListenerBase<{
socket.setAutoReconnect(false);
socket.connection.addEventListener('close', () => websocketPromise.resolve(false), {once: true});
socket.connection.addEventListener('open', () => websocketPromise.resolve(true), {once: true});
setTimeout(() => websocketPromise.resolve(false), timeout);
setTimeout(() => {
if(websocketPromise.isFulfilled || websocketPromise.isRejected) {
return;
}
if(socket.connection) {
socket.connection.close();
}
websocketPromise.resolve(false);
}, timeout);
const [isHttpAvailable, isWebSocketAvailable] = await Promise.all([httpPromise, websocketPromise]);

Loading…
Cancel
Save