[Debug] Add test servers (#1513)
This commit is contained in:
parent
3b2149ea58
commit
7e8bf8addf
@ -45,7 +45,7 @@ export async function init(_onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs)
|
||||
onUpdate = _onUpdate;
|
||||
|
||||
const {
|
||||
userAgent, platform, sessionData, isMovSupported,
|
||||
userAgent, platform, sessionData, isTest, isMovSupported,
|
||||
} = initialArgs;
|
||||
const session = new sessions.CallbackSession(sessionData, onSessionUpdate);
|
||||
|
||||
@ -61,6 +61,7 @@ export async function init(_onUpdate: OnApiUpdate, initialArgs: ApiInitialArgs)
|
||||
appVersion: `${APP_VERSION} ${APP_CODE_NAME}`,
|
||||
useWSS: true,
|
||||
additionalDcsDisabled: IS_TEST,
|
||||
testServers: isTest,
|
||||
} as any,
|
||||
);
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ export interface ApiInitialArgs {
|
||||
userAgent: string;
|
||||
platform?: string;
|
||||
sessionData?: ApiSessionData;
|
||||
isTest?: boolean;
|
||||
isMovSupported?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@ -5,12 +5,6 @@ import usePrevious from './usePrevious';
|
||||
import { getDispatch } from '../lib/teact/teactn';
|
||||
import { areSortedArraysEqual } from '../util/iteratees';
|
||||
|
||||
// Carefully selected by swiping and observing visual changes
|
||||
// TODO: may be different on other devices such as iPad, maybe take dpi into account?
|
||||
const SAFARI_EDGE_BACK_GESTURE_LIMIT = 300;
|
||||
const SAFARI_EDGE_BACK_GESTURE_DURATION = 350;
|
||||
export const LOCATION_HASH = window.location.hash;
|
||||
|
||||
type HistoryState = {
|
||||
currentIndex: number;
|
||||
nextStateIndexToReplace: number;
|
||||
@ -20,6 +14,13 @@ type HistoryState = {
|
||||
currentIndexes: number[];
|
||||
};
|
||||
|
||||
// Carefully selected by swiping and observing visual changes
|
||||
// TODO: may be different on other devices such as iPad, maybe take dpi into account?
|
||||
const SAFARI_EDGE_BACK_GESTURE_LIMIT = 300;
|
||||
const SAFARI_EDGE_BACK_GESTURE_DURATION = 350;
|
||||
export const LOCATION_HASH = window.location.hash;
|
||||
const PATH_BASE = `${window.location.pathname}${window.location.search}`;
|
||||
|
||||
const historyState: HistoryState = {
|
||||
currentIndex: 0,
|
||||
nextStateIndexToReplace: -1,
|
||||
@ -55,7 +56,7 @@ if (IS_IOS) {
|
||||
window.addEventListener('popstate', handleTouchEnd);
|
||||
}
|
||||
|
||||
window.history.replaceState({ index: historyState.currentIndex }, '', window.location.pathname);
|
||||
window.history.replaceState({ index: historyState.currentIndex }, '', PATH_BASE);
|
||||
|
||||
export default function useHistoryBack(
|
||||
isActive: boolean | undefined,
|
||||
@ -87,14 +88,16 @@ export default function useHistoryBack(
|
||||
|
||||
historyState.currentIndexes.push(index);
|
||||
|
||||
window.history[
|
||||
(historyState.currentIndexes.includes(historyState.nextStateIndexToReplace - 1)
|
||||
window.history[(
|
||||
(
|
||||
historyState.currentIndexes.includes(historyState.nextStateIndexToReplace - 1)
|
||||
&& window.history.state.index !== 0
|
||||
&& historyState.nextStateIndexToReplace === index
|
||||
&& !shouldReplaceNext)
|
||||
&& !shouldReplaceNext
|
||||
)
|
||||
? 'replaceState'
|
||||
: 'pushState'
|
||||
]({
|
||||
)]({
|
||||
index,
|
||||
state: currentState,
|
||||
}, '');
|
||||
@ -170,7 +173,7 @@ export default function useHistoryBack(
|
||||
window.history.replaceState({
|
||||
index,
|
||||
state: currentState,
|
||||
}, '', `#${hashes[hashes.length - 1]}`);
|
||||
}, '', `${PATH_BASE}#${hashes[hashes.length - 1]}`);
|
||||
|
||||
indexHashRef.current[indexHashRef.current.length - 1] = {
|
||||
index,
|
||||
|
||||
@ -38,7 +38,6 @@ const PING_DISCONNECT_DELAY = 60000; // 1 min
|
||||
// All types
|
||||
const sizeTypes = ['w', 'y', 'd', 'x', 'c', 'm', 'b', 'a', 's'];
|
||||
|
||||
|
||||
class TelegramClient {
|
||||
static DEFAULT_OPTIONS = {
|
||||
connection: ConnectionTCPObfuscated,
|
||||
@ -59,6 +58,7 @@ class TelegramClient {
|
||||
baseLogger: 'gramjs',
|
||||
useWSS: false,
|
||||
additionalDcsDisabled: false,
|
||||
testServers: false,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -148,7 +148,6 @@ class TelegramClient {
|
||||
this._destroyed = false;
|
||||
}
|
||||
|
||||
|
||||
// region Connecting
|
||||
|
||||
/**
|
||||
@ -181,7 +180,7 @@ class TelegramClient {
|
||||
this._sender._disconnected = true;
|
||||
|
||||
const connection = new this._connection(
|
||||
this.session.serverAddress, this.session.port, this.session.dcId, this._log,
|
||||
this.session.serverAddress, this.session.port, this.session.dcId, this._log, this._args.testServers,
|
||||
);
|
||||
|
||||
const newConnection = await this._sender.connect(connection);
|
||||
@ -337,6 +336,7 @@ class TelegramClient {
|
||||
dc.port,
|
||||
dcId,
|
||||
this._log,
|
||||
this._args.testServers,
|
||||
));
|
||||
|
||||
if (this.session.dcId !== dcId && !sender._authenticated) {
|
||||
@ -551,7 +551,6 @@ class TelegramClient {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
_downloadCachedPhotoSize(size) {
|
||||
// No need to download anything, simply write the bytes
|
||||
let data;
|
||||
@ -688,7 +687,6 @@ class TelegramClient {
|
||||
// This causes issues for now because not enough utils
|
||||
// await request.resolve(this, utils)
|
||||
|
||||
|
||||
this._lastRequest = new Date().getTime();
|
||||
let attempt = 0;
|
||||
for (attempt = 0; attempt < this._requestRetries; attempt++) {
|
||||
@ -800,7 +798,6 @@ class TelegramClient {
|
||||
this._dispatchUpdate(args);
|
||||
}
|
||||
|
||||
|
||||
// endregion
|
||||
|
||||
// region private methods
|
||||
@ -883,7 +880,6 @@ class TelegramClient {
|
||||
*/
|
||||
// endregion
|
||||
|
||||
|
||||
// users region
|
||||
/**
|
||||
Turns the given entity into its input entity version.
|
||||
@ -1067,6 +1063,7 @@ async function attempts(cb, times, pause) {
|
||||
for (let i = 0; i < times; i++) {
|
||||
try {
|
||||
// We need to `return await` here so it can be caught locally
|
||||
// eslint-disable-next-line no-return-await
|
||||
return await cb();
|
||||
} catch (err) {
|
||||
if (i === times - 1) {
|
||||
|
||||
@ -20,6 +20,18 @@ const PUBLIC_KEYS = [
|
||||
),
|
||||
e: 65537,
|
||||
},
|
||||
{
|
||||
fingerprint: bigInt('-5595554452916591101'),
|
||||
n: bigInt(
|
||||
'2534288944884041556497168959071347320689884775908477905258202659454602246385394058588521595116849196570822' +
|
||||
'26493991806038180742006204637761354248846321625124031637930839216416315647409595294193595958529411668489405859523' +
|
||||
'37613333022396096584117954892216031229237302943701877588456738335398602461675225081791820393153757504952636234951' +
|
||||
'32323782003654358104782690612092797248736680529211579223142368426126233039432475078545094258975175539015664775146' +
|
||||
'07193514399690599495696153028090507215003302390050778898553239175099482557220816446894421272976054225797071426466' +
|
||||
'60768825302832201908302295573257427896031830742328565032949',
|
||||
),
|
||||
e: 65537,
|
||||
},
|
||||
];
|
||||
|
||||
export const _serverKeys = new Map<string, { n: bigInt.BigInteger; e: number }>();
|
||||
|
||||
@ -65,21 +65,21 @@ class PromisedWebSockets {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
getWebSocketLink(ip, port) {
|
||||
getWebSocketLink(ip, port, testServers) {
|
||||
if (port === 443) {
|
||||
return `wss://${ip}:${port}/apiws`;
|
||||
return `wss://${ip}:${port}/apiws${testServers ? '_test' : ''}`;
|
||||
} else {
|
||||
return `ws://${ip}:${port}/apiws`;
|
||||
return `ws://${ip}:${port}/apiws${testServers ? '_test' : ''}`;
|
||||
}
|
||||
}
|
||||
|
||||
connect(port, ip) {
|
||||
connect(port, ip, testServers = false) {
|
||||
this.stream = Buffer.alloc(0);
|
||||
this.canRead = new Promise((resolve) => {
|
||||
this.resolveRead = resolve;
|
||||
});
|
||||
this.closed = false;
|
||||
this.website = this.getWebSocketLink(ip, port);
|
||||
this.website = this.getWebSocketLink(ip, port, testServers);
|
||||
this.client = new WebSocketClient(this.website, 'binary');
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.onopen = () => {
|
||||
|
||||
@ -844,6 +844,7 @@ class MTProtoSender {
|
||||
this._connection._port,
|
||||
this._connection._dcId,
|
||||
this._connection._log,
|
||||
this._connection._testServers,
|
||||
);
|
||||
await this.connect(newConnection, true);
|
||||
|
||||
|
||||
@ -15,11 +15,12 @@ const AsyncQueue = require('../../extensions/AsyncQueue');
|
||||
class Connection {
|
||||
PacketCodecClass = undefined;
|
||||
|
||||
constructor(ip, port, dcId, loggers) {
|
||||
constructor(ip, port, dcId, loggers, testServers) {
|
||||
this._ip = ip;
|
||||
this._port = port;
|
||||
this._dcId = dcId;
|
||||
this._log = loggers;
|
||||
this._testServers = testServers;
|
||||
this._connected = false;
|
||||
this._sendTask = undefined;
|
||||
this._recvTask = undefined;
|
||||
@ -39,7 +40,7 @@ class Connection {
|
||||
async _connect() {
|
||||
this._log.debug('Connecting');
|
||||
this._codec = new this.PacketCodecClass(this);
|
||||
await this.socket.connect(this._port, this._ip, this);
|
||||
await this.socket.connect(this._port, this._ip, this._testServers);
|
||||
this._log.debug('Finished connecting');
|
||||
// await this.socket.connect({host: this._ip, port: this._port});
|
||||
await this._initConn();
|
||||
@ -152,7 +153,6 @@ class ObfuscatedConnection extends Connection {
|
||||
this._obfuscation.write(this._codec.encodePacket(data));
|
||||
}
|
||||
|
||||
|
||||
_recv() {
|
||||
return this._codec.readPacket(this._obfuscation);
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ addReducer('initApi', (global: GlobalState, actions) => {
|
||||
userAgent: navigator.userAgent,
|
||||
platform: PLATFORM_ENV,
|
||||
sessionData: loadStoredSession(),
|
||||
isTest: window.location.search.includes('test'),
|
||||
isMovSupported: IS_MOV_SUPPORTED,
|
||||
});
|
||||
})();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user