ifdef triple slash to double slash
This commit is contained in:
parent
a02387efa1
commit
6d18ef9d15
@ -415,7 +415,7 @@ export class AppMediaPlaybackController extends EventListenerBase<{
|
||||
* Only for audio
|
||||
*/
|
||||
public isSafariBuffering(media: HTMLMediaElement) {
|
||||
/// @ts-ignore
|
||||
// @ts-ignore
|
||||
return !!media.safariBuffering;
|
||||
}
|
||||
|
||||
|
@ -399,7 +399,7 @@ export default class PopupPayment extends PopupElement {
|
||||
|
||||
pricesElements.push(tipsLabel.label);
|
||||
|
||||
///
|
||||
//
|
||||
const tipsEl = document.createElement('div');
|
||||
tipsEl.classList.add(tipsClassName);
|
||||
|
||||
|
@ -21,20 +21,20 @@ const Modes = {
|
||||
transport: 'websocket' as TransportType
|
||||
};
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
Modes.http = location.search.indexOf('http=1') > 0;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
/// #if MTPROTO_HTTP || !MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HTTP || !MTPROTO_HAS_WS
|
||||
Modes.http = true;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
if(Modes.http) {
|
||||
Modes.transport = 'https';
|
||||
}
|
||||
|
||||
/// #if MTPROTO_SW
|
||||
// #if MTPROTO_SW
|
||||
Modes.asServiceWorker = true;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
export default Modes;
|
||||
|
@ -9,14 +9,14 @@
|
||||
* https://github.com/evgeny-nadymov/telegram-react/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/// NOTE: telegram returns sign source, while webrtc uses unsign source internally
|
||||
/// unsign => sign
|
||||
// NOTE: telegram returns sign source, while webrtc uses unsign source internally
|
||||
// unsign => sign
|
||||
export function toTelegramSource(source: number) {
|
||||
return source << 0;
|
||||
}
|
||||
|
||||
/// NOTE: telegram returns sign source, while webrtc uses unsign source internally
|
||||
/// sign => unsign
|
||||
// NOTE: telegram returns sign source, while webrtc uses unsign source internally
|
||||
// sign => unsign
|
||||
export function fromTelegramSource(source: number) {
|
||||
return source >>> 0;
|
||||
}
|
||||
|
@ -9,10 +9,10 @@
|
||||
* https://github.com/zhukov/webogram/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
import transportController from './transports/controller';
|
||||
import MTTransport from './transports/transport';
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
import type { UserAuth } from './mtproto_config';
|
||||
import sessionStorage from '../sessionStorage';
|
||||
@ -93,11 +93,11 @@ export class ApiManager extends ApiManagerMethods {
|
||||
|
||||
this.transportType = Modes.transport;
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
transportController.addEventListener('transport', (transportType) => {
|
||||
this.changeTransportType(transportType);
|
||||
});
|
||||
/// #endif
|
||||
// #endif
|
||||
}
|
||||
|
||||
protected after() {
|
||||
@ -148,14 +148,14 @@ export class ApiManager extends ApiManagerMethods {
|
||||
} */
|
||||
|
||||
private getTransportType(connectionType: ConnectionType) {
|
||||
/// #if MTPROTO_HTTP_UPLOAD
|
||||
// #if MTPROTO_HTTP_UPLOAD
|
||||
// @ts-ignore
|
||||
const transportType: TransportType = connectionType === 'upload' && getEnvironment().IS_SAFARI ? 'https' : 'websocket';
|
||||
//const transportType: TransportType = connectionType !== 'client' ? 'https' : 'websocket';
|
||||
/// #else
|
||||
// #else
|
||||
// @ts-ignore
|
||||
const transportType: TransportType = this.transportType;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
return transportType;
|
||||
}
|
||||
|
@ -9,9 +9,9 @@
|
||||
* https://github.com/zhukov/webogram/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
import transportController from "./transports/controller";
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
import { TLSerialization, TLDeserialization } from "./tl_utils";
|
||||
import { TransportType } from "./dcConfigurator";
|
||||
@ -114,9 +114,9 @@ export class Authorizer extends AppManager {
|
||||
|
||||
private transportType: TransportType;
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
private getTransportTypePromise: Promise<void>;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
protected after() {
|
||||
this.cached = {};
|
||||
@ -584,7 +584,7 @@ export class Authorizer extends AppManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
private getTransportType() {
|
||||
if(this.getTransportTypePromise) return this.getTransportTypePromise;
|
||||
return this.getTransportTypePromise = transportController.pingTransports().then(({websocket}) => {
|
||||
@ -592,7 +592,7 @@ export class Authorizer extends AppManager {
|
||||
this.log('will use transport:', this.transportType);
|
||||
});
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
public auth(dcId: DcId) {
|
||||
let promise = this.cached[dcId];
|
||||
@ -601,9 +601,9 @@ export class Authorizer extends AppManager {
|
||||
}
|
||||
|
||||
promise = new Promise(async(resolve, reject) => {
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
await this.getTransportType();
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
let error: ApiError;
|
||||
let _try = 1;
|
||||
|
@ -14,22 +14,22 @@ import Modes from '../../config/modes';
|
||||
import App from '../../config/app';
|
||||
import indexOfAndSplice from '../../helpers/array/indexOfAndSplice';
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
import HTTP from './transports/http';
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
import Socket from './transports/websocket';
|
||||
import TcpObfuscated from './transports/tcpObfuscated';
|
||||
import { IS_WEB_WORKER } from '../../helpers/context';
|
||||
import { DcId } from '../../types';
|
||||
import { getEnvironment } from '../../environment/utils';
|
||||
|
||||
/// #if !MTPROTO_SW && SAFARI_PROXY_WEBSOCKET
|
||||
// #if !MTPROTO_SW && SAFARI_PROXY_WEBSOCKET
|
||||
import SocketProxied from './transports/socketProxied';
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
export type TransportType = 'websocket' | 'https' | 'http';
|
||||
export type ConnectionType = 'client' | 'download' | 'upload';
|
||||
@ -48,7 +48,7 @@ export function getTelegramConnectionSuffix(connectionType: ConnectionType) {
|
||||
return connectionType === 'client' ? '' : '-1';
|
||||
}
|
||||
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
export function constructTelegramWebSocketUrl(dcId: DcId, connectionType: ConnectionType, premium?: boolean) {
|
||||
const suffix = getTelegramConnectionSuffix(connectionType);
|
||||
const path = connectionType !== 'client' ? 'apiws' + (premium ? PREMIUM_SUFFIX : TEST_SUFFIX) : ('apiws' + TEST_SUFFIX);
|
||||
@ -56,7 +56,7 @@ export function constructTelegramWebSocketUrl(dcId: DcId, connectionType: Connec
|
||||
|
||||
return chosenServer;
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
export class DcConfigurator {
|
||||
private sslSubdomains = ['pluto', 'venus', 'aurora', 'vesta', 'flora'];
|
||||
@ -77,7 +77,7 @@ export class DcConfigurator {
|
||||
|
||||
public chosenServers: Servers = {} as any;
|
||||
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
private transportSocket = (dcId: DcId, connectionType: ConnectionType, premium?: boolean) => {
|
||||
const chosenServer = constructTelegramWebSocketUrl(dcId, connectionType, premium);
|
||||
const logSuffix = connectionType === 'upload' ? '-U' : connectionType === 'download' ? '-D' : '';
|
||||
@ -85,17 +85,17 @@ export class DcConfigurator {
|
||||
const retryTimeout = connectionType === 'client' ? 10000 : 10000;
|
||||
|
||||
let oooohLetMeLive: MTConnectionConstructable;
|
||||
/// #if MTPROTO_SW || !SAFARI_PROXY_WEBSOCKET
|
||||
// #if MTPROTO_SW || !SAFARI_PROXY_WEBSOCKET
|
||||
oooohLetMeLive = Socket;
|
||||
/// #else
|
||||
// #else
|
||||
oooohLetMeLive = (getEnvironment().IS_SAFARI && IS_WEB_WORKER && typeof(SocketProxied) !== 'undefined') /* || true */ ? SocketProxied : Socket;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
return new TcpObfuscated(oooohLetMeLive, dcId, chosenServer, logSuffix, retryTimeout);
|
||||
};
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
private transportHTTP = (dcId: DcId, connectionType: ConnectionType, premium?: boolean) => {
|
||||
let chosenServer: string;
|
||||
if(Modes.ssl || !Modes.http) {
|
||||
@ -115,7 +115,7 @@ export class DcConfigurator {
|
||||
const logSuffix = connectionType === 'upload' ? '-U' : connectionType === 'download' ? '-D' : '';
|
||||
return new HTTP(dcId, chosenServer, logSuffix);
|
||||
};
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
public chooseServer(
|
||||
dcId: DcId,
|
||||
@ -147,13 +147,13 @@ export class DcConfigurator {
|
||||
if(!transports.length || !reuse/* || (upload && transports.length < 1) */) {
|
||||
let transport: MTTransport;
|
||||
|
||||
/// #if MTPROTO_HAS_WS && MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_WS && MTPROTO_HAS_HTTP
|
||||
transport = (transportType === 'websocket' ? this.transportSocket : this.transportHTTP)(dcId, connectionType, premium);
|
||||
/// #elif !MTPROTO_HTTP
|
||||
// #elif !MTPROTO_HTTP
|
||||
transport = this.transportSocket(dcId, connectionType, premium);
|
||||
/// #else
|
||||
// #else
|
||||
transport = this.transportHTTP(dcId, connectionType, premium);
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
if(!transport) {
|
||||
console.error('No chosenServer!', dcId);
|
||||
|
@ -74,9 +74,9 @@ class ApiManagerProxy extends MTProtoMessagePort {
|
||||
|
||||
this.log('constructor');
|
||||
|
||||
/// #if !MTPROTO_SW
|
||||
// #if !MTPROTO_SW
|
||||
this.registerWorker();
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
this.registerServiceWorker();
|
||||
this.registerCryptoWorker();
|
||||
@ -222,9 +222,9 @@ class ApiManagerProxy extends MTProtoMessagePort {
|
||||
const controller = navigator.serviceWorker.controller || registration.installing || registration.waiting || registration.active;
|
||||
this.attachServiceWorker(controller);
|
||||
|
||||
/// #if MTPROTO_SW
|
||||
// #if MTPROTO_SW
|
||||
this.onWorkerFirstMessage(controller);
|
||||
/// #endif
|
||||
// #endif
|
||||
}, (err) => {
|
||||
this.log.error('SW registration failed!', err);
|
||||
|
||||
@ -260,16 +260,16 @@ class ApiManagerProxy extends MTProtoMessagePort {
|
||||
});
|
||||
});
|
||||
|
||||
/// #if MTPROTO_SW
|
||||
// #if MTPROTO_SW
|
||||
this.attachListenPort(worker);
|
||||
/// #else
|
||||
// #else
|
||||
this.serviceMessagePort.attachListenPort(worker);
|
||||
this.serviceMessagePort.addMultipleEventsListeners({
|
||||
port: (payload, source, event) => {
|
||||
this.invokeVoid('serviceWorkerPort', undefined, undefined, [event.ports[0]]);
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
worker.addEventListener('messageerror', (e) => {
|
||||
this.log.error('SW messageerror:', e);
|
||||
@ -299,7 +299,7 @@ class ApiManagerProxy extends MTProtoMessagePort {
|
||||
this.attachWorkerToPort(worker, cryptoMessagePort, 'crypto');
|
||||
}
|
||||
|
||||
/// #if !MTPROTO_SW
|
||||
// #if !MTPROTO_SW
|
||||
private registerWorker() {
|
||||
// return;
|
||||
|
||||
@ -320,7 +320,7 @@ class ApiManagerProxy extends MTProtoMessagePort {
|
||||
|
||||
this.onWorkerFirstMessage(worker);
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
private attachWorkerToPort(worker: SharedWorker | Worker, messagePort: SuperMessagePort<any, any, any>, type: string) {
|
||||
const port: MessagePort = (worker as SharedWorker).port || worker as any;
|
||||
@ -335,11 +335,11 @@ class ApiManagerProxy extends MTProtoMessagePort {
|
||||
this.log('set webWorker');
|
||||
|
||||
// this.worker = worker;
|
||||
/// #if MTPROTO_SW
|
||||
// #if MTPROTO_SW
|
||||
this.attachSendPort(worker);
|
||||
/// #else
|
||||
// #else
|
||||
this.attachWorkerToPort(worker, this, 'mtproto');
|
||||
/// #endif
|
||||
// #endif
|
||||
}
|
||||
|
||||
private loadState() {
|
||||
@ -362,11 +362,11 @@ class ApiManagerProxy extends MTProtoMessagePort {
|
||||
});
|
||||
}
|
||||
|
||||
/// #if MTPROTO_WORKER
|
||||
// #if MTPROTO_WORKER
|
||||
public invokeCrypto<Method extends keyof CryptoMethods>(method: Method, ...args: Parameters<CryptoMethods[typeof method]>): Promise<Awaited<ReturnType<CryptoMethods[typeof method]>>> {
|
||||
return cryptoMessagePort.invokeCrypto(method, ...args);
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
public async toggleStorages(enabled: boolean, clearWrite: boolean) {
|
||||
await toggleStorages(enabled, clearWrite);
|
||||
|
@ -24,9 +24,9 @@ import DEBUG from '../../config/debug';
|
||||
import Modes from '../../config/modes';
|
||||
import noop from '../../helpers/noop';
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
import HTTP from './transports/http';
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
import type TcpObfuscated from './transports/tcpObfuscated';
|
||||
import bigInt from 'big-integer';
|
||||
@ -135,7 +135,7 @@ export default class MTPNetworker {
|
||||
private nextReqTimeout: number;
|
||||
private nextReq: number = 0;
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
private longPollInterval: number;
|
||||
private longPollPending: number;
|
||||
private checkConnectionRetryAt: number;
|
||||
@ -144,7 +144,7 @@ export default class MTPNetworker {
|
||||
private sleepAfter: number;
|
||||
private offline = false;
|
||||
private sendingLongPoll: boolean;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
private seqNo: number;
|
||||
private prevSessionId: Uint8Array;
|
||||
@ -173,13 +173,13 @@ export default class MTPNetworker {
|
||||
|
||||
public transport: MTTransport;
|
||||
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
private pingDelayDisconnectDeferred: CancellablePromise<string>;
|
||||
private pingPromise: Promise<void>;
|
||||
// private pingInterval: number;
|
||||
private lastPingTime: number;
|
||||
private lastPingDelayDisconnectId: string;
|
||||
/// #endif
|
||||
// #endif
|
||||
//public onConnectionStatusChange: (online: boolean) => void;
|
||||
|
||||
//private debugRequests: Array<{before: Uint8Array, after: Uint8Array}> = [];
|
||||
@ -413,19 +413,19 @@ export default class MTPNetworker {
|
||||
|
||||
this.connectionInited = false;
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
if(this.longPollInterval !== undefined) {
|
||||
clearInterval(this.longPollInterval);
|
||||
this.longPollInterval = undefined;
|
||||
}
|
||||
|
||||
this.clearCheckConnectionTimeout();
|
||||
/// #endif
|
||||
// #endif
|
||||
}
|
||||
|
||||
this.log('change transport', transport, oldTransport);
|
||||
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
this.clearPingDelayDisconnect();
|
||||
|
||||
// if(this.pingInterval !== undefined) {
|
||||
@ -434,7 +434,7 @@ export default class MTPNetworker {
|
||||
// }
|
||||
|
||||
// this.clearPing();
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
this.transport = transport;
|
||||
if(!transport) {
|
||||
@ -443,19 +443,19 @@ export default class MTPNetworker {
|
||||
|
||||
transport.networker = this;
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_WS
|
||||
if(transport instanceof HTTP) {
|
||||
/// #endif
|
||||
// #endif
|
||||
this.longPollInterval = ctx.setInterval(this.checkLongPoll, 10000);
|
||||
this.checkLongPoll();
|
||||
this.checkConnection('changed transport');
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
}
|
||||
/// #endif
|
||||
/// #endif
|
||||
// #endif
|
||||
// #endif
|
||||
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
// * handle outcoming dead socket, server will close the connection
|
||||
if((transport as TcpObfuscated).connection) {
|
||||
// this.sendPingDelayDisconnect();
|
||||
@ -467,7 +467,7 @@ export default class MTPNetworker {
|
||||
// this.pingInterval = ctx.setInterval(this.sendPing, PING_INTERVAL);
|
||||
// this.sendPing();
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
this.resend();
|
||||
}
|
||||
@ -612,7 +612,7 @@ export default class MTPNetworker {
|
||||
.finally(onFinally);
|
||||
};
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
private checkLongPoll = () => {
|
||||
const isClean = this.cleanupSent();
|
||||
//this.log.error('Check lp', this.longPollPending, this.dcId, isClean, this);
|
||||
@ -725,20 +725,20 @@ export default class MTPNetworker {
|
||||
this.checkConnectionTimeout = ctx.setTimeout(() => this.checkConnection('from toggleOfline'), delay);
|
||||
this.checkConnectionPeriod = Math.min(30, (1 + this.checkConnectionPeriod) * 1.5);
|
||||
|
||||
/// #if !MTPROTO_WORKER
|
||||
// #if !MTPROTO_WORKER
|
||||
document.body.addEventListener('online', this.checkConnection, false);
|
||||
document.body.addEventListener('focus', this.checkConnection, false);
|
||||
/// #endif
|
||||
// #endif
|
||||
} else {
|
||||
this.setConnectionStatus(ConnectionStatus.Connected);
|
||||
this.checkLongPoll();
|
||||
|
||||
this.scheduleRequest();
|
||||
|
||||
/// #if !MTPROTO_WORKER
|
||||
// #if !MTPROTO_WORKER
|
||||
document.body.removeEventListener('online', this.checkConnection);
|
||||
document.body.removeEventListener('focus', this.checkConnection);
|
||||
/// #endif
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -784,7 +784,7 @@ export default class MTPNetworker {
|
||||
});
|
||||
});
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
// тут можно сделать таймаут и выводить дисконнект
|
||||
private pushMessage(message: {
|
||||
@ -1029,10 +1029,10 @@ export default class MTPNetworker {
|
||||
//const currentTime = Date.now();
|
||||
let messagesByteLen = 0;
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
let hasApiCall = false;
|
||||
let hasHttpWait = false;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
let lengthOverflow = false;
|
||||
|
||||
@ -1062,13 +1062,13 @@ export default class MTPNetworker {
|
||||
messages.push(message);
|
||||
messagesByteLen += messageByteLength;
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
if(message.isAPI) {
|
||||
hasApiCall = true;
|
||||
} else if(message.longPoll) {
|
||||
hasHttpWait = true;
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
outMessage = message;
|
||||
} else {
|
||||
@ -1079,10 +1079,10 @@ export default class MTPNetworker {
|
||||
//}
|
||||
}
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_WS
|
||||
if(this.transport instanceof HTTP)
|
||||
/// #endif
|
||||
// #endif
|
||||
if(hasApiCall && !hasHttpWait) {
|
||||
const serializer = new TLSerialization({mtproto: true});
|
||||
serializer.storeMethod('http_wait', {
|
||||
@ -1097,16 +1097,16 @@ export default class MTPNetworker {
|
||||
body: serializer.getBytes(true)
|
||||
});
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
if(!messages.length) {
|
||||
// this.log('no scheduled messages')
|
||||
return;
|
||||
}
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
const noResponseMsgs: Array<string> = messages.filter((message) => message.noResponse).map((message) => message.msg_id);
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
if(messages.length > 1) {
|
||||
const container = this.generateContainerMessage(messagesByteLen, messages);
|
||||
@ -1121,19 +1121,19 @@ export default class MTPNetworker {
|
||||
|
||||
const promise = this.sendEncryptedRequest(outMessage);
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_WS
|
||||
if(this.transport instanceof HTTP)
|
||||
/// #endif
|
||||
// #endif
|
||||
this.handleSentEncryptedRequestHTTP(promise, outMessage, noResponseMsgs);
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
/// #if MTPROTO_HAS_WS
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
if(!(this.transport instanceof HTTP))
|
||||
/// #endif
|
||||
// #endif
|
||||
this.cleanupSent(); // ! WARNING
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
if(lengthOverflow) {
|
||||
this.scheduleRequest();
|
||||
@ -1302,13 +1302,13 @@ export default class MTPNetworker {
|
||||
const promise: Promise<Uint8Array> = this.transport ? this.transport.send(requestData) as any : Promise.reject({});
|
||||
// this.debug && this.log.debug('sendEncryptedRequest: launched message into space:', message, promise);
|
||||
|
||||
/// #if !MTPROTO_HAS_HTTP
|
||||
// #if !MTPROTO_HAS_HTTP
|
||||
return promise;
|
||||
/// #else
|
||||
// #else
|
||||
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
if(!(this.transport instanceof HTTP)) return promise;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
const baseError: ApiError = {
|
||||
code: 406,
|
||||
@ -1334,7 +1334,7 @@ export default class MTPNetworker {
|
||||
|
||||
throw error;
|
||||
});
|
||||
/// #endif
|
||||
// #endif
|
||||
}
|
||||
|
||||
public parseResponse(responseBuffer: Uint8Array) {
|
||||
@ -1475,19 +1475,19 @@ export default class MTPNetworker {
|
||||
return;
|
||||
} */
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_WS
|
||||
if(this.transport instanceof HTTP) {
|
||||
/// #endif
|
||||
// #endif
|
||||
if(this.offline) {
|
||||
this.checkConnection('forced schedule');
|
||||
}
|
||||
|
||||
delay ||= 0; // set zero timeout to pack other messages too
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_WS
|
||||
}
|
||||
/// #endif
|
||||
/// #endif
|
||||
// #endif
|
||||
// #endif
|
||||
|
||||
const nextReq = Date.now() + (delay || 0);
|
||||
if(this.nextReq && (delay === undefined || this.nextReq <= nextReq)) {
|
||||
@ -1512,15 +1512,15 @@ export default class MTPNetworker {
|
||||
this.nextReqTimeout = 0;
|
||||
this.nextReq = 0;
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_WS
|
||||
if(this.transport instanceof HTTP)
|
||||
/// #endif
|
||||
// #endif
|
||||
if(this.offline) {
|
||||
//this.log('Cancel scheduled');
|
||||
return;
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
this.performScheduledRequest();
|
||||
};
|
||||
@ -1540,12 +1540,12 @@ export default class MTPNetworker {
|
||||
|
||||
let delay: number;
|
||||
|
||||
/// #if MTPROTO_HAS_HTTP
|
||||
/// #if MTPROTO_HAS_WS
|
||||
// #if MTPROTO_HAS_HTTP
|
||||
// #if MTPROTO_HAS_WS
|
||||
if(this.transport instanceof HTTP)
|
||||
/// #endif
|
||||
// #endif
|
||||
delay = 30000;
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
this.scheduleRequest(delay);
|
||||
}
|
||||
|
@ -11,10 +11,10 @@ import type MTPNetworker from '../networker';
|
||||
import MTTransport from './transport';
|
||||
import Modes from '../../../config/modes';
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
import transportController from './controller';
|
||||
import networkStats from '../networkStats';
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
export default class HTTP implements MTTransport {
|
||||
public networker: MTPNetworker;
|
||||
@ -82,9 +82,9 @@ export default class HTTP implements MTTransport {
|
||||
|
||||
this.connected = connected;
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
transportController.setTransportValue('https', connected);
|
||||
/// #endif
|
||||
// #endif
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
@ -36,7 +36,7 @@ export interface SocketProxyCloseTask extends WorkerTaskVoidTemplate {
|
||||
id: number
|
||||
};
|
||||
|
||||
/// #if !MTPROTO_SW
|
||||
// #if !MTPROTO_SW
|
||||
export default class SocketProxied extends EventListenerBase<{
|
||||
open: () => void,
|
||||
message: (buffer: ArrayBuffer) => any,
|
||||
@ -92,4 +92,4 @@ export default class SocketProxied extends EventListenerBase<{
|
||||
}
|
||||
export const socketsProxied: Map<number, SocketProxied> = new Map();
|
||||
|
||||
/// #endif
|
||||
// #endif
|
||||
|
@ -14,12 +14,12 @@ import abridgedPacketCodec from './abridged';
|
||||
// import paddedIntermediatePacketCodec from './padded';
|
||||
import { ConnectionStatus } from "../connectionStatus";
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
import transportController from "./controller";
|
||||
import bytesToHex from "../../../helpers/bytes/bytesToHex";
|
||||
import networkStats from "../networkStats";
|
||||
import ctx from "../../../environment/ctx";
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
export default class TcpObfuscated implements MTTransport {
|
||||
private codec = abridgedPacketCodec;
|
||||
@ -64,9 +64,9 @@ export default class TcpObfuscated implements MTTransport {
|
||||
private onOpen = async() => {
|
||||
this.connected = true;
|
||||
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
transportController.setTransportOpened('websocket');
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
const initPayload = await this.obfuscation.init(this.codec);
|
||||
if(!this.connected) {
|
||||
@ -156,11 +156,11 @@ export default class TcpObfuscated implements MTTransport {
|
||||
};
|
||||
|
||||
public clear() {
|
||||
/// #if MTPROTO_AUTO
|
||||
// #if MTPROTO_AUTO
|
||||
if(this.connected) {
|
||||
transportController.setTransportClosed('websocket');
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
this.connected = false;
|
||||
|
||||
|
@ -4,9 +4,9 @@
|
||||
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/// #if MTPROTO_SW
|
||||
// #if MTPROTO_SW
|
||||
import '../mtproto/mtproto.worker';
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
import { logger, LogTypes } from '../logger';
|
||||
import { CACHE_ASSETS_NAME, requestCache } from './cache';
|
||||
@ -24,7 +24,7 @@ import makeError from '../../helpers/makeError';
|
||||
export const log = logger('SW', LogTypes.Error | LogTypes.Debug | LogTypes.Log | LogTypes.Warn);
|
||||
const ctx = self as any as ServiceWorkerGlobalScope;
|
||||
|
||||
/// #if !MTPROTO_SW
|
||||
// #if !MTPROTO_SW
|
||||
let _mtprotoMessagePort: MessagePort;
|
||||
export const getMtprotoMessagePort = () => _mtprotoMessagePort;
|
||||
|
||||
@ -191,10 +191,10 @@ listenMessagePort(serviceMessagePort, undefined, (source) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
const onFetch = (event: FetchEvent): void => {
|
||||
/// #if !DEBUG
|
||||
// #if !DEBUG
|
||||
if(
|
||||
!IS_SAFARI &&
|
||||
event.request.url.indexOf(location.origin + '/') === 0 &&
|
||||
@ -202,7 +202,7 @@ const onFetch = (event: FetchEvent): void => {
|
||||
) {
|
||||
return event.respondWith(requestCache(event));
|
||||
}
|
||||
/// #endif
|
||||
// #endif
|
||||
|
||||
try {
|
||||
const [, url, scope, params] = /http[:s]+\/\/.*?(\/(.*?)(?:$|\/(.*)$))/.exec(event.request.url) || [];
|
||||
|
@ -1,313 +1,313 @@
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const MediaQueryPlugin = require('media-query-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const postcssPresetEnv = require('postcss-preset-env');
|
||||
// const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
|
||||
const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin');
|
||||
const fs = require('fs');
|
||||
const Dotenv = require('dotenv-webpack');
|
||||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||
const keepAsset = require('./keepAsset');
|
||||
const HtmlWebpackInjectPreload = require('@principalstudio/html-webpack-inject-preload');
|
||||
|
||||
const allowedIPs = ['127.0.0.1'];
|
||||
const devMode = process.env.NODE_ENV !== 'production';
|
||||
const useLocal = true;
|
||||
const useLocalNotLocal = false;
|
||||
|
||||
if(devMode) {
|
||||
console.log('DEVMODE IS ON!');
|
||||
}
|
||||
|
||||
const MTPROTO_HTTP = false;
|
||||
const MTPROTO_AUTO = true;
|
||||
|
||||
const opts = {
|
||||
MTPROTO_WORKER: true,
|
||||
MTPROTO_SW: false,
|
||||
MTPROTO_HTTP: MTPROTO_HTTP,
|
||||
MTPROTO_HTTP_UPLOAD: false,
|
||||
MTPROTO_AUTO: MTPROTO_AUTO, // use HTTPS when WS is unavailable
|
||||
MTPROTO_HAS_HTTP: MTPROTO_AUTO || MTPROTO_HTTP,
|
||||
MTPROTO_HAS_WS: MTPROTO_AUTO || !MTPROTO_HTTP,
|
||||
SAFARI_PROXY_WEBSOCKET: false,
|
||||
DEBUG: devMode,
|
||||
|
||||
version: 3,
|
||||
'ifdef-verbose': devMode, // add this for verbose output
|
||||
'ifdef-triple-slash': true, // add this to use double slash comment instead of default triple slash
|
||||
'ifdef-fill-with-blanks': true // add this to remove code with blank spaces instead of "//" comments
|
||||
};
|
||||
|
||||
const domain = 'yourdomain.com';
|
||||
const localIp = '192.168.92.78';
|
||||
|
||||
const middleware = (req, res, next) => {
|
||||
let IP = '';
|
||||
if(req.headers['cf-connecting-ip']) {
|
||||
IP = req.headers['cf-connecting-ip'];
|
||||
} else {
|
||||
IP = req.connection.remoteAddress.split(':').pop();
|
||||
}
|
||||
|
||||
if(!allowedIPs.includes(IP) && !/^192\.168\.\d{1,3}\.\d{1,3}$/.test(IP)) {
|
||||
console.log('Bad IP connecting: ' + IP, req.url);
|
||||
res.status(404).send('Nothing interesting here.');
|
||||
} else {
|
||||
if(req.url.indexOf('/assets/') !== 0) {
|
||||
console.log(req.url, IP);
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,/* {
|
||||
loader: MiniCssExtractPlugin.loader,
|
||||
options: {
|
||||
hmr: devMode,
|
||||
reloadAll: true,
|
||||
}
|
||||
}, */
|
||||
|
||||
// Webpack 4
|
||||
// 'css-loader?url=false',
|
||||
// Webpack 5
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
url: false
|
||||
}
|
||||
},
|
||||
|
||||
devMode ? undefined : MediaQueryPlugin.loader,
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: {
|
||||
// Webpack 4
|
||||
// ident: 'postcss',
|
||||
// plugins: [
|
||||
// postcssPresetEnv(),
|
||||
// ],
|
||||
|
||||
// Webpack 5
|
||||
postcssOptions: {
|
||||
plugins: [
|
||||
postcssPresetEnv(),
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: 'sass-loader',
|
||||
options: {
|
||||
sourceMap: devMode
|
||||
}
|
||||
}
|
||||
].filter(Boolean)
|
||||
},
|
||||
// {
|
||||
// test: /\.worker\.ts$/i,
|
||||
// loader: "worker-loader",
|
||||
// // options: {
|
||||
// // filename: "[name].[contenthash].worker.js",
|
||||
// // }
|
||||
// },
|
||||
{
|
||||
test: /\.ts?$/,
|
||||
use: [
|
||||
//{ loader: 'babel-loader', options: require('./babel.config') },
|
||||
'ts-loader',
|
||||
{loader: 'ifdef-loader', options: opts}
|
||||
],
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
{
|
||||
test: /\.hbs$/,
|
||||
loader: 'handlebars-loader',
|
||||
options: {
|
||||
helperDirs: __dirname + '/handlebarsHelpers'
|
||||
}
|
||||
// loader: 'handlebars-loader?helperDirs[]=' + __dirname + '/handlebarsHelpers',
|
||||
// use: [
|
||||
// 'handlebars-loader'
|
||||
// ]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js'],
|
||||
},
|
||||
|
||||
entry: './src/index.ts',
|
||||
// entry: {
|
||||
// index: './src/index.ts',
|
||||
// // sw: {import: './src/lib/serviceWorker/index.service.ts', filename: 'sw.js'}
|
||||
// },
|
||||
/* entry: {
|
||||
index: './src/index.ts',
|
||||
pluralPolyfill: './src/lib/pluralPolyfill.ts'
|
||||
}, */
|
||||
//devtool: 'inline-source-map',
|
||||
|
||||
output: {
|
||||
globalObject: 'this',
|
||||
path: path.resolve(__dirname, 'public'),
|
||||
filename: devMode ? '[name].bundle.js' : '[name].[chunkhash].bundle.js',
|
||||
chunkFilename: devMode ? '[name].chunk.js' : '[name].[chunkhash].chunk.js',
|
||||
|
||||
// Webpack 5
|
||||
clean: {
|
||||
keep: keepAsset,
|
||||
}
|
||||
},
|
||||
|
||||
devServer: {
|
||||
// Webpack 4 options
|
||||
// contentBase: path.join(__dirname, 'public'),
|
||||
// watchContentBase: true,
|
||||
// before: useLocal ? undefined : function(app, server, compiler) {
|
||||
// app.use(middleware);
|
||||
// },
|
||||
// public: useLocal ? undefined : domain,
|
||||
// sockHost: useLocal ? undefined : domain,
|
||||
// overlay: true,
|
||||
|
||||
// static: {
|
||||
// directory: path.join(__dirname, 'public')
|
||||
// },
|
||||
compress: true,
|
||||
http2: useLocalNotLocal ? true : (useLocal ? undefined : true),
|
||||
https: useLocal ? undefined : {
|
||||
key: fs.readFileSync(__dirname + '/certs/server-key.pem', 'utf8'),
|
||||
cert: fs.readFileSync(__dirname + '/certs/server-cert.pem', 'utf8')
|
||||
},
|
||||
allowedHosts: useLocal ? undefined : [
|
||||
domain
|
||||
],
|
||||
host: useLocalNotLocal ? localIp : (useLocal ? undefined : '0.0.0.0'),
|
||||
//host: domain, // '0.0.0.0'
|
||||
port: useLocal ? undefined : 443,
|
||||
|
||||
|
||||
// Webpack 5
|
||||
hot: false,
|
||||
setupMiddlewares: useLocal ? undefined : (middlewares, devServer) => {
|
||||
middlewares.push(middleware);
|
||||
|
||||
return middlewares;
|
||||
},
|
||||
client: {
|
||||
overlay: true,
|
||||
progress: false
|
||||
},
|
||||
},
|
||||
|
||||
plugins: [
|
||||
devMode ? undefined : new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: false,
|
||||
defaultSizes: 'gzip'
|
||||
}),
|
||||
|
||||
new Dotenv(),
|
||||
|
||||
// new ServiceWorkerWebpackPlugin({
|
||||
// entry: path.join(__dirname, 'src/lib/serviceWorker/index.service.ts'),
|
||||
// filename: 'sw.js',
|
||||
// //excludes: ['**/*'],
|
||||
// includes: [
|
||||
// '**/*.js',
|
||||
// '**/*.css',
|
||||
// '**/*.json',
|
||||
// '**/*.wasm',
|
||||
// '**/*.mp3',
|
||||
// '**/*.svg',
|
||||
// '**/*.tgs',
|
||||
// '**/*.ico',
|
||||
// '**/*.woff',
|
||||
// '**/*.woff2',
|
||||
// '**/*.ttf',
|
||||
// '**/*.webmanifest'
|
||||
// ],
|
||||
// }),
|
||||
|
||||
new HtmlWebpackPlugin({
|
||||
title: 'Telegram Web',
|
||||
description: 'Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.',
|
||||
url: 'https://web.telegram.org/k/',
|
||||
filename: 'index.html',
|
||||
//template: 'public/index_template.html',
|
||||
template: 'src/index.hbs',
|
||||
inject: 'body', // true, 'head'
|
||||
scriptLoading: 'blocking',
|
||||
minify: devMode ? false : {
|
||||
removeComments: true,
|
||||
collapseWhitespace: true,
|
||||
removeRedundantAttributes: true,
|
||||
useShortDoctype: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
keepClosingSlash: true,
|
||||
minifyJS: true,
|
||||
minifyCSS: true,
|
||||
minifyURLs: true
|
||||
},
|
||||
chunks: 'all',
|
||||
excludeChunks: [],
|
||||
}),
|
||||
|
||||
new HtmlWebpackInjectPreload({
|
||||
files: [
|
||||
{
|
||||
match: /(mtproto).*\.js$/,
|
||||
attributes: {rel: 'modulepreload'},
|
||||
},
|
||||
]
|
||||
}),
|
||||
|
||||
new MiniCssExtractPlugin({
|
||||
// Options similar to the same options in webpackOptions.output
|
||||
// both options are optional
|
||||
filename: '[name].[contenthash].css',
|
||||
chunkFilename: '[id].[contenthash].css',
|
||||
}),
|
||||
|
||||
new MediaQueryPlugin({
|
||||
include: [
|
||||
'style'
|
||||
],
|
||||
queries: {
|
||||
'only screen and (max-width: 720px)': 'mobile',
|
||||
'only screen and (min-width: 721px)': 'desktop',
|
||||
}
|
||||
}),
|
||||
|
||||
new RetryChunkLoadPlugin({
|
||||
// optional stringified function to get the cache busting query string appended to the script src
|
||||
// if not set will default to appending the string `?cache-bust=true`
|
||||
cacheBust: `function() {
|
||||
return Date.now();
|
||||
}`,
|
||||
// optional value to set the amount of time in milliseconds before trying to load the chunk again. Default is 0
|
||||
retryDelay: 3000,
|
||||
// optional value to set the maximum number of retries to load the chunk. Default is 1
|
||||
maxRetries: 999999,
|
||||
// optional list of chunks to which retry script should be injected
|
||||
// if not set will add retry script to all chunks that have webpack script loading
|
||||
//chunks: ['chunkName'],
|
||||
// optional code to be executed in the browser context if after all retries chunk is not loaded.
|
||||
// if not set - nothing will happen and error will be returned to the chunk loader.
|
||||
//lastResortScript: "window.location.href='/500.html';",
|
||||
}),
|
||||
].filter(Boolean),
|
||||
};
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const MediaQueryPlugin = require('media-query-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const postcssPresetEnv = require('postcss-preset-env');
|
||||
// const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
|
||||
const {RetryChunkLoadPlugin} = require('webpack-retry-chunk-load-plugin');
|
||||
const fs = require('fs');
|
||||
const Dotenv = require('dotenv-webpack');
|
||||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||
const keepAsset = require('./keepAsset');
|
||||
const HtmlWebpackInjectPreload = require('@principalstudio/html-webpack-inject-preload');
|
||||
|
||||
const allowedIPs = ['127.0.0.1'];
|
||||
const devMode = process.env.NODE_ENV !== 'production';
|
||||
const useLocal = true;
|
||||
const useLocalNotLocal = false;
|
||||
|
||||
if(devMode) {
|
||||
console.log('DEVMODE IS ON!');
|
||||
}
|
||||
|
||||
const MTPROTO_HTTP = false;
|
||||
const MTPROTO_AUTO = true;
|
||||
|
||||
const opts = {
|
||||
'MTPROTO_WORKER': true,
|
||||
'MTPROTO_SW': false,
|
||||
'MTPROTO_HTTP': MTPROTO_HTTP,
|
||||
'MTPROTO_HTTP_UPLOAD': false,
|
||||
'MTPROTO_AUTO': MTPROTO_AUTO, // use HTTPS when WS is unavailable
|
||||
'MTPROTO_HAS_HTTP': MTPROTO_AUTO || MTPROTO_HTTP,
|
||||
'MTPROTO_HAS_WS': MTPROTO_AUTO || !MTPROTO_HTTP,
|
||||
'SAFARI_PROXY_WEBSOCKET': false,
|
||||
'DEBUG': devMode,
|
||||
|
||||
'version': 3,
|
||||
'ifdef-verbose': devMode, // add this for verbose output
|
||||
'ifdef-triple-slash': false, // add this to use double slash comment instead of default triple slash
|
||||
'ifdef-fill-with-blanks': true, // add this to remove code with blank spaces instead of "//" comments
|
||||
};
|
||||
|
||||
const domain = 'yourdomain.com';
|
||||
const localIp = '192.168.92.78';
|
||||
|
||||
const middleware = (req, res, next) => {
|
||||
let IP = '';
|
||||
if (req.headers['cf-connecting-ip']) {
|
||||
IP = req.headers['cf-connecting-ip'];
|
||||
} else {
|
||||
IP = req.connection.remoteAddress.split(':').pop();
|
||||
}
|
||||
|
||||
if (!allowedIPs.includes(IP) && !/^192\.168\.\d{1,3}\.\d{1,3}$/.test(IP)) {
|
||||
console.log('Bad IP connecting: ' + IP, req.url);
|
||||
res.status(404).send('Nothing interesting here.');
|
||||
} else {
|
||||
if (req.url.indexOf('/assets/') !== 0) {
|
||||
console.log(req.url, IP);
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.scss$/,
|
||||
use: [
|
||||
devMode ? 'style-loader' : MiniCssExtractPlugin.loader, /* {
|
||||
loader: MiniCssExtractPlugin.loader,
|
||||
options: {
|
||||
hmr: devMode,
|
||||
reloadAll: true,
|
||||
}
|
||||
}, */
|
||||
|
||||
// Webpack 4
|
||||
// 'css-loader?url=false',
|
||||
// Webpack 5
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
url: false,
|
||||
},
|
||||
},
|
||||
|
||||
devMode ? undefined : MediaQueryPlugin.loader,
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: {
|
||||
// Webpack 4
|
||||
// ident: 'postcss',
|
||||
// plugins: [
|
||||
// postcssPresetEnv(),
|
||||
// ],
|
||||
|
||||
// Webpack 5
|
||||
postcssOptions: {
|
||||
plugins: [
|
||||
postcssPresetEnv(),
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: 'sass-loader',
|
||||
options: {
|
||||
sourceMap: devMode,
|
||||
},
|
||||
},
|
||||
].filter(Boolean),
|
||||
},
|
||||
// {
|
||||
// test: /\.worker\.ts$/i,
|
||||
// loader: "worker-loader",
|
||||
// // options: {
|
||||
// // filename: "[name].[contenthash].worker.js",
|
||||
// // }
|
||||
// },
|
||||
{
|
||||
test: /\.ts?$/,
|
||||
use: [
|
||||
// { loader: 'babel-loader', options: require('./babel.config') },
|
||||
'ts-loader',
|
||||
{loader: 'ifdef-loader', options: opts},
|
||||
],
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
{
|
||||
test: /\.hbs$/,
|
||||
loader: 'handlebars-loader',
|
||||
options: {
|
||||
helperDirs: __dirname + '/handlebarsHelpers',
|
||||
},
|
||||
// loader: 'handlebars-loader?helperDirs[]=' + __dirname + '/handlebarsHelpers',
|
||||
// use: [
|
||||
// 'handlebars-loader'
|
||||
// ]
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js'],
|
||||
},
|
||||
|
||||
entry: './src/index.ts',
|
||||
// entry: {
|
||||
// index: './src/index.ts',
|
||||
// // sw: {import: './src/lib/serviceWorker/index.service.ts', filename: 'sw.js'}
|
||||
// },
|
||||
/* entry: {
|
||||
index: './src/index.ts',
|
||||
pluralPolyfill: './src/lib/pluralPolyfill.ts'
|
||||
}, */
|
||||
// devtool: 'inline-source-map',
|
||||
|
||||
output: {
|
||||
globalObject: 'this',
|
||||
path: path.resolve(__dirname, 'public'),
|
||||
filename: devMode ? '[name].bundle.js' : '[name].[chunkhash].bundle.js',
|
||||
chunkFilename: devMode ? '[name].chunk.js' : '[name].[chunkhash].chunk.js',
|
||||
|
||||
// Webpack 5
|
||||
clean: {
|
||||
keep: keepAsset,
|
||||
},
|
||||
},
|
||||
|
||||
devServer: {
|
||||
// Webpack 4 options
|
||||
// contentBase: path.join(__dirname, 'public'),
|
||||
// watchContentBase: true,
|
||||
// before: useLocal ? undefined : function(app, server, compiler) {
|
||||
// app.use(middleware);
|
||||
// },
|
||||
// public: useLocal ? undefined : domain,
|
||||
// sockHost: useLocal ? undefined : domain,
|
||||
// overlay: true,
|
||||
|
||||
// static: {
|
||||
// directory: path.join(__dirname, 'public')
|
||||
// },
|
||||
compress: true,
|
||||
http2: useLocalNotLocal ? true : (useLocal ? undefined : true),
|
||||
https: useLocal ? undefined : {
|
||||
key: fs.readFileSync(__dirname + '/certs/server-key.pem', 'utf8'),
|
||||
cert: fs.readFileSync(__dirname + '/certs/server-cert.pem', 'utf8'),
|
||||
},
|
||||
allowedHosts: useLocal ? undefined : [
|
||||
domain,
|
||||
],
|
||||
host: useLocalNotLocal ? localIp : (useLocal ? undefined : '0.0.0.0'),
|
||||
// host: domain, // '0.0.0.0'
|
||||
port: useLocal ? undefined : 443,
|
||||
|
||||
|
||||
// Webpack 5
|
||||
hot: false,
|
||||
setupMiddlewares: useLocal ? undefined : (middlewares, devServer) => {
|
||||
middlewares.push(middleware);
|
||||
|
||||
return middlewares;
|
||||
},
|
||||
client: {
|
||||
overlay: true,
|
||||
progress: false,
|
||||
},
|
||||
},
|
||||
|
||||
plugins: [
|
||||
devMode ? undefined : new BundleAnalyzerPlugin({
|
||||
analyzerMode: 'static',
|
||||
openAnalyzer: false,
|
||||
generateStatsFile: false,
|
||||
defaultSizes: 'gzip',
|
||||
}),
|
||||
|
||||
new Dotenv(),
|
||||
|
||||
// new ServiceWorkerWebpackPlugin({
|
||||
// entry: path.join(__dirname, 'src/lib/serviceWorker/index.service.ts'),
|
||||
// filename: 'sw.js',
|
||||
// //excludes: ['**/*'],
|
||||
// includes: [
|
||||
// '**/*.js',
|
||||
// '**/*.css',
|
||||
// '**/*.json',
|
||||
// '**/*.wasm',
|
||||
// '**/*.mp3',
|
||||
// '**/*.svg',
|
||||
// '**/*.tgs',
|
||||
// '**/*.ico',
|
||||
// '**/*.woff',
|
||||
// '**/*.woff2',
|
||||
// '**/*.ttf',
|
||||
// '**/*.webmanifest'
|
||||
// ],
|
||||
// }),
|
||||
|
||||
new HtmlWebpackPlugin({
|
||||
title: 'Telegram Web',
|
||||
description: 'Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.',
|
||||
url: 'https://web.telegram.org/k/',
|
||||
filename: 'index.html',
|
||||
// template: 'public/index_template.html',
|
||||
template: 'src/index.hbs',
|
||||
inject: 'body', // true, 'head'
|
||||
scriptLoading: 'blocking',
|
||||
minify: devMode ? false : {
|
||||
removeComments: true,
|
||||
collapseWhitespace: true,
|
||||
removeRedundantAttributes: true,
|
||||
useShortDoctype: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
keepClosingSlash: true,
|
||||
minifyJS: true,
|
||||
minifyCSS: true,
|
||||
minifyURLs: true,
|
||||
},
|
||||
chunks: 'all',
|
||||
excludeChunks: [],
|
||||
}),
|
||||
|
||||
new HtmlWebpackInjectPreload({
|
||||
files: [
|
||||
{
|
||||
match: /(mtproto).*\.js$/,
|
||||
attributes: {rel: 'modulepreload'},
|
||||
},
|
||||
],
|
||||
}),
|
||||
|
||||
new MiniCssExtractPlugin({
|
||||
// Options similar to the same options in webpackOptions.output
|
||||
// both options are optional
|
||||
filename: '[name].[contenthash].css',
|
||||
chunkFilename: '[id].[contenthash].css',
|
||||
}),
|
||||
|
||||
new MediaQueryPlugin({
|
||||
include: [
|
||||
'style',
|
||||
],
|
||||
queries: {
|
||||
'only screen and (max-width: 720px)': 'mobile',
|
||||
'only screen and (min-width: 721px)': 'desktop',
|
||||
},
|
||||
}),
|
||||
|
||||
new RetryChunkLoadPlugin({
|
||||
// optional stringified function to get the cache busting query string appended to the script src
|
||||
// if not set will default to appending the string `?cache-bust=true`
|
||||
cacheBust: `function() {
|
||||
return Date.now();
|
||||
}`,
|
||||
// optional value to set the amount of time in milliseconds before trying to load the chunk again. Default is 0
|
||||
retryDelay: 3000,
|
||||
// optional value to set the maximum number of retries to load the chunk. Default is 1
|
||||
maxRetries: 999999,
|
||||
// optional list of chunks to which retry script should be injected
|
||||
// if not set will add retry script to all chunks that have webpack script loading
|
||||
// chunks: ['chunkName'],
|
||||
// optional code to be executed in the browser context if after all retries chunk is not loaded.
|
||||
// if not set - nothing will happen and error will be returned to the chunk loader.
|
||||
// lastResortScript: "window.location.href='/500.html';",
|
||||
}),
|
||||
].filter(Boolean),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user