Calls: Fix leaving on page unload (#4248)
This commit is contained in:
parent
588c7a95b5
commit
96c87c9755
@ -176,7 +176,7 @@ function onUpdate(update: ApiUpdate) {
|
|||||||
sendUpdatesOnTickEnd();
|
sendUpdatesOnTickEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendToOrigin(data: WorkerMessageData, arrayBuffer?: ArrayBuffer) {
|
function sendToOrigin(data: WorkerMessageData, arrayBuffer?: ArrayBuffer) {
|
||||||
if (arrayBuffer) {
|
if (arrayBuffer) {
|
||||||
postMessage(data, [arrayBuffer]);
|
postMessage(data, [arrayBuffer]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -41,7 +41,7 @@ class HttpStream {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
getURL(ip: string, port: number, testServers: boolean, isPremium: boolean) {
|
static getURL(ip: string, port: number, testServers: boolean, isPremium: boolean) {
|
||||||
if (port === 443) {
|
if (port === 443) {
|
||||||
return `https://${ip}:${port}/apiw1${testServers ? '_test' : ''}${isPremium ? '_premium' : ''}`;
|
return `https://${ip}:${port}/apiw1${testServers ? '_test' : ''}${isPremium ? '_premium' : ''}`;
|
||||||
} else {
|
} else {
|
||||||
@ -55,7 +55,7 @@ class HttpStream {
|
|||||||
this.resolveRead = resolve;
|
this.resolveRead = resolve;
|
||||||
this.rejectRead = reject;
|
this.rejectRead = reject;
|
||||||
});
|
});
|
||||||
this.url = this.getURL(ip, port, testServers, isPremium);
|
this.url = HttpStream.getURL(ip, port, testServers, isPremium);
|
||||||
|
|
||||||
await fetch(this.url, {
|
await fetch(this.url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@ -40,7 +40,6 @@ const { SecurityError } = require('../errors/Common');
|
|||||||
const { InvalidBufferError } = require('../errors/Common');
|
const { InvalidBufferError } = require('../errors/Common');
|
||||||
const { RPCMessageToError } = require('../errors');
|
const { RPCMessageToError } = require('../errors');
|
||||||
const { TypeNotFoundError } = require('../errors/Common');
|
const { TypeNotFoundError } = require('../errors/Common');
|
||||||
const { sendToOrigin } = require('../../../api/gramjs/worker/worker');
|
|
||||||
|
|
||||||
const LONGPOLL_MAX_WAIT = 3000;
|
const LONGPOLL_MAX_WAIT = 3000;
|
||||||
const LONGPOLL_MAX_DELAY = 500;
|
const LONGPOLL_MAX_DELAY = 500;
|
||||||
@ -353,7 +352,11 @@ class MTProtoSender {
|
|||||||
const data = await this._send_queue.getBeacon(state);
|
const data = await this._send_queue.getBeacon(state);
|
||||||
const encryptedData = await this._state.encryptMessageData(data);
|
const encryptedData = await this._state.encryptMessageData(data);
|
||||||
|
|
||||||
sendToOrigin({ type: 'sendBeacon', data: encryptedData, url: this._fallbackConnection.socket.website });
|
postMessage({
|
||||||
|
type: 'sendBeacon',
|
||||||
|
data: encryptedData,
|
||||||
|
url: this._fallbackConnection.href,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -189,6 +189,7 @@ class HttpConnection extends Connection {
|
|||||||
super(ip, port, dcId, loggers, testServers, isPremium);
|
super(ip, port, dcId, loggers, testServers, isPremium);
|
||||||
this.shouldLongPoll = true;
|
this.shouldLongPoll = true;
|
||||||
this.socket = new HttpStream(this.disconnectCallback.bind(this));
|
this.socket = new HttpStream(this.disconnectCallback.bind(this));
|
||||||
|
this.href = HttpStream.getURL(this._ip, this._port, this._testServers, this._isPremium);
|
||||||
}
|
}
|
||||||
|
|
||||||
send(data) {
|
send(data) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user